extent `BeaconStateFork` enum (#4396)

This commit is contained in:
tersec 2022-12-07 16:47:23 +00:00 committed by GitHub
parent d30cb8baf1
commit 2932d3b808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 231 additions and 38 deletions

View File

@ -327,6 +327,9 @@ ConsensusSpecPreset-mainnet
+ Light client - Single merkle proof - mainnet/capella/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/capella/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/capella/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/eip4844/light_client/single_merkle_proof/Beac OK
+ Slots - double_empty_epoch OK
+ Slots - empty_epoch OK
+ Slots - over_epoch_boundary OK
@ -647,7 +650,7 @@ ConsensusSpecPreset-mainnet
+ fork_random_low_balances OK
+ fork_random_misc_balances OK
```
OK: 636/644 Fail: 0/644 Skip: 8/644
OK: 639/647 Fail: 0/647 Skip: 8/647
## Attestation
```diff
+ [Invalid] EF - Altair - Operations - Attestation - after_epoch_slots OK
@ -2322,4 +2325,4 @@ OK: 63/63 Fail: 0/63 Skip: 0/63
OK: 51/51 Fail: 0/51 Skip: 0/51
---TOTAL---
OK: 2028/2036 Fail: 0/2036 Skip: 8/2036
OK: 2031/2039 Fail: 0/2039 Skip: 8/2039

View File

@ -371,6 +371,9 @@ ConsensusSpecPreset-minimal
+ Light client - Single merkle proof - minimal/capella/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - minimal/capella/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - minimal/capella/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - minimal/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - minimal/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - minimal/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Sync - minimal/altair/light_client/sync/pyspec_tests/advance_finality_witho OK
+ Light client - Sync - minimal/altair/light_client/sync/pyspec_tests/light_client_sync OK
+ Light client - Sync - minimal/altair/light_client/sync/pyspec_tests/supply_sync_committee_ OK
@ -729,7 +732,7 @@ ConsensusSpecPreset-minimal
+ fork_random_low_balances OK
+ fork_random_misc_balances OK
```
OK: 718/726 Fail: 0/726 Skip: 8/726
OK: 721/729 Fail: 0/729 Skip: 8/729
## Attestation
```diff
+ [Invalid] EF - Altair - Operations - Attestation - after_epoch_slots OK
@ -2482,4 +2485,4 @@ OK: 68/68 Fail: 0/68 Skip: 0/68
OK: 52/52 Fail: 0/52 Skip: 0/52
---TOTAL---
OK: 2172/2180 Fail: 0/2180 Skip: 8/2180
OK: 2175/2183 Fail: 0/2183 Skip: 8/2183

View File

@ -509,7 +509,8 @@ proc new*(T: type BeaconChainDB,
kvStore db.openKvStore("state_no_validators2").expectDb(),
kvStore db.openKvStore("altair_state_no_validators").expectDb(),
kvStore db.openKvStore("bellatrix_state_no_validators").expectDb(),
kvStore db.openKvStore("capella_state_no_validators").expectDb()]
kvStore db.openKvStore("capella_state_no_validators").expectDb(),
kvStore db.openKvStore("eip4844_state_no_validators").expectDb()]
stateDiffs = kvStore db.openKvStore("state_diffs").expectDb()
summaries = kvStore db.openKvStore("beacon_block_summaries", true).expectDb()
@ -759,7 +760,8 @@ proc putBlock*(
proc putBlock*(
db: BeaconChainDB,
value: bellatrix.TrustedSignedBeaconBlock |
capella.TrustedSignedBeaconBlock) =
capella.TrustedSignedBeaconBlock |
eip4844.TrustedSignedBeaconBlock) =
db.withManyWrites:
db.blocks[type(value).toFork].putSZSSZ(value.root.data, value)
db.putBeaconBlockSummary(value.root, value.message.toBeaconBlockSummary())
@ -794,6 +796,10 @@ template toBeaconStateNoImmutableValidators(state: capella.BeaconState):
CapellaBeaconStateNoImmutableValidators =
isomorphicCast[CapellaBeaconStateNoImmutableValidators](state)
template toBeaconStateNoImmutableValidators(state: eip4844.BeaconState):
EIP4844BeaconStateNoImmutableValidators =
isomorphicCast[EIP4844BeaconStateNoImmutableValidators](state)
proc putState*(
db: BeaconChainDB, key: Eth2Digest,
value: phase0.BeaconState | altair.BeaconState) =
@ -803,7 +809,7 @@ proc putState*(
proc putState*(
db: BeaconChainDB, key: Eth2Digest,
value: bellatrix.BeaconState | capella.BeaconState) =
value: bellatrix.BeaconState | capella.BeaconState | eip4844.BeaconState) =
db.updateImmutableValidators(value.validators.asSeq())
db.statesNoVal[type(value).toFork()].putSZSSZ(
key.data, toBeaconStateNoImmutableValidators(value))
@ -1105,7 +1111,8 @@ proc getStateOnlyMutableValidators(
proc getStateOnlyMutableValidators(
immutableValidators: openArray[ImmutableValidatorData2],
store: KvStoreRef, key: openArray[byte],
output: var (bellatrix.BeaconState | capella.BeaconState),
output: var (bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState),
rollback: RollbackProc): bool =
## Load state into `output` - BeaconState is large so we want to avoid
## re-allocating it if possible
@ -1197,7 +1204,7 @@ proc getState*(
proc getState*(
db: BeaconChainDB, key: Eth2Digest,
output: var (altair.BeaconState | bellatrix.BeaconState |
capella.BeaconState),
capella.BeaconState | eip4844.BeaconState),
rollback: RollbackProc): bool =
## Load state into `output` - BeaconState is large so we want to avoid
## re-allocating it if possible

View File

@ -15,6 +15,7 @@ import
./spec/[eth2_ssz_serialization, eth2_merkleization]
from ./spec/datatypes/capella import ExecutionPayloadHeader, Withdrawal
from ./spec/datatypes/eip4844 import ExecutionPayloadHeader
type
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#beaconstate
@ -186,6 +187,7 @@ type
latest_execution_payload_header*: bellatrix.ExecutionPayloadHeader # [New in Bellatrix]
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#beaconstate
# with indirect changes via ExecutionPayload
# Memory-representation-equivalent to a Capella BeaconState for in-place SSZ
# reading and writing
CapellaBeaconStateNoImmutableValidators* = object
@ -248,3 +250,68 @@ type
# Withdrawals
next_withdrawal_index*: WithdrawalIndex # [New in Capella]
next_withdrawal_validator_index*: uint64 # [New in Capella]
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#beaconstate
# with indirect changes via ExecutionPayloadHeader
# Memory-representation-equivalent to a Capella BeaconState for in-place SSZ
# reading and writing
EIP4844BeaconStateNoImmutableValidators* = object
# Versioning
genesis_time*: uint64
genesis_validators_root*: Eth2Digest
slot*: Slot
fork*: Fork
# History
latest_block_header*: BeaconBlockHeader
## `latest_block_header.state_root == ZERO_HASH` temporarily
block_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
## Needed to process attestations, older to newer
state_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
historical_roots*: HashList[Eth2Digest, Limit HISTORICAL_ROOTS_LIMIT]
# Eth1
eth1_data*: Eth1Data
eth1_data_votes*:
HashList[Eth1Data, Limit(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH)]
eth1_deposit_index*: uint64
# Registry
validators*: HashList[ValidatorStatus, Limit VALIDATOR_REGISTRY_LIMIT]
balances*: HashList[Gwei, Limit VALIDATOR_REGISTRY_LIMIT]
# Randomness
randao_mixes*: HashArray[Limit EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
# Slashings
slashings*: HashArray[Limit EPOCHS_PER_SLASHINGS_VECTOR, Gwei]
## Per-epoch sums of slashed effective balances
# Participation
previous_epoch_participation*: EpochParticipationFlags
current_epoch_participation*: EpochParticipationFlags
# Finality
justification_bits*: JustificationBits
previous_justified_checkpoint*: Checkpoint
## Previous epoch snapshot
current_justified_checkpoint*: Checkpoint
finalized_checkpoint*: Checkpoint
# Inactivity
inactivity_scores*: HashList[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
# Light client sync committees
current_sync_committee*: SyncCommittee
next_sync_committee*: SyncCommittee
# Execution
latest_execution_payload_header*: eip4844.ExecutionPayloadHeader
# Withdrawals
next_withdrawal_index*: WithdrawalIndex
next_withdrawal_validator_index*: uint64

View File

@ -146,7 +146,9 @@ proc init*(T: type AttestationPool, dag: ChainDAGRef,
var unrealized: FinalityCheckpoints
if enableTestFeatures in dag.updateFlags and blckRef == dag.head:
unrealized = withState(dag.headState):
when stateFork >= BeaconStateFork.Altair:
when stateFork == BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": attestation_pool.nim:init"
elif stateFork >= BeaconStateFork.Altair:
forkyState.data.compute_unrealized_finality()
else:
var cache: StateCache
@ -558,6 +560,8 @@ proc check_attestation_compatible*(
ok()
from ../spec/datatypes/eip4844 import HashedBeaconState
proc getAttestationsForBlock*(pool: var AttestationPool,
state: ForkyHashedBeaconState,
cache: var StateCache): seq[Attestation] =
@ -584,6 +588,10 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
elif state is altair.HashedBeaconState or state is bellatrix.HashedBeaconState or
state is capella.HashedBeaconState:
AttestationCache.init(state, cache)
elif state is eip4844.HashedBeaconState:
if true:
raiseAssert $eip4844ImplementationMissing & ": attestation_pool.nim:getAttestationsForBlock"
default(AttestationCache)
else:
static: doAssert false
@ -643,8 +651,10 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
var
prevEpoch = state.data.get_previous_epoch()
prevEpochSpace =
when state is altair.HashedBeaconState or state is bellatrix.HashedBeaconState or
state is capella.HashedBeaconState:
when state is altair.HashedBeaconState or
state is bellatrix.HashedBeaconState or
state is capella.HashedBeaconState or
state is eip4844.HashedBeaconState:
MAX_ATTESTATIONS
elif state is phase0.HashedBeaconState:
state.data.previous_epoch_attestations.maxLen -

View File

@ -107,8 +107,10 @@ proc addResolvedHeadBlock(
var unrealized: FinalityCheckpoints
if enableTestFeatures in dag.updateFlags:
unrealized = withState(state):
static: doAssert high(BeaconStateFork) == BeaconStateFork.Capella
when stateFork >= BeaconStateFork.Altair:
static: doAssert high(BeaconStateFork) == BeaconStateFork.EIP4844
when stateFork == BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": block_clearance.nim:addResolvedHeadBlock"
elif stateFork >= BeaconStateFork.Altair:
forkyState.data.compute_unrealized_finality()
else:
forkyState.data.compute_unrealized_finality(cache)

View File

@ -1016,6 +1016,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
of BeaconStateFork.Altair: altairFork(cfg)
of BeaconStateFork.Bellatrix: bellatrixFork(cfg)
of BeaconStateFork.Capella: capellaFork(cfg)
of BeaconStateFork.EIP4844: eip4844Fork(cfg)
stateFork = getStateField(dag.headState, fork)
if stateFork != configFork:

View File

@ -19,16 +19,20 @@ import
"."/[block_pools_types, blockchain_dag]
from ../spec/datatypes/capella import TrustedSignedBeaconBlock
from ../spec/datatypes/eip4844 import
HashedBeaconState, TrustedSignedBeaconBlock
logScope: topics = "chaindag_lc"
type
HashedBeaconStateWithSyncCommittee =
eip4844.HashedBeaconState |
capella.HashedBeaconState |
bellatrix.HashedBeaconState |
altair.HashedBeaconState
TrustedSignedBeaconBlockWithSyncAggregate =
eip4844.TrustedSignedBeaconBlock |
capella.TrustedSignedBeaconBlock |
bellatrix.TrustedSignedBeaconBlock |
altair.TrustedSignedBeaconBlock
@ -218,6 +222,7 @@ proc initLightClientBootstrapForPeriod(
res
from ../spec/datatypes/capella import asSigned
from ../spec/datatypes/eip4844 import asSigned
proc initLightClientUpdateForPeriod(
dag: ChainDAGRef, period: SyncCommitteePeriod): Opt[void] =

View File

@ -386,6 +386,8 @@ iterator getBlockIds*(
state = nil # No `return` in iterators
of BeaconStateFork.Capella:
raiseAssert $capellaImplementationMissing
of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing
if state == nil:
break

View File

@ -719,7 +719,8 @@ func forkDigests(node: BeaconNode): auto =
node.dag.forkDigests.phase0,
node.dag.forkDigests.altair,
node.dag.forkDigests.bellatrix,
node.dag.forkDigests.capella]
node.dag.forkDigests.capella,
node.dag.forkDigests.eip4844]
forkDigestsArray
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/validator.md#phase-0-attestation-subnet-stability
@ -1050,20 +1051,24 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
let forkDigests = node.forkDigests()
discard $eip4844ImplementationMissing & "nimbus_beacon_node.nim:updateGossipStatus check EIP4844 removeMessageHandlers"
const removeMessageHandlers: array[BeaconStateFork, auto] = [
removePhase0MessageHandlers,
removeAltairMessageHandlers,
removeAltairMessageHandlers, # with different forkDigest
removeCapellaMessageHandlers,
removeCapellaMessageHandlers
]
for gossipFork in oldGossipForks:
removeMessageHandlers[gossipFork](node, forkDigests[gossipFork])
discard $eip4844ImplementationMissing & "nimbus_beacon_node.nim:updateGossipStatus check EIP4844 message addMessageHandlers"
const addMessageHandlers: array[BeaconStateFork, auto] = [
addPhase0MessageHandlers,
addAltairMessageHandlers,
addAltairMessageHandlers, # with different forkDigest
addCapellaMessageHandlers,
addCapellaMessageHandlers
]

View File

@ -840,6 +840,8 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, BlockIncorrectFork)
case currentEpochFork
of BeaconStateFork.EIP4844:
return RestApiResponse.jsonError(Http500, $eip4844ImplementationMissing)
of BeaconStateFork.Capella:
return RestApiResponse.jsonError(Http500, $capellaImplementationMissing)
of BeaconStateFork.Bellatrix:

View File

@ -270,6 +270,8 @@ proc getStateOptimistic*(node: BeaconNode,
case state.kind
of BeaconStateFork.Phase0, BeaconStateFork.Altair:
some[bool](false)
of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & "rest_utils.nim:getStateOptimistic"
of BeaconStateFork.Bellatrix, BeaconStateFork.Capella:
# A state is optimistic iff the block which created it is
withState(state):

View File

@ -362,6 +362,17 @@ func get_initial_beacon_block*(state: bellatrix.HashedBeaconState):
bellatrix.TrustedSignedBeaconBlock(
message: message, root: hash_tree_root(message))
func get_initial_beacon_block*(state: eip4844.HashedBeaconState):
eip4844.TrustedSignedBeaconBlock =
# The genesis block is implicitly trusted
let message = eip4844.TrustedBeaconBlock(
slot: state.data.slot,
state_root: state.root)
# parent_root, randao_reveal, eth1_data, signature, and body automatically
# initialized to default values.
eip4844.TrustedSignedBeaconBlock(
message: message, root: hash_tree_root(message))
# https://github.com/ethereum/consensus-specs/blob/v1.1.7/specs/merge/beacon-chain.md#testing
func get_initial_beacon_block*(state: capella.HashedBeaconState):
capella.TrustedSignedBeaconBlock =

View File

@ -19,6 +19,7 @@ import ".."/[eth2_ssz_serialization, forks, keystore],
import nimcrypto/utils as ncrutils
from ".."/datatypes/capella import SignedBeaconBlock
from ".."/datatypes/eip4844 import BeaconState
export
eth2_ssz_serialization, results, peerid, common, serialization, chronicles,
@ -1588,6 +1589,7 @@ proc readValue*(reader: var JsonReader[RestJson],
of "altair": some(BeaconStateFork.Altair)
of "bellatrix": some(BeaconStateFork.Bellatrix)
of "capella": some(BeaconStateFork.Capella)
of "eip4844": some(BeaconStateFork.EIP4844)
else: reader.raiseUnexpectedValue("Incorrect version field value")
of "data":
if data.isSome():
@ -1657,6 +1659,16 @@ proc readValue*(reader: var JsonReader[RestJson],
except SerializationError:
reader.raiseUnexpectedValue("Incorrect capella beacon state format")
toValue(capellaData)
of BeaconStateFork.EIP4844:
try:
tmp[].eip4844Data.data = RestJson.decode(
string(data.get()),
eip4844.BeaconState,
requireAllFields = true,
allowUnknownFields = true)
except SerializationError:
reader.raiseUnexpectedValue("Incorrect EIP4844 beacon state format")
toValue(eip4844Data)
proc writeValue*(writer: var JsonWriter[RestJson], value: ForkedHashedBeaconState)
{.raises: [IOError, Defect].} =
@ -1674,6 +1686,9 @@ proc writeValue*(writer: var JsonWriter[RestJson], value: ForkedHashedBeaconStat
of BeaconStateFork.Capella:
writer.writeField("version", "capella")
writer.writeField("data", value.capellaData.data)
of BeaconStateFork.EIP4844:
writer.writeField("version", "eip4844")
writer.writeField("data", value.eip4844Data.data)
writer.endRecord()
## Web3SignerRequest

View File

@ -45,7 +45,8 @@ type
Phase0,
Altair,
Bellatrix,
Capella
Capella,
EIP4844
ForkyBeaconState* =
phase0.BeaconState |
@ -58,7 +59,8 @@ type
phase0.HashedBeaconState |
altair.HashedBeaconState |
bellatrix.HashedBeaconState |
capella.HashedBeaconState
capella.HashedBeaconState |
eip4844.HashedBeaconState
ForkedHashedBeaconState* = object
case kind*: BeaconStateFork
@ -66,6 +68,7 @@ type
of BeaconStateFork.Altair: altairData*: altair.HashedBeaconState
of BeaconStateFork.Bellatrix: bellatrixData*: bellatrix.HashedBeaconState
of BeaconStateFork.Capella: capellaData*: capella.HashedBeaconState
of BeaconStateFork.EIP4844: eip4844Data*: eip4844.HashedBeaconState
BeaconBlockFork* {.pure.} = enum
Phase0,
@ -259,6 +262,9 @@ template toFork*[T: bellatrix.BeaconState | bellatrix.HashedBeaconState](
template toFork*[T: capella.BeaconState | capella.HashedBeaconState](
t: type T): BeaconStateFork =
BeaconStateFork.Capella
template toFork*[T: eip4844.BeaconState | eip4844.HashedBeaconState](
t: type T): BeaconStateFork =
BeaconStateFork.EIP4844
# TODO these cause stack overflows due to large temporaries getting allocated
# template init*(T: type ForkedHashedBeaconState, data: phase0.HashedBeaconState): T =
@ -401,6 +407,8 @@ template toString*(kind: BeaconStateFork): string =
"bellatrix"
of BeaconStateFork.Capella:
"capella"
of BeaconStateFork.EIP4844:
"eip4844"
template toFork*[T:
phase0.BeaconBlock |
@ -411,6 +419,7 @@ template toFork*[T:
phase0.TrustedSignedBeaconBlock](
t: type T): BeaconBlockFork =
BeaconBlockFork.Phase0
template toFork*[T:
altair.BeaconBlock |
altair.SignedBeaconBlock |
@ -420,6 +429,7 @@ template toFork*[T:
altair.TrustedSignedBeaconBlock](
t: type T): BeaconBlockFork =
BeaconBlockFork.Altair
template toFork*[T:
bellatrix.BeaconBlock |
bellatrix.SignedBeaconBlock |
@ -429,6 +439,7 @@ template toFork*[T:
bellatrix.TrustedSignedBeaconBlock](
t: type T): BeaconBlockFork =
BeaconBlockFork.Bellatrix
template toFork*[T:
capella.BeaconBlock |
capella.SignedBeaconBlock |
@ -456,6 +467,10 @@ template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T =
template withState*(x: ForkedHashedBeaconState, body: untyped): untyped =
case x.kind
of BeaconStateFork.EIP4844:
const stateFork {.inject, used.} = BeaconStateFork.EIP4844
template forkyState: untyped {.inject, used.} = x.eip4844Data
body
of BeaconStateFork.Capella:
const stateFork {.inject, used.} = BeaconStateFork.Capella
template forkyState: untyped {.inject, used.} = x.capellaData
@ -493,7 +508,8 @@ template withEpochInfo*(
body
template withEpochInfo*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState,
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState,
x: var ForkedEpochInfo, body: untyped): untyped =
if x.kind != EpochInfoFork.Altair:
# Rare, so efficiency not critical
@ -504,6 +520,8 @@ template withEpochInfo*(
func assign*(tgt: var ForkedHashedBeaconState, src: ForkedHashedBeaconState) =
if tgt.kind == src.kind:
case tgt.kind
of BeaconStateFork.EIP4844:
assign(tgt.eip4844Data, src.eip4844Data):
of BeaconStateFork.Capella:
assign(tgt.capellaData, src.capellaData):
of BeaconStateFork.Bellatrix:
@ -524,6 +542,7 @@ template getStateField*(x: ForkedHashedBeaconState, y: untyped): untyped =
# ```
# Without `unsafeAddr`, the `validators` list would be copied to a temporary variable.
(case x.kind
of BeaconStateFork.EIP4844: unsafeAddr x.eip4844Data.data.y
of BeaconStateFork.Capella: unsafeAddr x.capellaData.data.y
of BeaconStateFork.Bellatrix: unsafeAddr x.bellatrixData.data.y
of BeaconStateFork.Altair: unsafeAddr x.altairData.data.y
@ -574,6 +593,8 @@ func stateForkForDigest*(
func atStateFork*(
forkDigests: ForkDigests, stateFork: BeaconStateFork): ForkDigest =
case stateFork
of BeaconStateFork.EIP4844:
forkDigests.eip4844
of BeaconStateFork.Capella:
forkDigests.capella
of BeaconStateFork.Bellatrix:
@ -710,6 +731,11 @@ template withStateAndBlck*(
ForkedTrustedSignedBeaconBlock,
body: untyped): untyped =
case s.kind
of BeaconStateFork.EIP4844:
const stateFork {.inject.} = BeaconStateFork.EIP4844
template forkyState: untyped {.inject.} = s.eip4844Data
template blck: untyped {.inject.} = b.eip4844Data
body
of BeaconStateFork.Capella:
const stateFork {.inject.} = BeaconStateFork.Capella
template forkyState: untyped {.inject.} = s.capellaData
@ -784,6 +810,7 @@ func eip4844Fork*(cfg: RuntimeConfig): Fork =
func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
case cfg.stateForkAtEpoch(epoch)
of BeaconStateFork.EIP4844: cfg.eip4844Fork
of BeaconStateFork.Capella: cfg.capellaFork
of BeaconStateFork.Bellatrix: cfg.bellatrixFork
of BeaconStateFork.Altair: cfg.altairFork
@ -791,6 +818,7 @@ func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
case cfg.stateForkAtEpoch(epoch)
of BeaconStateFork.EIP4844: cfg.EIP4844_FORK_VERSION
of BeaconStateFork.Capella: cfg.CAPELLA_FORK_VERSION
of BeaconStateFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
of BeaconStateFork.Altair: cfg.ALTAIR_FORK_VERSION
@ -798,7 +826,8 @@ func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
func nextForkEpochAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Epoch =
case cfg.stateForkAtEpoch(epoch)
of BeaconStateFork.Capella: FAR_FUTURE_EPOCH
of BeaconStateFork.EIP4844: FAR_FUTURE_EPOCH
of BeaconStateFork.Capella: cfg.EIP4844_FORK_EPOCH
of BeaconStateFork.Bellatrix: cfg.CAPELLA_FORK_EPOCH
of BeaconStateFork.Altair: cfg.BELLATRIX_FORK_EPOCH
of BeaconStateFork.Phase0: cfg.ALTAIR_FORK_EPOCH
@ -867,6 +896,7 @@ func toBeaconBlockFork*(fork: BeaconStateFork): BeaconBlockFork =
of BeaconStateFork.Altair: BeaconBlockFork.Altair
of BeaconStateFork.Bellatrix: BeaconBlockFork.Bellatrix
of BeaconStateFork.Capella: BeaconBlockFork.Capella
of BeaconStateFork.EIP4844: BeaconBlockFork.EIP4844
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#compute_fork_data_root
func compute_fork_data_root*(current_version: Version,

View File

@ -158,9 +158,6 @@ func getTargetGossipState*(
if isBehind:
return {}
# When EIP4844 comes in, can be transformed to discard of that symbol
static: doAssert high(BeaconStateFork) == BeaconStateFork.Capella
doAssert BELLATRIX_FORK_EPOCH >= ALTAIR_FORK_EPOCH
doAssert CAPELLA_FORK_EPOCH >= BELLATRIX_FORK_EPOCH
doAssert EIP4844_FORK_EPOCH >= CAPELLA_FORK_EPOCH
@ -188,10 +185,8 @@ func getTargetGossipState*(
BeaconStateFork.Bellatrix, BELLATRIX_FORK_EPOCH, CAPELLA_FORK_EPOCH)
maybeIncludeFork(
BeaconStateFork.Capella, CAPELLA_FORK_EPOCH, EIP4844_FORK_EPOCH)
discard $eip4844ImplementationMissing & ": should be BeaconStateFork.EIP4844"
maybeIncludeFork(
BeaconStateFork.Capella, EIP4844_FORK_EPOCH, FAR_FUTURE_EPOCH)
BeaconStateFork.EIP4844, EIP4844_FORK_EPOCH, FAR_FUTURE_EPOCH)
doAssert len(targetForks) <= 2
targetForks

View File

@ -277,7 +277,9 @@ proc state_transition_block*(
doAssert not rollback.isNil, "use noRollback if it's ok to mess up state"
let res = withState(state):
when stateFork.toBeaconBlockFork() == type(signedBlock).toFork:
when stateFork == BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": state_transition.nim: state_transition_block()"
elif stateFork.toBeaconBlockFork() == type(signedBlock).toFork:
state_transition_block_aux(cfg, forkyState, signedBlock, cache, flags)
else:
err("State/block fork mismatch")
@ -439,6 +441,8 @@ template partialBeaconBlock*(
bls_to_execution_changes: bls_to_execution_changes
))
from ./datatypes/eip4844 import ExecutionPayload
proc makeBeaconBlock*[T: bellatrix.ExecutionPayload | capella.ExecutionPayload](
cfg: RuntimeConfig,
state: var ForkedHashedBeaconState,
@ -517,12 +521,16 @@ proc makeBeaconBlock*[T: bellatrix.ExecutionPayload | capella.ExecutionPayload](
of BeaconStateFork.Phase0: makeBeaconBlock(phase0)
of BeaconStateFork.Altair: makeBeaconBlock(altair)
of BeaconStateFork.Bellatrix: makeBeaconBlock(bellatrix)
of BeaconStateFork.Capella: raiseAssert "Attempt to use Bellatrix payload with Capella state"
of BeaconStateFork.Capella, BeaconStateFork.EIP4844:
raiseAssert "Attempt to use Bellatrix payload with post-Bellatrix state"
elif T is capella.ExecutionPayload:
case state.kind
of BeaconStateFork.Phase0, BeaconStateFork.Altair, BeaconStateFork.Bellatrix:
of BeaconStateFork.Phase0, BeaconStateFork.Altair,
BeaconStateFork.Bellatrix, BeaconStateFork.EIP4844:
raiseAssert "Attempt to use Capella payload with non-Capella state"
of BeaconStateFork.Capella: makeBeaconBlock(capella)
elif T is eip4844.ExecutionPayload:
raiseAssert $eip4844ImplementationMissing & ": state_transition"
# workaround for https://github.com/nim-lang/Nim/issues/20900 rather than have
# these be default arguments

View File

@ -1120,7 +1120,8 @@ func init*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#epoch-processing
proc process_epoch*(
cfg: RuntimeConfig,
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
state: var (altair.BeaconState | bellatrix.BeaconState |
capella.BeaconState | eip4844.BeaconState),
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo):
Result[void, cstring] =
let currentEpoch = get_current_epoch(state)
@ -1142,7 +1143,7 @@ proc process_epoch*(
# the finalization rules triggered.
doAssert state.finalized_checkpoint.epoch + 3 >= currentEpoch
process_inactivity_updates(cfg, state, info) # [New in Altair]
process_inactivity_updates(cfg, state, info)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#process_rewards_and_penalties
process_rewards_and_penalties(cfg, state, info)
@ -1158,7 +1159,7 @@ proc process_epoch*(
process_slashings_reset(state)
process_randao_mixes_reset(state)
process_historical_roots_update(state)
process_participation_flag_updates(state) # [New in Altair]
process_sync_committee_updates(state) # [New in Altair]
process_participation_flag_updates(state)
process_sync_committee_updates(state)
ok()

View File

@ -85,6 +85,7 @@ template saveSSZFile(filename: string, value: ForkedHashedBeaconState) =
of BeaconStateFork.Altair: SSZ.saveFile(filename, value.altairData.data)
of BeaconStateFork.Bellatrix: SSZ.saveFile(filename, value.bellatrixData.data)
of BeaconStateFork.Capella: SSZ.saveFile(filename, value.capellaData.data)
of BeaconStateFork.EIP4844: SSZ.saveFile(filename, value.eip4844Data.data)
proc loadFile(filename: string, T: type): T =
let

View File

@ -330,6 +330,8 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
of BeaconStateFork.Capella:
doAssert dbBenchmark.getState(
forkyState.root, loadedState[3][].data, noRollback)
of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": ncli_db.nim: cmdBench (1)"
if forkyState.data.slot.epoch mod 16 == 0:
let loadedRoot = case stateFork
@ -337,6 +339,7 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
of BeaconStateFork.Altair: hash_tree_root(loadedState[1][].data)
of BeaconStateFork.Bellatrix: hash_tree_root(loadedState[2][].data)
of BeaconStateFork.Capella: hash_tree_root(loadedState[3][].data)
of BeaconStateFork.EIP4844: raiseAssert $eip4844ImplementationMissing & ": ncli_db.nim: cmdBench (2)"
doAssert hash_tree_root(forkyState.data) == loadedRoot
processBlocks(blocks[0])
@ -996,8 +999,11 @@ proc cmdValidatorDb(conf: DbConf, cfg: RuntimeConfig) =
if nextSlot.is_epoch:
withState(tmpState[]):
var stateData = newClone(forkyState.data)
rewardsAndPenalties.collectEpochRewardsAndPenalties(
stateData[], cache, cfg, flags)
when stateFork == BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": ncli_db.nim:cmdValidatorDb"
else:
rewardsAndPenalties.collectEpochRewardsAndPenalties(
stateData[], cache, cfg, flags)
let res = process_slots(cfg, tmpState[], nextSlot, cache, forkedInfo, flags)
doAssert res.isOk, "Slot processing can't fail with correct inputs"

View File

@ -623,6 +623,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
if blockRatio > 0.0:
withTimer(timers[t]):
case dag.cfg.stateForkAtEpoch(slot.epoch)
of BeaconStateFork.EIP4844: raiseAssert $eip4844ImplementationMissing & ": block_sim.nim"
of BeaconStateFork.Capella: proposeCapellaBlock(slot)
of BeaconStateFork.Bellatrix: proposeBellatrixBlock(slot)
of BeaconStateFork.Altair: proposeAltairBlock(slot)

View File

@ -44,6 +44,11 @@ func readValue*(r: var JsonReader, a: var seq[byte]) =
func genesisTestRuntimeConfig*(stateFork: BeaconStateFork): RuntimeConfig =
var res = defaultRuntimeConfig
case stateFork
of BeaconStateFork.EIP4844:
res.EIP4844_FORK_EPOCH = GENESIS_EPOCH
res.CAPELLA_FORK_EPOCH = GENESIS_EPOCH
res.BELLATRIX_FORK_EPOCH = GENESIS_EPOCH
res.ALTAIR_FORK_EPOCH = GENESIS_EPOCH
of BeaconStateFork.Capella:
res.CAPELLA_FORK_EPOCH = GENESIS_EPOCH
res.BELLATRIX_FORK_EPOCH = GENESIS_EPOCH
@ -119,13 +124,20 @@ proc parseTest*(path: string, Format: typedesc[SSZ], T: typedesc): T =
quit 1
from ../../beacon_chain/spec/datatypes/capella import BeaconState
from ../../beacon_chain/spec/datatypes/eip4844 import BeaconState
proc loadForkedState*(
path: string, fork: BeaconStateFork): ref ForkedHashedBeaconState =
# TODO stack usage. newClone and assignClone do not seem to
# prevent temporaries created by case objects
# TODO depends on something like nimOldCaseObjects
let forkedState = new ForkedHashedBeaconState
case fork
of BeaconStateFork.EIP4844:
let state = newClone(parseTest(path, SSZ, eip4844.BeaconState))
forkedState.kind = BeaconStateFork.EIP4844
forkedState.eip4844Data.data = state[]
forkedState.eip4844Data.root = hash_tree_root(state[])
of BeaconStateFork.Capella:
let state = newClone(parseTest(path, SSZ, capella.BeaconState))
forkedState.kind = BeaconStateFork.Capella

View File

@ -165,6 +165,8 @@ proc loadOps(path: string, fork: BeaconStateFork): seq[Operation] =
)
result.add Operation(kind: opOnBlock,
blck: ForkedSignedBeaconBlock.init(blck))
of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": test_fixture_fork_choice.nim:loadOps"
elif step.hasKey"attester_slashing":
let filename = step["attester_slashing"].getStr()
let attesterSlashing = parseTest(
@ -318,6 +320,8 @@ proc doRunTest(path: string, fork: BeaconStateFork) =
let stores =
case fork
of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": test_fixture_fork_choice.nim:doRunTest"
of BeaconStateFork.Capella:
initialLoad(path, db, capella.BeaconState, capella.BeaconBlock)
of BeaconStateFork.Bellatrix:
@ -402,11 +406,9 @@ template fcSuite(suiteName: static[string], testPathElem: static[string]) =
let testsPath = presetPath/path/testPathElem
if kind != pcDir or not dirExists(testsPath):
continue
if path.contains("eip4844"):
continue
let fork = forkForPathComponent(path).valueOr:
if path.contains("eip4844"):
# TODO can either wait if/when 4844 is incorporated into capella or
# add it as next fork even not as part of 4844
continue
raiseAssert "Unknown test fork: " & testsPath
for kind, path in walkDir(testsPath, relative = true, checkDir = true):
let basePath = testsPath/path/"pyspec_tests"

View File

@ -236,6 +236,8 @@ proc addTestBlock*(
addTestBlockAux[capella.ExecutionPayload](
state, cache, eth1_data, attestations, deposits, sync_aggregate,
graffiti, flags, nextSlot, cfg)
of BeaconStateFork.EIP4844:
raiseAssert $eip4844ImplementationMissing & ": tests/testblockutil.nim addTestBlock"
proc makeTestBlock*(
state: ForkedHashedBeaconState,