From fb1c3ba718ef0ec18bdc21f87573b493b6dce4c5 Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 31 Dec 2024 17:12:43 +0000 Subject: [PATCH] add support for Electra blob subnets and IDs (#6806) * add support for Electra blob subnets and IDs * fix tests --- beacon_chain/spec/datatypes/base.nim | 8 +++++--- beacon_chain/spec/network.nim | 14 +++++++------- tests/test_honest_validator.nim | 5 ++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/beacon_chain/spec/datatypes/base.nim b/beacon_chain/spec/datatypes/base.nim index 10b8e5b3d..d38c97d17 100644 --- a/beacon_chain/spec/datatypes/base.nim +++ b/beacon_chain/spec/datatypes/base.nim @@ -144,7 +144,7 @@ template ethAmountUnit*(typ: type) {.dirty.} = func u256*(n: typ): UInt256 {.borrow.} - proc toString*(B: typedesc[Base10], value: typ): string {.borrow.} + func toString*(B: typedesc[Base10], value: typ): string {.borrow.} proc writeValue*(writer: var JsonWriter, value: typ) {.raises: [IOError].} = writer.writeValue(distinctBase(value)) @@ -204,7 +204,7 @@ type ## blob sidecar - it is distinct from the CommitteeIndex in particular ## ## The `BlobId` type is constrained to values in the range - ## `[0, BLOB_SIDECAR_SUBNET_COUNT)` during initialization. + ## `[0, MAX_BLOBS_PER_BLOCK_ELECTRA)` during initialization. # BitVector[4] in the spec, ie 4 bits which end up encoded as a byte for # SSZ / hashing purposes @@ -612,7 +612,9 @@ template makeLimitedU64*(T: untyped, limit: uint64) = makeLimitedU64(CommitteeIndex, MAX_COMMITTEES_PER_SLOT) makeLimitedU64(SubnetId, ATTESTATION_SUBNET_COUNT) -makeLimitedU64(BlobId, BLOB_SIDECAR_SUBNET_COUNT) + +static: doAssert MAX_BLOBS_PER_BLOCK_ELECTRA >= BLOB_SIDECAR_SUBNET_COUNT +makeLimitedU64(BlobId, MAX_BLOBS_PER_BLOCK_ELECTRA) const validatorIndexLimit = min(uint64(int32.high), VALIDATOR_REGISTRY_LIMIT) diff --git a/beacon_chain/spec/network.nim b/beacon_chain/spec/network.nim index 239a3693a..3c7f05852 100644 --- a/beacon_chain/spec/network.nim +++ b/beacon_chain/spec/network.nim @@ -16,12 +16,12 @@ export base const # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.8/specs/phase0/p2p-interface.md#topics-and-messages # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/specs/capella/p2p-interface.md#topics-and-messages - topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy" - topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy" - topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy" - topicAttesterSlashingsSuffix* = "attester_slashing/ssz_snappy" - topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz_snappy" - topicBlsToExecutionChangeSuffix* = "bls_to_execution_change/ssz_snappy" + topicBeaconBlocksSuffix = "beacon_block/ssz_snappy" + topicVoluntaryExitsSuffix = "voluntary_exit/ssz_snappy" + topicProposerSlashingsSuffix = "proposer_slashing/ssz_snappy" + topicAttesterSlashingsSuffix = "attester_slashing/ssz_snappy" + topicAggregateAndProofsSuffix = "beacon_aggregate_and_proof/ssz_snappy" + topicBlsToExecutionChangeSuffix = "bls_to_execution_change/ssz_snappy" const # The spec now includes this as a bare uint64 as `RESP_TIMEOUT` @@ -112,7 +112,7 @@ func getBlobSidecarTopic*(forkDigest: ForkDigest, # https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/deneb/validator.md#sidecar func compute_subnet_for_blob_sidecar*(blob_index: BlobIndex): BlobId = - BlobId(blob_index mod BLOB_SIDECAR_SUBNET_COUNT) + BlobId(blob_index mod MAX_BLOBS_PER_BLOCK_ELECTRA) # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.8/specs/_features/eip7594/p2p-interface.md#compute_subnet_for_data_column_sidecar func compute_subnet_for_data_column_sidecar*(column_index: ColumnIndex): uint64 = diff --git a/tests/test_honest_validator.nim b/tests/test_honest_validator.nim index 1363b3b5e..59b79d9bb 100644 --- a/tests/test_honest_validator.nim +++ b/tests/test_honest_validator.nim @@ -86,7 +86,10 @@ suite "Honest validator": "/eth2/00000000/blob_sidecar_2/ssz_snappy", "/eth2/00000000/blob_sidecar_3/ssz_snappy", "/eth2/00000000/blob_sidecar_4/ssz_snappy", - "/eth2/00000000/blob_sidecar_5/ssz_snappy"] + "/eth2/00000000/blob_sidecar_5/ssz_snappy", + "/eth2/00000000/blob_sidecar_6/ssz_snappy", + "/eth2/00000000/blob_sidecar_7/ssz_snappy", + "/eth2/00000000/blob_sidecar_8/ssz_snappy"] test "is_aggregator": check: