add sanity checks for ELECTRA_FORK_VERSION and ELECTRA_FORK_EPOCH; add support for Electra to ForkyFoo (#5950)

This commit is contained in:
tersec 2024-02-24 11:14:45 +00:00 committed by GitHub
parent e865817d44
commit de8ac999c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 18 deletions

View File

@ -1032,7 +1032,7 @@ func checkForkConsistency*(cfg: RuntimeConfig) =
let forkVersions = let forkVersions =
[cfg.GENESIS_FORK_VERSION, cfg.ALTAIR_FORK_VERSION, [cfg.GENESIS_FORK_VERSION, cfg.ALTAIR_FORK_VERSION,
cfg.BELLATRIX_FORK_VERSION, cfg.CAPELLA_FORK_VERSION, cfg.BELLATRIX_FORK_VERSION, cfg.CAPELLA_FORK_VERSION,
cfg.DENEB_FORK_VERSION] cfg.DENEB_FORK_VERSION, cfg.ELECTRA_FORK_VERSION]
for i in 0 ..< forkVersions.len: for i in 0 ..< forkVersions.len:
for j in i+1 ..< forkVersions.len: for j in i+1 ..< forkVersions.len:
@ -1050,9 +1050,12 @@ func checkForkConsistency*(cfg: RuntimeConfig) =
assertForkEpochOrder(cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH) assertForkEpochOrder(cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH)
assertForkEpochOrder(cfg.BELLATRIX_FORK_EPOCH, cfg.CAPELLA_FORK_EPOCH) assertForkEpochOrder(cfg.BELLATRIX_FORK_EPOCH, cfg.CAPELLA_FORK_EPOCH)
assertForkEpochOrder(cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH) assertForkEpochOrder(cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH)
assertForkEpochOrder(cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH)
func ofLen*[T, N](ListType: type List[T, N], n: int): ListType = func ofLen*[T, N](ListType: type List[T, N], n: int): ListType =
if n < N: if n < N:
distinctBase(result).setLen(n) distinctBase(result).setLen(n)
else: else:
raise newException(SszSizeMismatchError) raise newException(SszSizeMismatchError)
template debugRaiseAssert*(s: string) = discard

View File

@ -16,7 +16,7 @@ import
"."/[ "."/[
block_id, eth2_merkleization, eth2_ssz_serialization, block_id, eth2_merkleization, eth2_ssz_serialization,
forks_light_client, presets], forks_light_client, presets],
./datatypes/[phase0, altair, bellatrix, capella, deneb], ./datatypes/[phase0, altair, bellatrix, capella, deneb, electra],
./mev/bellatrix_mev, ./mev/capella_mev, ./mev/deneb_mev ./mev/bellatrix_mev, ./mev/capella_mev, ./mev/deneb_mev
export export
@ -53,14 +53,16 @@ type
altair.BeaconState | altair.BeaconState |
bellatrix.BeaconState | bellatrix.BeaconState |
capella.BeaconState | capella.BeaconState |
deneb.BeaconState deneb.BeaconState |
electra.BeaconState
ForkyHashedBeaconState* = ForkyHashedBeaconState* =
phase0.HashedBeaconState | phase0.HashedBeaconState |
altair.HashedBeaconState | altair.HashedBeaconState |
bellatrix.HashedBeaconState | bellatrix.HashedBeaconState |
capella.HashedBeaconState | capella.HashedBeaconState |
deneb.HashedBeaconState deneb.HashedBeaconState |
electra.HashedBeaconState
ForkedHashedBeaconState* = object ForkedHashedBeaconState* = object
case kind*: ConsensusFork case kind*: ConsensusFork
@ -73,7 +75,8 @@ type
ForkyExecutionPayload* = ForkyExecutionPayload* =
bellatrix.ExecutionPayload | bellatrix.ExecutionPayload |
capella.ExecutionPayload | capella.ExecutionPayload |
deneb.ExecutionPayload deneb.ExecutionPayload |
electra.ExecutionPayload
ForkyExecutionPayloadHeader* = ForkyExecutionPayloadHeader* =
bellatrix.ExecutionPayloadHeader | bellatrix.ExecutionPayloadHeader |
@ -85,21 +88,24 @@ type
altair.BeaconBlockBody | altair.BeaconBlockBody |
bellatrix.BeaconBlockBody | bellatrix.BeaconBlockBody |
capella.BeaconBlockBody | capella.BeaconBlockBody |
deneb.BeaconBlockBody deneb.BeaconBlockBody |
electra.BeaconBlockBody
ForkySigVerifiedBeaconBlockBody* = ForkySigVerifiedBeaconBlockBody* =
phase0.SigVerifiedBeaconBlockBody | phase0.SigVerifiedBeaconBlockBody |
altair.SigVerifiedBeaconBlockBody | altair.SigVerifiedBeaconBlockBody |
bellatrix.SigVerifiedBeaconBlockBody | bellatrix.SigVerifiedBeaconBlockBody |
capella.SigVerifiedBeaconBlockBody | capella.SigVerifiedBeaconBlockBody |
deneb.SigVerifiedBeaconBlockBody deneb.SigVerifiedBeaconBlockBody |
electra.SigVerifiedBeaconBlockBody
ForkyTrustedBeaconBlockBody* = ForkyTrustedBeaconBlockBody* =
phase0.TrustedBeaconBlockBody | phase0.TrustedBeaconBlockBody |
altair.TrustedBeaconBlockBody | altair.TrustedBeaconBlockBody |
bellatrix.TrustedBeaconBlockBody | bellatrix.TrustedBeaconBlockBody |
capella.TrustedBeaconBlockBody | capella.TrustedBeaconBlockBody |
deneb.TrustedBeaconBlockBody deneb.TrustedBeaconBlockBody |
electra.TrustedBeaconBlockBody
SomeForkyBeaconBlockBody* = SomeForkyBeaconBlockBody* =
ForkyBeaconBlockBody | ForkyBeaconBlockBody |
@ -111,21 +117,24 @@ type
altair.BeaconBlock | altair.BeaconBlock |
bellatrix.BeaconBlock | bellatrix.BeaconBlock |
capella.BeaconBlock | capella.BeaconBlock |
deneb.BeaconBlock deneb.BeaconBlock |
electra.BeaconBlock
ForkySigVerifiedBeaconBlock* = ForkySigVerifiedBeaconBlock* =
phase0.SigVerifiedBeaconBlock | phase0.SigVerifiedBeaconBlock |
altair.SigVerifiedBeaconBlock | altair.SigVerifiedBeaconBlock |
bellatrix.SigVerifiedBeaconBlock | bellatrix.SigVerifiedBeaconBlock |
capella.SigVerifiedBeaconBlock | capella.SigVerifiedBeaconBlock |
deneb.SigVerifiedBeaconBlock deneb.SigVerifiedBeaconBlock |
electra.SigVerifiedBeaconBlock
ForkyTrustedBeaconBlock* = ForkyTrustedBeaconBlock* =
phase0.TrustedBeaconBlock | phase0.TrustedBeaconBlock |
altair.TrustedBeaconBlock | altair.TrustedBeaconBlock |
bellatrix.TrustedBeaconBlock | bellatrix.TrustedBeaconBlock |
capella.TrustedBeaconBlock | capella.TrustedBeaconBlock |
deneb.TrustedBeaconBlock deneb.TrustedBeaconBlock |
electra.TrustedBeaconBlock
SomeForkyBeaconBlock* = SomeForkyBeaconBlock* =
ForkyBeaconBlock | ForkyBeaconBlock |
@ -135,7 +144,8 @@ type
ForkyExecutionPayloadForSigning* = ForkyExecutionPayloadForSigning* =
bellatrix.ExecutionPayloadForSigning | bellatrix.ExecutionPayloadForSigning |
capella.ExecutionPayloadForSigning | capella.ExecutionPayloadForSigning |
deneb.ExecutionPayloadForSigning deneb.ExecutionPayloadForSigning |
electra.ExecutionPayloadForSigning
ForkyBlindedBeaconBlock* = ForkyBlindedBeaconBlock* =
capella_mev.BlindedBeaconBlock | capella_mev.BlindedBeaconBlock |
@ -189,7 +199,8 @@ type
altair.SignedBeaconBlock | altair.SignedBeaconBlock |
bellatrix.SignedBeaconBlock | bellatrix.SignedBeaconBlock |
capella.SignedBeaconBlock | capella.SignedBeaconBlock |
deneb.SignedBeaconBlock deneb.SignedBeaconBlock |
electra.SignedBeaconBlock
ForkedSignedBeaconBlock* = object ForkedSignedBeaconBlock* = object
case kind*: ConsensusFork case kind*: ConsensusFork
@ -219,21 +230,24 @@ type
altair.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock |
bellatrix.SigVerifiedSignedBeaconBlock | bellatrix.SigVerifiedSignedBeaconBlock |
capella.SigVerifiedSignedBeaconBlock | capella.SigVerifiedSignedBeaconBlock |
deneb.SigVerifiedSignedBeaconBlock deneb.SigVerifiedSignedBeaconBlock |
electra.SigVerifiedSignedBeaconBlock
ForkyMsgTrustedSignedBeaconBlock* = ForkyMsgTrustedSignedBeaconBlock* =
phase0.MsgTrustedSignedBeaconBlock | phase0.MsgTrustedSignedBeaconBlock |
altair.MsgTrustedSignedBeaconBlock | altair.MsgTrustedSignedBeaconBlock |
bellatrix.MsgTrustedSignedBeaconBlock | bellatrix.MsgTrustedSignedBeaconBlock |
capella.MsgTrustedSignedBeaconBlock | capella.MsgTrustedSignedBeaconBlock |
deneb.MsgTrustedSignedBeaconBlock deneb.MsgTrustedSignedBeaconBlock |
electra.MsgTrustedSignedBeaconBlock
ForkyTrustedSignedBeaconBlock* = ForkyTrustedSignedBeaconBlock* =
phase0.TrustedSignedBeaconBlock | phase0.TrustedSignedBeaconBlock |
altair.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock |
bellatrix.TrustedSignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock |
capella.TrustedSignedBeaconBlock | capella.TrustedSignedBeaconBlock |
deneb.TrustedSignedBeaconBlock deneb.TrustedSignedBeaconBlock |
electra.TrustedSignedBeaconBlock
ForkedMsgTrustedSignedBeaconBlock* = object ForkedMsgTrustedSignedBeaconBlock* = object
case kind*: ConsensusFork case kind*: ConsensusFork
@ -274,6 +288,7 @@ type
bellatrix*: ForkDigest bellatrix*: ForkDigest
capella*: ForkDigest capella*: ForkDigest
deneb*: ForkDigest deneb*: ForkDigest
electra*: ForkDigest
template kind*( template kind*(
x: typedesc[ x: typedesc[
@ -799,7 +814,7 @@ template withEpochInfo*(
template withEpochInfo*( template withEpochInfo*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState | state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
deneb.BeaconState, deneb.BeaconState | electra.BeaconState,
x: var ForkedEpochInfo, body: untyped): untyped = x: var ForkedEpochInfo, body: untyped): untyped =
if x.kind != EpochInfoFork.Altair: if x.kind != EpochInfoFork.Altair:
# Rare, so efficiency not critical # Rare, so efficiency not critical
@ -1165,6 +1180,12 @@ func denebFork*(cfg: RuntimeConfig): Fork =
current_version: cfg.DENEB_FORK_VERSION, current_version: cfg.DENEB_FORK_VERSION,
epoch: cfg.DENEB_FORK_EPOCH) epoch: cfg.DENEB_FORK_EPOCH)
func electraFork*(cfg: RuntimeConfig): Fork =
Fork(
previous_version: cfg.DENEB_FORK_VERSION,
current_version: cfg.ELECTRA_FORK_VERSION,
epoch: cfg.ELECTRA_FORK_EPOCH)
func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork = func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
case cfg.consensusForkAtEpoch(epoch) case cfg.consensusForkAtEpoch(epoch)
of ConsensusFork.Deneb: cfg.denebFork of ConsensusFork.Deneb: cfg.denebFork
@ -1315,7 +1336,9 @@ func init*(T: type ForkDigests,
capella: capella:
compute_fork_digest(cfg.CAPELLA_FORK_VERSION, genesis_validators_root), compute_fork_digest(cfg.CAPELLA_FORK_VERSION, genesis_validators_root),
deneb: deneb:
compute_fork_digest(cfg.DENEB_FORK_VERSION, genesis_validators_root) compute_fork_digest(cfg.DENEB_FORK_VERSION, genesis_validators_root),
electra:
compute_fork_digest(cfg.ELECTRA_FORK_VERSION, genesis_validators_root)
) )
func toBlockId*(header: BeaconBlockHeader): BlockId = func toBlockId*(header: BeaconBlockHeader): BlockId =