Skip to content

Commit

Permalink
add support for Electra blob subnets and IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Dec 31, 2024
1 parent e29ef24 commit bb62d90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions beacon_chain/spec/datatypes/base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions beacon_chain/spec/network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit bb62d90

Please sign in to comment.