Skip to content

Commit

Permalink
treat more constants as quasi-runtime-presets per v1.4.0 consensus sp…
Browse files Browse the repository at this point in the history
…ecs (#5335)
  • Loading branch information
tersec authored Aug 21, 2023
1 parent 295c3e2 commit c08d125
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions beacon_chain/spec/datatypes/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const
EPOCHS_PER_SUBNET_SUBSCRIPTION* = 256'u64
SUBNETS_PER_NODE* = 2'u64
ATTESTATION_SUBNET_COUNT*: uint64 = 64
ATTESTATION_SUBNET_EXTRA_BITS* = 0
ATTESTATION_SUBNET_PREFIX_BITS* = 6 ## \
ATTESTATION_SUBNET_EXTRA_BITS* = 0'u64
ATTESTATION_SUBNET_PREFIX_BITS* = 6'u64 ## \
## int(ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS)

static: doAssert 1 shl (ATTESTATION_SUBNET_PREFIX_BITS - ATTESTATION_SUBNET_EXTRA_BITS) ==
Expand Down Expand Up @@ -73,3 +73,6 @@ const
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#configuration
GOSSIP_MAX_SIZE* = 10'u64 * 1024 * 1024 # bytes
MAX_CHUNK_SIZE* = 10'u64 * 1024 * 1024 # bytes

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/deneb/p2p-interface.md#configuration
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS* = 4096'u64
3 changes: 0 additions & 3 deletions beacon_chain/spec/datatypes/deneb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/polynomial-commitments.md#constants
BLS_MODULUS* = "52435875175126190479447740508185965837690552500527637822603658699938581184513".u256

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/deneb/p2p-interface.md#configuration
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS* = 4096'u64

type
KzgCommitments* = List[KzgCommitment, Limit MAX_BLOB_COMMITMENTS_PER_BLOCK]
Blobs* = List[Blob, Limit MAX_BLOBS_PER_BLOCK]
Expand Down
4 changes: 4 additions & 0 deletions beacon_chain/spec/presets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ proc readRuntimeConfig*(
checkCompatibility EPOCHS_PER_SUBNET_SUBSCRIPTION
checkCompatibility MAX_CHUNK_SIZE
checkCompatibility SUBNETS_PER_NODE
checkCompatibility ATTESTATION_SUBNET_EXTRA_BITS
checkCompatibility ATTESTATION_SUBNET_PREFIX_BITS
checkCompatibility BLOB_SIDECAR_SUBNET_COUNT
checkCompatibility MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS

# Never pervasively implemented, still under discussion
checkCompatibility TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH
Expand Down
7 changes: 4 additions & 3 deletions beacon_chain/spec/validator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func livenessFailsafeInEffect*(

false

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/phase0/p2p-interface.md#attestation-subnet-subcription
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#attestation-subnet-subscription
func compute_subscribed_subnet(node_id: UInt256, epoch: Epoch, index: uint64):
SubnetId =
# Ensure neither `truncate` loses information
Expand All @@ -482,7 +482,8 @@ func compute_subscribed_subnet(node_id: UInt256, epoch: Epoch, index: uint64):

let
node_id_prefix = truncate(
node_id shr (NODE_ID_BITS - ATTESTATION_SUBNET_PREFIX_BITS), uint64)
node_id shr (
NODE_ID_BITS - static(ATTESTATION_SUBNET_PREFIX_BITS.int)), uint64)
node_offset = truncate(
node_id mod static(EPOCHS_PER_SUBNET_SUBSCRIPTION.u256), uint64)
permutation_seed = eth2digest(uint_to_bytes(
Expand All @@ -494,7 +495,7 @@ func compute_subscribed_subnet(node_id: UInt256, epoch: Epoch, index: uint64):
)
SubnetId((permutated_prefix + index) mod ATTESTATION_SUBNET_COUNT)

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/phase0/p2p-interface.md#attestation-subnet-subcription
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#attestation-subnet-subscription
iterator compute_subscribed_subnets*(node_id: UInt256, epoch: Epoch): SubnetId =
for index in 0'u64 ..< SUBNETS_PER_NODE:
yield compute_subscribed_subnet(node_id, epoch, index)

0 comments on commit c08d125

Please sign in to comment.