Skip to content

Commit

Permalink
rename stateFork > consensusFork (#4718)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
etan-status authored Mar 11, 2023
1 parent 969c6f7 commit ad118cd
Show file tree
Hide file tree
Showing 28 changed files with 121 additions and 121 deletions.
4 changes: 2 additions & 2 deletions beacon_chain/beacon_node_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proc initLightClient*(
dag = node.dag.head.bid,
wallSlot = node.currentSlot
withBlck(signedBlock):
when stateFork >= ConsensusFork.Bellatrix:
when consensusFork >= ConsensusFork.Bellatrix:
if blck.message.is_execution_block:
template payload(): auto = blck.message.body.execution_payload

Expand Down Expand Up @@ -151,7 +151,7 @@ proc updateLightClientFromDag*(node: BeaconNode) =
return
var header {.noinit.}: ForkedLightClientHeader
withBlck(bdata):
const lcDataFork = lcDataForkAtStateFork(stateFork)
const lcDataFork = lcDataForkAtStateFork(consensusFork)
when lcDataFork > LightClientDataFork.None:
header = ForkedLightClientHeader(kind: lcDataFork)
header.forky(lcDataFork) = blck.toLightClientHeader(lcDataFork)
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ 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 >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
forkyState.data.compute_unrealized_finality()
else:
var cache: StateCache
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/block_clearance.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ proc addResolvedHeadBlock(
if enableTestFeatures in dag.updateFlags:
unrealized = withState(state):
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
forkyState.data.compute_unrealized_finality()
else:
forkyState.data.compute_unrealized_finality(cache)
Expand Down
22 changes: 11 additions & 11 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func validatorKey*(
template is_merge_transition_complete*(
stateParam: ForkedHashedBeaconState): bool =
withState(stateParam):
when stateFork >= ConsensusFork.Bellatrix:
when consensusFork >= ConsensusFork.Bellatrix:
is_merge_transition_complete(forkyState.data)
else:
false
Expand Down Expand Up @@ -757,7 +757,7 @@ proc currentSyncCommitteeForPeriod*(
bsi = ? dag.getBlockIdAtSlot(syncCommitteeSlot)
dag.withUpdatedState(tmpState, bsi) do:
withState(updatedState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
ok forkyState.data.current_sync_committee
else: err()
do: err()
Expand Down Expand Up @@ -1037,7 +1037,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
quit 1

withState(dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache)

block:
Expand Down Expand Up @@ -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
withState(dag.headState):
when stateFork >= ConsensusFork.Bellatrix:
when consensusFork >= ConsensusFork.Bellatrix:
template executionPayloadHeader(): auto =
forkyState().data.latest_execution_payload_header
const emptyExecutionPayloadHeader =
Expand Down Expand Up @@ -1735,7 +1735,7 @@ iterator syncSubcommitteePairs*(
func syncCommitteeParticipants*(dag: ChainDAGRef,
slot: Slot): seq[ValidatorIndex] =
withState(dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
let
period = sync_committee_period(slot)
curPeriod = sync_committee_period(forkyState.data.slot)
Expand Down Expand Up @@ -1765,7 +1765,7 @@ func getSubcommitteePositions*(
subcommitteeIdx: SyncSubcommitteeIndex,
validatorIdx: uint64): seq[uint64] =
withState(dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
let
period = sync_committee_period(slot)
curPeriod = sync_committee_period(forkyState.data.slot)
Expand Down Expand Up @@ -1954,9 +1954,9 @@ proc pruneHistory*(dag: ChainDAGRef, startup = false) =
# so as to "mostly" clean up the phase0 tables as well (which cannot be
# pruned easily by fork)

let stateFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch)
if stateFork > ConsensusFork.Phase0:
for fork in ConsensusFork.Phase0..<stateFork:
let consensusFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch)
if consensusFork > ConsensusFork.Phase0:
for fork in ConsensusFork.Phase0..<consensusFork:
dag.db.clearStates(fork)

let blockFork = dag.cfg.consensusForkAtEpoch(blockHorizon.epoch)
Expand All @@ -1973,7 +1973,7 @@ proc loadExecutionBlockRoot*(dag: ChainDAGRef, bid: BlockId): Eth2Digest =
return ZERO_HASH

withBlck(blockData):
when stateFork >= ConsensusFork.Bellatrix:
when consensusFork >= ConsensusFork.Bellatrix:
blck.message.body.execution_payload.block_hash
else:
ZERO_HASH
Expand Down Expand Up @@ -2099,7 +2099,7 @@ proc updateHead*(
updateBeaconMetrics(dag.headState, dag.head.bid, cache)

withState(dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache)

let
Expand Down
40 changes: 20 additions & 20 deletions beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ proc syncCommitteeRootForPeriod(
bsi = ? dag.getExistingBlockIdAtSlot(syncCommitteeSlot)
dag.withUpdatedExistingState(tmpState, bsi) do:
withState(updatedState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
ok forkyState.syncCommitteeRoot
else: raiseAssert "Unreachable"
do: err()
Expand Down Expand Up @@ -213,8 +213,8 @@ proc initLightClientBootstrapForPeriod(
res.err()
continue
withStateAndBlck(tmpState[], bdata):
when stateFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork)
when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(consensusFork)
if not dag.lcDataStore.db.hasSyncCommittee(period):
dag.lcDataStore.db.putSyncCommittee(
period, forkyState.data.current_sync_committee)
Expand Down Expand Up @@ -274,7 +274,7 @@ proc initLightClientUpdateForPeriod(
break
numParticipants =
withBlck(bdata):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
blck.message.body.sync_aggregate.num_active_participants
else: raiseAssert "Unreachable"
if numParticipants >= maxParticipants:
Expand Down Expand Up @@ -332,7 +332,7 @@ proc initLightClientUpdateForPeriod(
finalizedEpoch = block:
dag.withUpdatedExistingState(tmpState[], attestedBid.atSlot) do:
withState(updatedState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
forkyState.data.finalized_checkpoint.epoch
else: raiseAssert "Unreachable"
do:
Expand Down Expand Up @@ -364,8 +364,8 @@ proc initLightClientUpdateForPeriod(
dag.handleUnexpectedLightClientError(bid.slot)
return err()
withStateAndBlck(updatedState, bdata):
when stateFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork)
when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(consensusFork)
update = ForkedLightClientUpdate(kind: lcDataFork)
template forkyUpdate: untyped = update.forky(lcDataFork)
forkyUpdate.attested_header = blck.toLightClientHeader(lcDataFork)
Expand All @@ -386,14 +386,14 @@ proc initLightClientUpdateForPeriod(
withBlck(bdata):
withForkyUpdate(update):
when lcDataFork > LightClientDataFork.None:
when lcDataFork >= lcDataForkAtStateFork(stateFork):
when lcDataFork >= lcDataForkAtStateFork(consensusFork):
forkyUpdate.finalized_header = blck.toLightClientHeader(lcDataFork)
else: raiseAssert "Unreachable"
let bdata = dag.getExistingForkedBlock(signatureBid).valueOr:
dag.handleUnexpectedLightClientError(signatureBid.slot)
return err()
withBlck(bdata):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
withForkyUpdate(update):
when lcDataFork > LightClientDataFork.None:
forkyUpdate.sync_aggregate =
Expand Down Expand Up @@ -477,7 +477,7 @@ template lazy_header(name: untyped): untyped {.dirty.} =
`name _ ok` = false
else:
withBlck(bdata.get):
when data_fork >= lcDataForkAtStateFork(stateFork):
when data_fork >= lcDataForkAtStateFork(consensusFork):
obj.name = blck.toLightClientHeader(data_fork)
else: raiseAssert "Unreachable"
`name _ ptr` = addr obj.name
Expand All @@ -495,7 +495,7 @@ template lazy_header(name: untyped): untyped {.dirty.} =
else:
obj.migrateToDataFork(data_fork)
withBlck(bdata.get):
when data_fork >= lcDataForkAtStateFork(stateFork):
when data_fork >= lcDataForkAtStateFork(consensusFork):
obj.forky(data_fork).name = blck.toLightClientHeader(data_fork)
else: raiseAssert "Unreachable"
`name _ ptr` = addr obj.forky(data_fork).name
Expand Down Expand Up @@ -686,7 +686,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
if dag.head.slot < dag.lcDataStore.cache.tailSlot:
return
withState(dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
dag.cacheLightClientData(forkyState, dag.head.bid)
else: raiseAssert "Unreachable" # `tailSlot` cannot be before Altair
if dag.lcDataStore.importMode == LightClientDataImportMode.OnlyNew:
Expand Down Expand Up @@ -737,7 +737,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
res.err()
continue
withStateAndBlck(dag.headState, bdata):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
# Cache light client data (non-finalized blocks may refer to this)
if i != blocks.low:
dag.cacheLightClientData(forkyState, bid) # `dag.head` already cached
Expand Down Expand Up @@ -826,7 +826,7 @@ proc processHeadChangeForLightClient*(dag: ChainDAGRef) =
dag.lcDataStore.db.putBestUpdate(
period, dag.lcDataStore.cache.pendingBest.getOrDefault(key))
withState(dag.headState): # Common case separate to avoid `tmpState` copy
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
let key = (headPeriod, forkyState.syncCommitteeRoot)
dag.lcDataStore.db.putBestUpdate(
headPeriod, dag.lcDataStore.cache.pendingBest.getOrDefault(key))
Expand Down Expand Up @@ -862,7 +862,7 @@ proc processFinalizationForLightClient*(
period = bid.slot.sync_committee_period
if not dag.lcDataStore.db.hasSyncCommittee(period):
let didPutSyncCommittee = withState(dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
if period == forkyState.data.slot.sync_committee_period:
dag.lcDataStore.db.putSyncCommittee(
period, forkyState.data.current_sync_committee)
Expand All @@ -880,8 +880,8 @@ proc processFinalizationForLightClient*(
break
dag.lcDataStore.db.putSyncCommittee(period, syncCommittee)
withBlck(bdata):
when stateFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork)
when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(consensusFork)
dag.lcDataStore.db.putHeader(blck.toLightClientHeader(lcDataFork))
else: raiseAssert "Unreachable"
dag.lcDataStore.db.putCurrentSyncCommitteeBranch(
Expand Down Expand Up @@ -949,7 +949,7 @@ proc getLightClientBootstrap(
tmpState = assignClone(dag.headState)
dag.withUpdatedExistingState(tmpState[], bsi) do:
withState(updatedState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
if not dag.lcDataStore.db.hasSyncCommittee(period):
dag.lcDataStore.db.putSyncCommittee(
period, forkyState.data.current_sync_committee)
Expand Down Expand Up @@ -1003,8 +1003,8 @@ proc getLightClientBootstrap*(
debug "LC bootstrap unavailable: Block not found", blockRoot
return default(ForkedLightClientBootstrap)
withBlck(bdata):
when stateFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(stateFork)
when consensusFork >= ConsensusFork.Altair:
const lcDataFork = lcDataForkAtStateFork(consensusFork)
let
header = blck.toLightClientHeader(lcDataFork)
bootstrap = dag.getLightClientBootstrap(header)
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/consensus_object_pools/consensus_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ proc runProposalForkchoiceUpdated*(
feeRecipient = self[].getFeeRecipient(
nextProposer, Opt.some(validatorIndex), nextWallSlot.epoch)
withdrawals = withState(self.dag.headState):
when stateFork >= ConsensusFork.Capella:
when consensusFork >= ConsensusFork.Capella:
Opt.some get_expected_withdrawals(forkyState.data)
else:
Opt.none(seq[Withdrawal])
Expand All @@ -352,7 +352,7 @@ proc runProposalForkchoiceUpdated*(
debug "Fork-choice updated for proposal", status

static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
when stateFork >= ConsensusFork.Capella:
when consensusFork >= ConsensusFork.Capella:
callForkchoiceUpdated(PayloadAttributesV2(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/gossip_processing/block_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ proc storeBlock*(
trustedBlock.message.slot)

withState(dag[].clearanceState):
when stateFork >= ConsensusFork.Altair and
when consensusFork >= ConsensusFork.Altair and
Trusted isnot phase0.TrustedSignedBeaconBlock: # altair+
for i in trustedBlock.message.body.sync_aggregate.sync_committee_bits.oneIndices():
vm[].registerSyncAggregateInBlock(
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/gossip_processing/gossip_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ proc validateBlsToExecutionChange*(
# [REJECT] All of the conditions within `process_bls_to_execution_change`
# pass validation.
withState(pool.dag.headState):
when stateFork < ConsensusFork.Capella:
when consensusFork < ConsensusFork.Capella:
return errIgnore("validateBlsToExecutionChange: can't validate against pre-Capella state")
else:
let res = check_bls_to_execution_change(
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ proc installMessageValidators*(
ValidationResult.Ignore

let forkDigests = lightClient.forkDigests
for stateFork in ConsensusFork:
withLcDataFork(lcDataForkAtStateFork(stateFork)):
for consensusFork in ConsensusFork:
withLcDataFork(lcDataForkAtStateFork(consensusFork)):
when lcDataFork > LightClientDataFork.None:
let
contextFork = stateFork # Copy to avoid capturing `Deneb` (Nim 1.6)
contextFork = consensusFork # Avoid capturing `Deneb` (Nim 1.6)
digest = forkDigests[].atStateFork(contextFork)

lightClient.network.addValidator(
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func hasSyncPubKey(node: BeaconNode, epoch: Epoch): auto =

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

func getNextSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
let syncCommittee = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
forkyState.data.next_sync_committee
else:
return static(default(SyncnetBits))
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/nimbus_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ programMain:
opt = signedBlock.toBlockId(),
wallSlot = getBeaconTime().slotOrZero
withBlck(signedBlock):
when stateFork >= ConsensusFork.Bellatrix:
when consensusFork >= ConsensusFork.Bellatrix:
if blck.message.is_execution_block:
template payload(): auto = blck.message.body.execution_payload

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/rpc/rest_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func syncCommitteeParticipants*(forkedState: ForkedHashedBeaconState,
epoch: Epoch
): Result[seq[ValidatorPubKey], cstring] =
withState(forkedState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
let
epochPeriod = sync_committee_period(epoch)
curPeriod = sync_committee_period(forkyState.data.slot)
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/rpc/rest_validator_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
if qSyncPeriod == headSyncPeriod:
let optimistic = node.getStateOptimistic(node.dag.headState)
let res = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
produceResponse(indexList,
forkyState.data.current_sync_committee.pubkeys.data,
forkyState.data.validators.asSeq)
Expand All @@ -257,7 +257,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
elif qSyncPeriod == (headSyncPeriod + 1):
let optimistic = node.getStateOptimistic(node.dag.headState)
let res = withState(node.dag.headState):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
produceResponse(indexList,
forkyState.data.next_sync_committee.pubkeys.data,
forkyState.data.validators.asSeq)
Expand Down Expand Up @@ -288,7 +288,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
node.withStateForBlockSlotId(bsi):
let optimistic = node.getStateOptimistic(state)
let res = withState(state):
when stateFork >= ConsensusFork.Altair:
when consensusFork >= ConsensusFork.Altair:
produceResponse(indexList,
forkyState.data.current_sync_committee.pubkeys.data,
forkyState.data.validators.asSeq)
Expand Down
Loading

0 comments on commit ad118cd

Please sign in to comment.