rename `stateFork` > `consensusFork` (#4718)

Just the variable, not yet `lcDataForkAtStateFork` / `atStateFork`.

- Shorten comment in `light_client.nim` to keep line width
- Do not rename `stateFork` mention in `runProposalForkchoiceUpdated`.
- Do not rename `stateFork` in `getStateField(dag.headState, fork)`

Rest is just a mechanical mass replace
This commit is contained in:
Etan Kissling 2023-03-11 01:35:52 +01:00 committed by GitHub
parent 969c6f73ae
commit ad118cd354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 121 additions and 121 deletions

View File

@ -45,7 +45,7 @@ proc initLightClient*(
dag = node.dag.head.bid, dag = node.dag.head.bid,
wallSlot = node.currentSlot wallSlot = node.currentSlot
withBlck(signedBlock): withBlck(signedBlock):
when stateFork >= ConsensusFork.Bellatrix: when consensusFork >= ConsensusFork.Bellatrix:
if blck.message.is_execution_block: if blck.message.is_execution_block:
template payload(): auto = blck.message.body.execution_payload template payload(): auto = blck.message.body.execution_payload
@ -151,7 +151,7 @@ proc updateLightClientFromDag*(node: BeaconNode) =
return return
var header {.noinit.}: ForkedLightClientHeader var header {.noinit.}: ForkedLightClientHeader
withBlck(bdata): withBlck(bdata):
const lcDataFork = lcDataForkAtStateFork(stateFork) const lcDataFork = lcDataForkAtStateFork(consensusFork)
when lcDataFork > LightClientDataFork.None: when lcDataFork > LightClientDataFork.None:
header = ForkedLightClientHeader(kind: lcDataFork) header = ForkedLightClientHeader(kind: lcDataFork)
header.forky(lcDataFork) = blck.toLightClientHeader(lcDataFork) header.forky(lcDataFork) = blck.toLightClientHeader(lcDataFork)

View File

@ -143,7 +143,7 @@ proc init*(T: type AttestationPool, dag: ChainDAGRef,
var unrealized: FinalityCheckpoints var unrealized: FinalityCheckpoints
if enableTestFeatures in dag.updateFlags and blckRef == dag.head: if enableTestFeatures in dag.updateFlags and blckRef == dag.head:
unrealized = withState(dag.headState): unrealized = withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
forkyState.data.compute_unrealized_finality() forkyState.data.compute_unrealized_finality()
else: else:
var cache: StateCache var cache: StateCache

View File

@ -105,7 +105,7 @@ proc addResolvedHeadBlock(
if enableTestFeatures in dag.updateFlags: if enableTestFeatures in dag.updateFlags:
unrealized = withState(state): unrealized = withState(state):
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
forkyState.data.compute_unrealized_finality() forkyState.data.compute_unrealized_finality()
else: else:
forkyState.data.compute_unrealized_finality(cache) forkyState.data.compute_unrealized_finality(cache)

View File

@ -145,7 +145,7 @@ func validatorKey*(
template is_merge_transition_complete*( template is_merge_transition_complete*(
stateParam: ForkedHashedBeaconState): bool = stateParam: ForkedHashedBeaconState): bool =
withState(stateParam): withState(stateParam):
when stateFork >= ConsensusFork.Bellatrix: when consensusFork >= ConsensusFork.Bellatrix:
is_merge_transition_complete(forkyState.data) is_merge_transition_complete(forkyState.data)
else: else:
false false
@ -757,7 +757,7 @@ proc currentSyncCommitteeForPeriod*(
bsi = ? dag.getBlockIdAtSlot(syncCommitteeSlot) bsi = ? dag.getBlockIdAtSlot(syncCommitteeSlot)
dag.withUpdatedState(tmpState, bsi) do: dag.withUpdatedState(tmpState, bsi) do:
withState(updatedState): withState(updatedState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
ok forkyState.data.current_sync_committee ok forkyState.data.current_sync_committee
else: err() else: err()
do: err() do: err()
@ -1037,7 +1037,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
quit 1 quit 1
withState(dag.headState): withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache) dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache)
block: block:
@ -1218,7 +1218,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
# If these aren't actually optimistic, the first fcU will resolve that # If these aren't actually optimistic, the first fcU will resolve that
withState(dag.headState): withState(dag.headState):
when stateFork >= ConsensusFork.Bellatrix: when consensusFork >= ConsensusFork.Bellatrix:
template executionPayloadHeader(): auto = template executionPayloadHeader(): auto =
forkyState().data.latest_execution_payload_header forkyState().data.latest_execution_payload_header
const emptyExecutionPayloadHeader = const emptyExecutionPayloadHeader =
@ -1735,7 +1735,7 @@ iterator syncSubcommitteePairs*(
func syncCommitteeParticipants*(dag: ChainDAGRef, func syncCommitteeParticipants*(dag: ChainDAGRef,
slot: Slot): seq[ValidatorIndex] = slot: Slot): seq[ValidatorIndex] =
withState(dag.headState): withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
let let
period = sync_committee_period(slot) period = sync_committee_period(slot)
curPeriod = sync_committee_period(forkyState.data.slot) curPeriod = sync_committee_period(forkyState.data.slot)
@ -1765,7 +1765,7 @@ func getSubcommitteePositions*(
subcommitteeIdx: SyncSubcommitteeIndex, subcommitteeIdx: SyncSubcommitteeIndex,
validatorIdx: uint64): seq[uint64] = validatorIdx: uint64): seq[uint64] =
withState(dag.headState): withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
let let
period = sync_committee_period(slot) period = sync_committee_period(slot)
curPeriod = sync_committee_period(forkyState.data.slot) curPeriod = sync_committee_period(forkyState.data.slot)
@ -1954,9 +1954,9 @@ proc pruneHistory*(dag: ChainDAGRef, startup = false) =
# so as to "mostly" clean up the phase0 tables as well (which cannot be # so as to "mostly" clean up the phase0 tables as well (which cannot be
# pruned easily by fork) # pruned easily by fork)
let stateFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch) let consensusFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch)
if stateFork > ConsensusFork.Phase0: if consensusFork > ConsensusFork.Phase0:
for fork in ConsensusFork.Phase0..<stateFork: for fork in ConsensusFork.Phase0..<consensusFork:
dag.db.clearStates(fork) dag.db.clearStates(fork)
let blockFork = dag.cfg.consensusForkAtEpoch(blockHorizon.epoch) let blockFork = dag.cfg.consensusForkAtEpoch(blockHorizon.epoch)
@ -1973,7 +1973,7 @@ proc loadExecutionBlockRoot*(dag: ChainDAGRef, bid: BlockId): Eth2Digest =
return ZERO_HASH return ZERO_HASH
withBlck(blockData): withBlck(blockData):
when stateFork >= ConsensusFork.Bellatrix: when consensusFork >= ConsensusFork.Bellatrix:
blck.message.body.execution_payload.block_hash blck.message.body.execution_payload.block_hash
else: else:
ZERO_HASH ZERO_HASH
@ -2099,7 +2099,7 @@ proc updateHead*(
updateBeaconMetrics(dag.headState, dag.head.bid, cache) updateBeaconMetrics(dag.headState, dag.head.bid, cache)
withState(dag.headState): withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache) dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache)
let let

View File

@ -119,7 +119,7 @@ proc syncCommitteeRootForPeriod(
bsi = ? dag.getExistingBlockIdAtSlot(syncCommitteeSlot) bsi = ? dag.getExistingBlockIdAtSlot(syncCommitteeSlot)
dag.withUpdatedExistingState(tmpState, bsi) do: dag.withUpdatedExistingState(tmpState, bsi) do:
withState(updatedState): withState(updatedState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
ok forkyState.syncCommitteeRoot ok forkyState.syncCommitteeRoot
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
do: err() do: err()
@ -213,8 +213,8 @@ proc initLightClientBootstrapForPeriod(
res.err() res.err()
continue continue
withStateAndBlck(tmpState[], bdata): withStateAndBlck(tmpState[], bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork) const lcDataFork = lcDataForkAtStateFork(consensusFork)
if not dag.lcDataStore.db.hasSyncCommittee(period): if not dag.lcDataStore.db.hasSyncCommittee(period):
dag.lcDataStore.db.putSyncCommittee( dag.lcDataStore.db.putSyncCommittee(
period, forkyState.data.current_sync_committee) period, forkyState.data.current_sync_committee)
@ -274,7 +274,7 @@ proc initLightClientUpdateForPeriod(
break break
numParticipants = numParticipants =
withBlck(bdata): withBlck(bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
blck.message.body.sync_aggregate.num_active_participants blck.message.body.sync_aggregate.num_active_participants
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
if numParticipants >= maxParticipants: if numParticipants >= maxParticipants:
@ -332,7 +332,7 @@ proc initLightClientUpdateForPeriod(
finalizedEpoch = block: finalizedEpoch = block:
dag.withUpdatedExistingState(tmpState[], attestedBid.atSlot) do: dag.withUpdatedExistingState(tmpState[], attestedBid.atSlot) do:
withState(updatedState): withState(updatedState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
forkyState.data.finalized_checkpoint.epoch forkyState.data.finalized_checkpoint.epoch
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
do: do:
@ -364,8 +364,8 @@ proc initLightClientUpdateForPeriod(
dag.handleUnexpectedLightClientError(bid.slot) dag.handleUnexpectedLightClientError(bid.slot)
return err() return err()
withStateAndBlck(updatedState, bdata): withStateAndBlck(updatedState, bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork) const lcDataFork = lcDataForkAtStateFork(consensusFork)
update = ForkedLightClientUpdate(kind: lcDataFork) update = ForkedLightClientUpdate(kind: lcDataFork)
template forkyUpdate: untyped = update.forky(lcDataFork) template forkyUpdate: untyped = update.forky(lcDataFork)
forkyUpdate.attested_header = blck.toLightClientHeader(lcDataFork) forkyUpdate.attested_header = blck.toLightClientHeader(lcDataFork)
@ -386,14 +386,14 @@ proc initLightClientUpdateForPeriod(
withBlck(bdata): withBlck(bdata):
withForkyUpdate(update): withForkyUpdate(update):
when lcDataFork > LightClientDataFork.None: when lcDataFork > LightClientDataFork.None:
when lcDataFork >= lcDataForkAtStateFork(stateFork): when lcDataFork >= lcDataForkAtStateFork(consensusFork):
forkyUpdate.finalized_header = blck.toLightClientHeader(lcDataFork) forkyUpdate.finalized_header = blck.toLightClientHeader(lcDataFork)
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
let bdata = dag.getExistingForkedBlock(signatureBid).valueOr: let bdata = dag.getExistingForkedBlock(signatureBid).valueOr:
dag.handleUnexpectedLightClientError(signatureBid.slot) dag.handleUnexpectedLightClientError(signatureBid.slot)
return err() return err()
withBlck(bdata): withBlck(bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
withForkyUpdate(update): withForkyUpdate(update):
when lcDataFork > LightClientDataFork.None: when lcDataFork > LightClientDataFork.None:
forkyUpdate.sync_aggregate = forkyUpdate.sync_aggregate =
@ -477,7 +477,7 @@ template lazy_header(name: untyped): untyped {.dirty.} =
`name _ ok` = false `name _ ok` = false
else: else:
withBlck(bdata.get): withBlck(bdata.get):
when data_fork >= lcDataForkAtStateFork(stateFork): when data_fork >= lcDataForkAtStateFork(consensusFork):
obj.name = blck.toLightClientHeader(data_fork) obj.name = blck.toLightClientHeader(data_fork)
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
`name _ ptr` = addr obj.name `name _ ptr` = addr obj.name
@ -495,7 +495,7 @@ template lazy_header(name: untyped): untyped {.dirty.} =
else: else:
obj.migrateToDataFork(data_fork) obj.migrateToDataFork(data_fork)
withBlck(bdata.get): withBlck(bdata.get):
when data_fork >= lcDataForkAtStateFork(stateFork): when data_fork >= lcDataForkAtStateFork(consensusFork):
obj.forky(data_fork).name = blck.toLightClientHeader(data_fork) obj.forky(data_fork).name = blck.toLightClientHeader(data_fork)
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
`name _ ptr` = addr obj.forky(data_fork).name `name _ ptr` = addr obj.forky(data_fork).name
@ -686,7 +686,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
if dag.head.slot < dag.lcDataStore.cache.tailSlot: if dag.head.slot < dag.lcDataStore.cache.tailSlot:
return return
withState(dag.headState): withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
dag.cacheLightClientData(forkyState, dag.head.bid) dag.cacheLightClientData(forkyState, dag.head.bid)
else: raiseAssert "Unreachable" # `tailSlot` cannot be before Altair else: raiseAssert "Unreachable" # `tailSlot` cannot be before Altair
if dag.lcDataStore.importMode == LightClientDataImportMode.OnlyNew: if dag.lcDataStore.importMode == LightClientDataImportMode.OnlyNew:
@ -737,7 +737,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
res.err() res.err()
continue continue
withStateAndBlck(dag.headState, bdata): withStateAndBlck(dag.headState, bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
# Cache light client data (non-finalized blocks may refer to this) # Cache light client data (non-finalized blocks may refer to this)
if i != blocks.low: if i != blocks.low:
dag.cacheLightClientData(forkyState, bid) # `dag.head` already cached dag.cacheLightClientData(forkyState, bid) # `dag.head` already cached
@ -826,7 +826,7 @@ proc processHeadChangeForLightClient*(dag: ChainDAGRef) =
dag.lcDataStore.db.putBestUpdate( dag.lcDataStore.db.putBestUpdate(
period, dag.lcDataStore.cache.pendingBest.getOrDefault(key)) period, dag.lcDataStore.cache.pendingBest.getOrDefault(key))
withState(dag.headState): # Common case separate to avoid `tmpState` copy withState(dag.headState): # Common case separate to avoid `tmpState` copy
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
let key = (headPeriod, forkyState.syncCommitteeRoot) let key = (headPeriod, forkyState.syncCommitteeRoot)
dag.lcDataStore.db.putBestUpdate( dag.lcDataStore.db.putBestUpdate(
headPeriod, dag.lcDataStore.cache.pendingBest.getOrDefault(key)) headPeriod, dag.lcDataStore.cache.pendingBest.getOrDefault(key))
@ -862,7 +862,7 @@ proc processFinalizationForLightClient*(
period = bid.slot.sync_committee_period period = bid.slot.sync_committee_period
if not dag.lcDataStore.db.hasSyncCommittee(period): if not dag.lcDataStore.db.hasSyncCommittee(period):
let didPutSyncCommittee = withState(dag.headState): let didPutSyncCommittee = withState(dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
if period == forkyState.data.slot.sync_committee_period: if period == forkyState.data.slot.sync_committee_period:
dag.lcDataStore.db.putSyncCommittee( dag.lcDataStore.db.putSyncCommittee(
period, forkyState.data.current_sync_committee) period, forkyState.data.current_sync_committee)
@ -880,8 +880,8 @@ proc processFinalizationForLightClient*(
break break
dag.lcDataStore.db.putSyncCommittee(period, syncCommittee) dag.lcDataStore.db.putSyncCommittee(period, syncCommittee)
withBlck(bdata): withBlck(bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork) const lcDataFork = lcDataForkAtStateFork(consensusFork)
dag.lcDataStore.db.putHeader(blck.toLightClientHeader(lcDataFork)) dag.lcDataStore.db.putHeader(blck.toLightClientHeader(lcDataFork))
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"
dag.lcDataStore.db.putCurrentSyncCommitteeBranch( dag.lcDataStore.db.putCurrentSyncCommitteeBranch(
@ -949,7 +949,7 @@ proc getLightClientBootstrap(
tmpState = assignClone(dag.headState) tmpState = assignClone(dag.headState)
dag.withUpdatedExistingState(tmpState[], bsi) do: dag.withUpdatedExistingState(tmpState[], bsi) do:
withState(updatedState): withState(updatedState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
if not dag.lcDataStore.db.hasSyncCommittee(period): if not dag.lcDataStore.db.hasSyncCommittee(period):
dag.lcDataStore.db.putSyncCommittee( dag.lcDataStore.db.putSyncCommittee(
period, forkyState.data.current_sync_committee) period, forkyState.data.current_sync_committee)
@ -1003,8 +1003,8 @@ proc getLightClientBootstrap*(
debug "LC bootstrap unavailable: Block not found", blockRoot debug "LC bootstrap unavailable: Block not found", blockRoot
return default(ForkedLightClientBootstrap) return default(ForkedLightClientBootstrap)
withBlck(bdata): withBlck(bdata):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork) const lcDataFork = lcDataForkAtStateFork(consensusFork)
let let
header = blck.toLightClientHeader(lcDataFork) header = blck.toLightClientHeader(lcDataFork)
bootstrap = dag.getLightClientBootstrap(header) bootstrap = dag.getLightClientBootstrap(header)

View File

@ -330,7 +330,7 @@ proc runProposalForkchoiceUpdated*(
feeRecipient = self[].getFeeRecipient( feeRecipient = self[].getFeeRecipient(
nextProposer, Opt.some(validatorIndex), nextWallSlot.epoch) nextProposer, Opt.some(validatorIndex), nextWallSlot.epoch)
withdrawals = withState(self.dag.headState): withdrawals = withState(self.dag.headState):
when stateFork >= ConsensusFork.Capella: when consensusFork >= ConsensusFork.Capella:
Opt.some get_expected_withdrawals(forkyState.data) Opt.some get_expected_withdrawals(forkyState.data)
else: else:
Opt.none(seq[Withdrawal]) Opt.none(seq[Withdrawal])
@ -352,7 +352,7 @@ proc runProposalForkchoiceUpdated*(
debug "Fork-choice updated for proposal", status debug "Fork-choice updated for proposal", status
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
when stateFork >= ConsensusFork.Capella: when consensusFork >= ConsensusFork.Capella:
callForkchoiceUpdated(PayloadAttributesV2( callForkchoiceUpdated(PayloadAttributesV2(
timestamp: Quantity timestamp, timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData, prevRandao: FixedBytes[32] randomData,

View File

@ -420,7 +420,7 @@ proc storeBlock*(
trustedBlock.message.slot) trustedBlock.message.slot)
withState(dag[].clearanceState): withState(dag[].clearanceState):
when stateFork >= ConsensusFork.Altair and when consensusFork >= ConsensusFork.Altair and
Trusted isnot phase0.TrustedSignedBeaconBlock: # altair+ Trusted isnot phase0.TrustedSignedBeaconBlock: # altair+
for i in trustedBlock.message.body.sync_aggregate.sync_committee_bits.oneIndices(): for i in trustedBlock.message.body.sync_aggregate.sync_committee_bits.oneIndices():
vm[].registerSyncAggregateInBlock( vm[].registerSyncAggregateInBlock(

View File

@ -765,7 +765,7 @@ proc validateBlsToExecutionChange*(
# [REJECT] All of the conditions within `process_bls_to_execution_change` # [REJECT] All of the conditions within `process_bls_to_execution_change`
# pass validation. # pass validation.
withState(pool.dag.headState): withState(pool.dag.headState):
when stateFork < ConsensusFork.Capella: when consensusFork < ConsensusFork.Capella:
return errIgnore("validateBlsToExecutionChange: can't validate against pre-Capella state") return errIgnore("validateBlsToExecutionChange: can't validate against pre-Capella state")
else: else:
let res = check_bls_to_execution_change( let res = check_bls_to_execution_change(

View File

@ -343,11 +343,11 @@ proc installMessageValidators*(
ValidationResult.Ignore ValidationResult.Ignore
let forkDigests = lightClient.forkDigests let forkDigests = lightClient.forkDigests
for stateFork in ConsensusFork: for consensusFork in ConsensusFork:
withLcDataFork(lcDataForkAtStateFork(stateFork)): withLcDataFork(lcDataForkAtStateFork(consensusFork)):
when lcDataFork > LightClientDataFork.None: when lcDataFork > LightClientDataFork.None:
let let
contextFork = stateFork # Copy to avoid capturing `Deneb` (Nim 1.6) contextFork = consensusFork # Avoid capturing `Deneb` (Nim 1.6)
digest = forkDigests[].atStateFork(contextFork) digest = forkDigests[].atStateFork(contextFork)
lightClient.network.addValidator( lightClient.network.addValidator(

View File

@ -862,7 +862,7 @@ func hasSyncPubKey(node: BeaconNode, epoch: Epoch): auto =
func getCurrentSyncCommiteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits = func getCurrentSyncCommiteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
let syncCommittee = withState(node.dag.headState): let syncCommittee = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
forkyState.data.current_sync_committee forkyState.data.current_sync_committee
else: else:
return static(default(SyncnetBits)) return static(default(SyncnetBits))
@ -871,7 +871,7 @@ func getCurrentSyncCommiteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits
func getNextSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits = func getNextSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
let syncCommittee = withState(node.dag.headState): let syncCommittee = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
forkyState.data.next_sync_committee forkyState.data.next_sync_committee
else: else:
return static(default(SyncnetBits)) return static(default(SyncnetBits))

View File

@ -105,7 +105,7 @@ programMain:
opt = signedBlock.toBlockId(), opt = signedBlock.toBlockId(),
wallSlot = getBeaconTime().slotOrZero wallSlot = getBeaconTime().slotOrZero
withBlck(signedBlock): withBlck(signedBlock):
when stateFork >= ConsensusFork.Bellatrix: when consensusFork >= ConsensusFork.Bellatrix:
if blck.message.is_execution_block: if blck.message.is_execution_block:
template payload(): auto = blck.message.body.execution_payload template payload(): auto = blck.message.body.execution_payload

View File

@ -233,7 +233,7 @@ func syncCommitteeParticipants*(forkedState: ForkedHashedBeaconState,
epoch: Epoch epoch: Epoch
): Result[seq[ValidatorPubKey], cstring] = ): Result[seq[ValidatorPubKey], cstring] =
withState(forkedState): withState(forkedState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
let let
epochPeriod = sync_committee_period(epoch) epochPeriod = sync_committee_period(epoch)
curPeriod = sync_committee_period(forkyState.data.slot) curPeriod = sync_committee_period(forkyState.data.slot)

View File

@ -247,7 +247,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
if qSyncPeriod == headSyncPeriod: if qSyncPeriod == headSyncPeriod:
let optimistic = node.getStateOptimistic(node.dag.headState) let optimistic = node.getStateOptimistic(node.dag.headState)
let res = withState(node.dag.headState): let res = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
produceResponse(indexList, produceResponse(indexList,
forkyState.data.current_sync_committee.pubkeys.data, forkyState.data.current_sync_committee.pubkeys.data,
forkyState.data.validators.asSeq) forkyState.data.validators.asSeq)
@ -257,7 +257,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
elif qSyncPeriod == (headSyncPeriod + 1): elif qSyncPeriod == (headSyncPeriod + 1):
let optimistic = node.getStateOptimistic(node.dag.headState) let optimistic = node.getStateOptimistic(node.dag.headState)
let res = withState(node.dag.headState): let res = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
produceResponse(indexList, produceResponse(indexList,
forkyState.data.next_sync_committee.pubkeys.data, forkyState.data.next_sync_committee.pubkeys.data,
forkyState.data.validators.asSeq) forkyState.data.validators.asSeq)
@ -288,7 +288,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
node.withStateForBlockSlotId(bsi): node.withStateForBlockSlotId(bsi):
let optimistic = node.getStateOptimistic(state) let optimistic = node.getStateOptimistic(state)
let res = withState(state): let res = withState(state):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
produceResponse(indexList, produceResponse(indexList,
forkyState.data.current_sync_committee.pubkeys.data, forkyState.data.current_sync_committee.pubkeys.data,
forkyState.data.validators.asSeq) forkyState.data.validators.asSeq)

View File

@ -282,19 +282,19 @@ template withStateFork*(
x: ConsensusFork, body: untyped): untyped = x: ConsensusFork, body: untyped): untyped =
case x case x
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
const stateFork {.inject, used.} = ConsensusFork.Deneb const consensusFork {.inject, used.} = ConsensusFork.Deneb
body body
of ConsensusFork.Capella: of ConsensusFork.Capella:
const stateFork {.inject, used.} = ConsensusFork.Capella const consensusFork {.inject, used.} = ConsensusFork.Capella
body body
of ConsensusFork.Bellatrix: of ConsensusFork.Bellatrix:
const stateFork {.inject, used.} = ConsensusFork.Bellatrix const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
body body
of ConsensusFork.Altair: of ConsensusFork.Altair:
const stateFork {.inject, used.} = ConsensusFork.Altair const consensusFork {.inject, used.} = ConsensusFork.Altair
body body
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
const stateFork {.inject, used.} = ConsensusFork.Phase0 const consensusFork {.inject, used.} = ConsensusFork.Phase0
body body
# TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type # TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type
@ -533,23 +533,23 @@ template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T =
template withState*(x: ForkedHashedBeaconState, body: untyped): untyped = template withState*(x: ForkedHashedBeaconState, body: untyped): untyped =
case x.kind case x.kind
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
const stateFork {.inject, used.} = ConsensusFork.Deneb const consensusFork {.inject, used.} = ConsensusFork.Deneb
template forkyState: untyped {.inject, used.} = x.denebData template forkyState: untyped {.inject, used.} = x.denebData
body body
of ConsensusFork.Capella: of ConsensusFork.Capella:
const stateFork {.inject, used.} = ConsensusFork.Capella const consensusFork {.inject, used.} = ConsensusFork.Capella
template forkyState: untyped {.inject, used.} = x.capellaData template forkyState: untyped {.inject, used.} = x.capellaData
body body
of ConsensusFork.Bellatrix: of ConsensusFork.Bellatrix:
const stateFork {.inject, used.} = ConsensusFork.Bellatrix const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
template forkyState: untyped {.inject, used.} = x.bellatrixData template forkyState: untyped {.inject, used.} = x.bellatrixData
body body
of ConsensusFork.Altair: of ConsensusFork.Altair:
const stateFork {.inject, used.} = ConsensusFork.Altair const consensusFork {.inject, used.} = ConsensusFork.Altair
template forkyState: untyped {.inject, used.} = x.altairData template forkyState: untyped {.inject, used.} = x.altairData
body body
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
const stateFork {.inject, used.} = ConsensusFork.Phase0 const consensusFork {.inject, used.} = ConsensusFork.Phase0
template forkyState: untyped {.inject, used.} = x.phase0Data template forkyState: untyped {.inject, used.} = x.phase0Data
body body
@ -652,8 +652,8 @@ func stateForkForDigest*(
err() err()
func atStateFork*( func atStateFork*(
forkDigests: ForkDigests, stateFork: ConsensusFork): ForkDigest = forkDigests: ForkDigests, consensusFork: ConsensusFork): ForkDigest =
case stateFork case consensusFork
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
forkDigests.deneb forkDigests.deneb
of ConsensusFork.Capella: of ConsensusFork.Capella:
@ -713,23 +713,23 @@ template withBlck*(
body: untyped): untyped = body: untyped): untyped =
case x.kind case x.kind
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
const stateFork {.inject, used.} = ConsensusFork.Phase0 const consensusFork {.inject, used.} = ConsensusFork.Phase0
template blck: untyped {.inject.} = x.phase0Data template blck: untyped {.inject.} = x.phase0Data
body body
of ConsensusFork.Altair: of ConsensusFork.Altair:
const stateFork {.inject, used.} = ConsensusFork.Altair const consensusFork {.inject, used.} = ConsensusFork.Altair
template blck: untyped {.inject.} = x.altairData template blck: untyped {.inject.} = x.altairData
body body
of ConsensusFork.Bellatrix: of ConsensusFork.Bellatrix:
const stateFork {.inject, used.} = ConsensusFork.Bellatrix const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
template blck: untyped {.inject.} = x.bellatrixData template blck: untyped {.inject.} = x.bellatrixData
body body
of ConsensusFork.Capella: of ConsensusFork.Capella:
const stateFork {.inject, used.} = ConsensusFork.Capella const consensusFork {.inject, used.} = ConsensusFork.Capella
template blck: untyped {.inject.} = x.capellaData template blck: untyped {.inject.} = x.capellaData
body body
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
const stateFork {.inject, used.} = ConsensusFork.Deneb const consensusFork {.inject, used.} = ConsensusFork.Deneb
template blck: untyped {.inject.} = x.denebData template blck: untyped {.inject.} = x.denebData
body body
@ -793,27 +793,27 @@ template withStateAndBlck*(
body: untyped): untyped = body: untyped): untyped =
case s.kind case s.kind
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
const stateFork {.inject.} = ConsensusFork.Deneb const consensusFork {.inject.} = ConsensusFork.Deneb
template forkyState: untyped {.inject.} = s.denebData template forkyState: untyped {.inject.} = s.denebData
template blck: untyped {.inject.} = b.denebData template blck: untyped {.inject.} = b.denebData
body body
of ConsensusFork.Capella: of ConsensusFork.Capella:
const stateFork {.inject.} = ConsensusFork.Capella const consensusFork {.inject.} = ConsensusFork.Capella
template forkyState: untyped {.inject.} = s.capellaData template forkyState: untyped {.inject.} = s.capellaData
template blck: untyped {.inject.} = b.capellaData template blck: untyped {.inject.} = b.capellaData
body body
of ConsensusFork.Bellatrix: of ConsensusFork.Bellatrix:
const stateFork {.inject.} = ConsensusFork.Bellatrix const consensusFork {.inject.} = ConsensusFork.Bellatrix
template forkyState: untyped {.inject.} = s.bellatrixData template forkyState: untyped {.inject.} = s.bellatrixData
template blck: untyped {.inject.} = b.bellatrixData template blck: untyped {.inject.} = b.bellatrixData
body body
of ConsensusFork.Altair: of ConsensusFork.Altair:
const stateFork {.inject.} = ConsensusFork.Altair const consensusFork {.inject.} = ConsensusFork.Altair
template forkyState: untyped {.inject.} = s.altairData template forkyState: untyped {.inject.} = s.altairData
template blck: untyped {.inject.} = b.altairData template blck: untyped {.inject.} = b.altairData
body body
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
const stateFork {.inject.} = ConsensusFork.Phase0 const consensusFork {.inject.} = ConsensusFork.Phase0
template forkyState: untyped {.inject.} = s.phase0Data template forkyState: untyped {.inject.} = s.phase0Data
template blck: untyped {.inject.} = b.phase0Data template blck: untyped {.inject.} = b.phase0Data
body body
@ -903,13 +903,13 @@ func forkVersion*(cfg: RuntimeConfig, consensusFork: ConsensusFork): Version =
of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION
of ConsensusFork.Deneb: cfg.DENEB_FORK_VERSION of ConsensusFork.Deneb: cfg.DENEB_FORK_VERSION
func lcDataForkAtStateFork*(stateFork: ConsensusFork): LightClientDataFork = func lcDataForkAtStateFork*(consensusFork: ConsensusFork): LightClientDataFork =
static: doAssert LightClientDataFork.high == LightClientDataFork.Deneb static: doAssert LightClientDataFork.high == LightClientDataFork.Deneb
if stateFork >= ConsensusFork.Deneb: if consensusFork >= ConsensusFork.Deneb:
LightClientDataFork.Deneb LightClientDataFork.Deneb
elif stateFork >= ConsensusFork.Capella: elif consensusFork >= ConsensusFork.Capella:
LightClientDataFork.Capella LightClientDataFork.Capella
elif stateFork >= ConsensusFork.Altair: elif consensusFork >= ConsensusFork.Altair:
LightClientDataFork.Altair LightClientDataFork.Altair
else: else:
LightClientDataFork.None LightClientDataFork.None

View File

@ -387,7 +387,7 @@ proc collectSignatureSets*(
# 7. SyncAggregate # 7. SyncAggregate
# ---------------------------------------------------- # ----------------------------------------------------
withState(state): withState(state):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
if signed_block.message.body.sync_aggregate.sync_committee_bits.countOnes() == 0: if signed_block.message.body.sync_aggregate.sync_committee_bits.countOnes() == 0:
if signed_block.message.body.sync_aggregate.sync_committee_signature != ValidatorSig.infinity(): if signed_block.message.body.sync_aggregate.sync_committee_signature != ValidatorSig.infinity():
return err("collectSignatureSets: empty sync aggregates need signature of point at infinity") return err("collectSignatureSets: empty sync aggregates need signature of point at infinity")
@ -412,7 +412,7 @@ proc collectSignatureSets*(
# 8. BLS to execution changes # 8. BLS to execution changes
when typeof(signed_block).toFork() >= ConsensusFork.Capella: when typeof(signed_block).toFork() >= ConsensusFork.Capella:
withState(state): withState(state):
when stateFork >= ConsensusFork.Capella: when consensusFork >= ConsensusFork.Capella:
for bls_change in signed_block.message.body.bls_to_execution_changes: for bls_change in signed_block.message.body.bls_to_execution_changes:
let sig = bls_change.signature.load.valueOr: let sig = bls_change.signature.load.valueOr:
return err("collectSignatureSets: cannot load BLS to execution change signature") return err("collectSignatureSets: cannot load BLS to execution change signature")

View File

@ -293,7 +293,7 @@ proc state_transition_block*(
doAssert not rollback.isNil, "use noRollback if it's ok to mess up state" doAssert not rollback.isNil, "use noRollback if it's ok to mess up state"
let res = withState(state): let res = withState(state):
when stateFork == type(signedBlock).toFork: when consensusFork == type(signedBlock).toFork:
state_transition_block_aux(cfg, forkyState, signedBlock, cache, flags) state_transition_block_aux(cfg, forkyState, signedBlock, cache, flags)
else: else:
err("State/block fork mismatch") err("State/block fork mismatch")
@ -530,10 +530,10 @@ proc makeBeaconBlock*(
# Override for MEV # Override for MEV
if transactions_root.isSome and execution_payload_root.isSome: if transactions_root.isSome and execution_payload_root.isSome:
withState(state): withState(state):
when stateFork < ConsensusFork.Bellatrix: when consensusFork < ConsensusFork.Bellatrix:
# Vacuously # Vacuously
discard discard
elif stateFork == ConsensusFork.Bellatrix: elif consensusFork == ConsensusFork.Bellatrix:
forkyState.data.latest_execution_payload_header.transactions_root = forkyState.data.latest_execution_payload_header.transactions_root =
transactions_root.get transactions_root.get
@ -552,7 +552,7 @@ proc makeBeaconBlock*(
hash_tree_root(validator_changes.voluntary_exits), hash_tree_root(validator_changes.voluntary_exits),
hash_tree_root(sync_aggregate), hash_tree_root(sync_aggregate),
execution_payload_root.get]) execution_payload_root.get])
elif stateFork == ConsensusFork.Capella: elif consensusFork == ConsensusFork.Capella:
forkyState.data.latest_execution_payload_header.transactions_root = forkyState.data.latest_execution_payload_header.transactions_root =
transactions_root.get transactions_root.get
@ -572,7 +572,7 @@ proc makeBeaconBlock*(
hash_tree_root(sync_aggregate), hash_tree_root(sync_aggregate),
execution_payload_root.get, execution_payload_root.get,
hash_tree_root(validator_changes.bls_to_execution_changes)]) hash_tree_root(validator_changes.bls_to_execution_changes)])
elif stateFork > ConsensusFork.Capella: elif consensusFork > ConsensusFork.Capella:
discard denebImplementationMissing discard denebImplementationMissing
state.`kind Data`.root = hash_tree_root(state.`kind Data`.data) state.`kind Data`.root = hash_tree_root(state.`kind Data`.data)

View File

@ -83,10 +83,10 @@ proc doTrustedNodeSync*(
genesisRoot = genesisRoot.get() genesisRoot = genesisRoot.get()
quit 1 quit 1
genesisStateRoot = getForkedBlockField(genesisBlock, state_root) genesisStateRoot = getForkedBlockField(genesisBlock, state_root)
stateFork = cfg.consensusForkAtEpoch(GENESIS_EPOCH) consensusFork = cfg.consensusForkAtEpoch(GENESIS_EPOCH)
tmp = (ref ForkedHashedBeaconState)(kind: stateFork) tmp = (ref ForkedHashedBeaconState)(kind: consensusFork)
if not db.getState(stateFork, genesisStateRoot, tmp[], noRollback): if not db.getState(consensusFork, genesisStateRoot, tmp[], noRollback):
error "Cannot load genesis state from database", error "Cannot load genesis state from database",
genesisStateRoot genesisStateRoot
quit 1 quit 1

View File

@ -271,7 +271,7 @@ proc routeSyncCommitteeMessages*(
router: ref MessageRouter, msgs: seq[SyncCommitteeMessage]): router: ref MessageRouter, msgs: seq[SyncCommitteeMessage]):
Future[seq[SendResult]] {.async.} = Future[seq[SendResult]] {.async.} =
return withState(router[].dag.headState): return withState(router[].dag.headState):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
var statuses = newSeq[Option[SendResult]](len(msgs)) var statuses = newSeq[Option[SendResult]](len(msgs))
let let

View File

@ -298,16 +298,16 @@ proc getExecutionPayload(
# transmit this information through the Forked types, so this has to # transmit this information through the Forked types, so this has to
# be re-proven here. # be re-proven here.
withState(proposalState[]): withState(proposalState[]):
when stateFork >= ConsensusFork.Capella: when consensusFork >= ConsensusFork.Capella:
# As of Capella, because EL state root changes in way more difficult to # As of Capella, because EL state root changes in way more difficult to
# compute way from CL due to incorporation of withdrawals into EL state # compute way from CL due to incorporation of withdrawals into EL state
# cannot use fake-EL fallback. Unlike transactions, withdrawals are not # cannot use fake-EL fallback. Unlike transactions, withdrawals are not
# optional, so one cannot avoid this by not including any withdrawals. # optional, so one cannot avoid this by not including any withdrawals.
Opt.none PayloadType Opt.none PayloadType
elif (stateFork == ConsensusFork.Bellatrix and elif (consensusFork == ConsensusFork.Bellatrix and
PayloadType is bellatrix.ExecutionPayloadForSigning): PayloadType is bellatrix.ExecutionPayloadForSigning):
Opt.some build_empty_execution_payload(forkyState.data, feeRecipient) Opt.some build_empty_execution_payload(forkyState.data, feeRecipient)
elif stateFork == ConsensusFork.Bellatrix: elif consensusFork == ConsensusFork.Bellatrix:
raiseAssert "getExecutionPayload: mismatched proposalState and ExecutionPayload fork" raiseAssert "getExecutionPayload: mismatched proposalState and ExecutionPayload fork"
else: else:
# Vacuously -- these are pre-Bellatrix and not used. # Vacuously -- these are pre-Bellatrix and not used.
@ -317,7 +317,7 @@ proc getExecutionPayload(
let let
beaconHead = node.attestationPool[].getBeaconHead(node.dag.head) beaconHead = node.attestationPool[].getBeaconHead(node.dag.head)
executionHead = withState(proposalState[]): executionHead = withState(proposalState[]):
when stateFork >= ConsensusFork.Bellatrix: when consensusFork >= ConsensusFork.Bellatrix:
forkyState.data.latest_execution_payload_header.block_hash forkyState.data.latest_execution_payload_header.block_hash
else: else:
(static(default(Eth2Digest))) (static(default(Eth2Digest)))
@ -328,7 +328,7 @@ proc getExecutionPayload(
random = withState(proposalState[]): random = withState(proposalState[]):
get_randao_mix(forkyState.data, get_current_epoch(forkyState.data)) get_randao_mix(forkyState.data, get_current_epoch(forkyState.data))
withdrawals = withState(proposalState[]): withdrawals = withState(proposalState[]):
when stateFork >= ConsensusFork.Capella: when consensusFork >= ConsensusFork.Capella:
get_expected_withdrawals(forkyState.data) get_expected_withdrawals(forkyState.data)
else: else:
@[] @[]
@ -386,7 +386,7 @@ proc makeBeaconBlockForHeadAndSlot*(
# it won't have transactions (it's blinded) # it won't have transactions (it's blinded)
var modified_execution_payload = execution_payload var modified_execution_payload = execution_payload
withState(state[]): withState(state[]):
when stateFork >= ConsensusFork.Capella and when consensusFork >= ConsensusFork.Capella and
PayloadType.toFork >= ConsensusFork.Capella: PayloadType.toFork >= ConsensusFork.Capella:
let withdrawals = List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]( let withdrawals = List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD](
get_expected_withdrawals(forkyState.data)) get_expected_withdrawals(forkyState.data))
@ -590,15 +590,15 @@ proc getBlindedBeaconBlock[
capella.ExecutionPayloadHeader): capella.ExecutionPayloadHeader):
Future[Result[T, string]] {.async.} = Future[Result[T, string]] {.async.} =
withBlck(forkedBlock): withBlck(forkedBlock):
when stateFork >= ConsensusFork.Deneb: when consensusFork >= ConsensusFork.Deneb:
debugRaiseAssert $denebImplementationMissing & ": getBlindedBeaconBlock" debugRaiseAssert $denebImplementationMissing & ": getBlindedBeaconBlock"
return err("getBlindedBeaconBlock: Deneb blinded block creation not implemented") return err("getBlindedBeaconBlock: Deneb blinded block creation not implemented")
elif stateFork >= ConsensusFork.Bellatrix: elif consensusFork >= ConsensusFork.Bellatrix:
when not ( when not (
(T is bellatrix_mev.SignedBlindedBeaconBlock and (T is bellatrix_mev.SignedBlindedBeaconBlock and
stateFork == ConsensusFork.Bellatrix) or consensusFork == ConsensusFork.Bellatrix) or
(T is capella_mev.SignedBlindedBeaconBlock and (T is capella_mev.SignedBlindedBeaconBlock and
stateFork == ConsensusFork.Capella)): consensusFork == ConsensusFork.Capella)):
return err("getBlindedBeaconBlock: mismatched block/payload types") return err("getBlindedBeaconBlock: mismatched block/payload types")
else: else:
return await blindedBlockCheckSlashingAndSign( return await blindedBlockCheckSlashingAndSign(
@ -777,12 +777,12 @@ proc makeBlindedBeaconBlockForHeadAndSlot*[
let (executionPayloadHeader, forkedBlck) = blindedBlockParts.get let (executionPayloadHeader, forkedBlck) = blindedBlockParts.get
withBlck(forkedBlck): withBlck(forkedBlck):
when stateFork >= ConsensusFork.Deneb: when consensusFork >= ConsensusFork.Deneb:
debugRaiseAssert $denebImplementationMissing & ": makeBlindedBeaconBlockForHeadAndSlot" debugRaiseAssert $denebImplementationMissing & ": makeBlindedBeaconBlockForHeadAndSlot"
elif stateFork >= ConsensusFork.Bellatrix: elif consensusFork >= ConsensusFork.Bellatrix:
when ((stateFork == ConsensusFork.Bellatrix and when ((consensusFork == ConsensusFork.Bellatrix and
EPH is bellatrix.ExecutionPayloadHeader) or EPH is bellatrix.ExecutionPayloadHeader) or
(stateFork == ConsensusFork.Capella and (consensusFork == ConsensusFork.Capella and
EPH is capella.ExecutionPayloadHeader)): EPH is capella.ExecutionPayloadHeader)):
return ok constructPlainBlindedBlock[BBB, EPH]( return ok constructPlainBlindedBlock[BBB, EPH](
blck, executionPayloadHeader) blck, executionPayloadHeader)

View File

@ -56,7 +56,7 @@ const
func copyParticipationFlags*(auxiliaryState: var AuxiliaryState, func copyParticipationFlags*(auxiliaryState: var AuxiliaryState,
forkedState: ForkedHashedBeaconState) = forkedState: ForkedHashedBeaconState) =
withState(forkedState): withState(forkedState):
when stateFork > ConsensusFork.Phase0: when consensusFork > ConsensusFork.Phase0:
template flags: untyped = auxiliaryState.epochParticipationFlags template flags: untyped = auxiliaryState.epochParticipationFlags
flags.currentEpochParticipation = flags.currentEpochParticipation =
forkyState.data.current_epoch_participation forkyState.data.current_epoch_participation
@ -368,7 +368,7 @@ func collectFromAttestations(
epochParticipationFlags: var ParticipationFlags, epochParticipationFlags: var ParticipationFlags,
cache: var StateCache) = cache: var StateCache) =
withStateAndBlck(forkedState, forkedBlock): withStateAndBlck(forkedState, forkedBlock):
when stateFork > ConsensusFork.Phase0: when consensusFork > ConsensusFork.Phase0:
let base_reward_per_increment = get_base_reward_per_increment( let base_reward_per_increment = get_base_reward_per_increment(
get_total_active_balance(forkyState.data, cache)) get_total_active_balance(forkyState.data, cache))
doAssert base_reward_per_increment > 0 doAssert base_reward_per_increment > 0
@ -419,7 +419,7 @@ func collectFromSyncAggregate(
forkedBlock: ForkedTrustedSignedBeaconBlock, forkedBlock: ForkedTrustedSignedBeaconBlock,
cache: var StateCache) = cache: var StateCache) =
withStateAndBlck(forkedState, forkedBlock): withStateAndBlck(forkedState, forkedBlock):
when stateFork > ConsensusFork.Phase0: when consensusFork > ConsensusFork.Phase0:
let let
total_active_balance = get_total_active_balance(forkyState.data, cache) total_active_balance = get_total_active_balance(forkyState.data, cache)
participant_reward = get_participant_reward(total_active_balance) participant_reward = get_participant_reward(total_active_balance)

View File

@ -320,7 +320,7 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
dbBenchmark.checkpoint() dbBenchmark.checkpoint()
withTimer(timers[tDbLoad]): withTimer(timers[tDbLoad]):
case stateFork case consensusFork
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
doAssert dbBenchmark.getState( doAssert dbBenchmark.getState(
forkyState.root, loadedState[0][].data, noRollback) forkyState.root, loadedState[0][].data, noRollback)
@ -337,7 +337,7 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
raiseAssert $denebImplementationMissing & ": ncli_db.nim: cmdBench (1)" raiseAssert $denebImplementationMissing & ": ncli_db.nim: cmdBench (1)"
if forkyState.data.slot.epoch mod 16 == 0: if forkyState.data.slot.epoch mod 16 == 0:
let loadedRoot = case stateFork let loadedRoot = case consensusFork
of ConsensusFork.Phase0: hash_tree_root(loadedState[0][].data) of ConsensusFork.Phase0: hash_tree_root(loadedState[0][].data)
of ConsensusFork.Altair: hash_tree_root(loadedState[1][].data) of ConsensusFork.Altair: hash_tree_root(loadedState[1][].data)
of ConsensusFork.Bellatrix: hash_tree_root(loadedState[2][].data) of ConsensusFork.Bellatrix: hash_tree_root(loadedState[2][].data)

View File

@ -254,7 +254,7 @@ cli do(validatorsDir: string, secretsDir: string,
aggregates.add(attestation) aggregates.add(attestation)
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
let let
nextSlot = slot + 1 nextSlot = slot + 1
pubkeys = pubkeys =

View File

@ -42,9 +42,9 @@ func readValue*(r: var JsonReader, a: var seq[byte]) =
# ####################### # #######################
# Mock RuntimeConfig # Mock RuntimeConfig
func genesisTestRuntimeConfig*(stateFork: ConsensusFork): RuntimeConfig = func genesisTestRuntimeConfig*(consensusFork: ConsensusFork): RuntimeConfig =
var res = defaultRuntimeConfig var res = defaultRuntimeConfig
case stateFork case consensusFork
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
res.DENEB_FORK_EPOCH = GENESIS_EPOCH res.DENEB_FORK_EPOCH = GENESIS_EPOCH
res.CAPELLA_FORK_EPOCH = GENESIS_EPOCH res.CAPELLA_FORK_EPOCH = GENESIS_EPOCH

View File

@ -69,8 +69,8 @@ suite "EF - Light client - Single merkle proof" & preset():
for kind, path in walkDir(suitePath, relative = true, checkDir = true): for kind, path in walkDir(suitePath, relative = true, checkDir = true):
case objName case objName
of "BeaconBlockBody": of "BeaconBlockBody":
runTest(suitePath/path, BeaconBlockBodyType(stateFork)) runTest(suitePath/path, BeaconBlockBodyType(consensusFork))
of "BeaconState": of "BeaconState":
runTest(suitePath/path, BeaconStateType(stateFork)) runTest(suitePath/path, BeaconStateType(consensusFork))
else: else:
raiseAssert "Unknown test object: " & suitePath/path raiseAssert "Unknown test object: " & suitePath/path

View File

@ -62,7 +62,7 @@ suite "EF - Light client - Update ranking" & preset():
continue continue
for kind, path in walkDir(testsPath, relative = true, checkDir = true): for kind, path in walkDir(testsPath, relative = true, checkDir = true):
withStateFork(fork): withStateFork(fork):
const lcDataFork = lcDataForkAtStateFork(stateFork) const lcDataFork = lcDataForkAtStateFork(consensusFork)
when lcDataFork > LightClientDataFork.None: when lcDataFork > LightClientDataFork.None:
runTest(testsPath/path, lcDataFork) runTest(testsPath/path, lcDataFork)
else: raiseAssert "Unreachable" else: raiseAssert "Unreachable"

View File

@ -99,12 +99,12 @@ func withDigest(blck: deneb.TrustedBeaconBlock):
root: hash_tree_root(blck) root: hash_tree_root(blck)
) )
proc getTestStates(stateFork: ConsensusFork): auto = proc getTestStates(consensusFork: ConsensusFork): auto =
let let
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {}) dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {})
var testStates = getTestStates(dag.headState, stateFork) var testStates = getTestStates(dag.headState, consensusFork)
# Ensure transitions beyond just adding validators and increasing slots # Ensure transitions beyond just adding validators and increasing slots
sort(testStates) do (x, y: ref ForkedHashedBeaconState) -> int: sort(testStates) do (x, y: ref ForkedHashedBeaconState) -> int:

View File

@ -144,7 +144,7 @@ proc addTestBlock*(
default(bellatrix.ExecutionPayloadForSigning) default(bellatrix.ExecutionPayloadForSigning)
else: else:
withState(state): withState(state):
when stateFork == ConsensusFork.Bellatrix: when consensusFork == ConsensusFork.Bellatrix:
# Merge shortly after Bellatrix # Merge shortly after Bellatrix
if forkyState.data.slot > if forkyState.data.slot >
cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH + 10: cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH + 10:
@ -363,7 +363,7 @@ proc makeSyncAggregate(
let let
syncCommittee = syncCommittee =
withState(state): withState(state):
when stateFork >= ConsensusFork.Altair: when consensusFork >= ConsensusFork.Altair:
if (forkyState.data.slot + 1).is_sync_committee_period(): if (forkyState.data.slot + 1).is_sync_committee_period():
forkyState.data.next_sync_committee forkyState.data.next_sync_committee
else: else:

View File

@ -42,7 +42,7 @@ proc valid_deposit(state: var ForkyHashedBeaconState) =
state.root = hash_tree_root(state.data) state.root = hash_tree_root(state.data)
proc getTestStates*( proc getTestStates*(
initialState: ForkedHashedBeaconState, stateFork: ConsensusFork): initialState: ForkedHashedBeaconState, consensusFork: ConsensusFork):
seq[ref ForkedHashedBeaconState] = seq[ref ForkedHashedBeaconState] =
# Randomly generated slot numbers, with a jump to around # Randomly generated slot numbers, with a jump to around
# SLOTS_PER_HISTORICAL_ROOT to force wraparound of those # SLOTS_PER_HISTORICAL_ROOT to force wraparound of those
@ -66,13 +66,13 @@ proc getTestStates*(
cfg = defaultRuntimeConfig cfg = defaultRuntimeConfig
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
if stateFork >= ConsensusFork.Altair: if consensusFork >= ConsensusFork.Altair:
cfg.ALTAIR_FORK_EPOCH = 1.Epoch cfg.ALTAIR_FORK_EPOCH = 1.Epoch
if stateFork >= ConsensusFork.Bellatrix: if consensusFork >= ConsensusFork.Bellatrix:
cfg.BELLATRIX_FORK_EPOCH = 2.Epoch cfg.BELLATRIX_FORK_EPOCH = 2.Epoch
if stateFork >= ConsensusFork.Capella: if consensusFork >= ConsensusFork.Capella:
cfg.CAPELLA_FORK_EPOCH = 3.Epoch cfg.CAPELLA_FORK_EPOCH = 3.Epoch
if stateFork >= ConsensusFork.Deneb: if consensusFork >= ConsensusFork.Deneb:
cfg.DENEB_FORK_EPOCH = 4.Epoch cfg.DENEB_FORK_EPOCH = 4.Epoch
for i, epoch in stateEpochs: for i, epoch in stateEpochs:
@ -86,5 +86,5 @@ proc getTestStates*(
valid_deposit(forkyState) valid_deposit(forkyState)
doAssert getStateField(tmpState[], slot) == slot doAssert getStateField(tmpState[], slot) == slot
if tmpState[].kind == stateFork: if tmpState[].kind == consensusFork:
result.add assignClone(tmpState[]) result.add assignClone(tmpState[])