Skip to content

Commit ad118cd

Browse files
authored
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
1 parent 969c6f7 commit ad118cd

28 files changed

+121
-121
lines changed

beacon_chain/beacon_node_light_client.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ proc initLightClient*(
4545
dag = node.dag.head.bid,
4646
wallSlot = node.currentSlot
4747
withBlck(signedBlock):
48-
when stateFork >= ConsensusFork.Bellatrix:
48+
when consensusFork >= ConsensusFork.Bellatrix:
4949
if blck.message.is_execution_block:
5050
template payload(): auto = blck.message.body.execution_payload
5151

@@ -151,7 +151,7 @@ proc updateLightClientFromDag*(node: BeaconNode) =
151151
return
152152
var header {.noinit.}: ForkedLightClientHeader
153153
withBlck(bdata):
154-
const lcDataFork = lcDataForkAtStateFork(stateFork)
154+
const lcDataFork = lcDataForkAtStateFork(consensusFork)
155155
when lcDataFork > LightClientDataFork.None:
156156
header = ForkedLightClientHeader(kind: lcDataFork)
157157
header.forky(lcDataFork) = blck.toLightClientHeader(lcDataFork)

beacon_chain/consensus_object_pools/attestation_pool.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ proc init*(T: type AttestationPool, dag: ChainDAGRef,
143143
var unrealized: FinalityCheckpoints
144144
if enableTestFeatures in dag.updateFlags and blckRef == dag.head:
145145
unrealized = withState(dag.headState):
146-
when stateFork >= ConsensusFork.Altair:
146+
when consensusFork >= ConsensusFork.Altair:
147147
forkyState.data.compute_unrealized_finality()
148148
else:
149149
var cache: StateCache

beacon_chain/consensus_object_pools/block_clearance.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ proc addResolvedHeadBlock(
105105
if enableTestFeatures in dag.updateFlags:
106106
unrealized = withState(state):
107107
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
108-
when stateFork >= ConsensusFork.Altair:
108+
when consensusFork >= ConsensusFork.Altair:
109109
forkyState.data.compute_unrealized_finality()
110110
else:
111111
forkyState.data.compute_unrealized_finality(cache)

beacon_chain/consensus_object_pools/blockchain_dag.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func validatorKey*(
145145
template is_merge_transition_complete*(
146146
stateParam: ForkedHashedBeaconState): bool =
147147
withState(stateParam):
148-
when stateFork >= ConsensusFork.Bellatrix:
148+
when consensusFork >= ConsensusFork.Bellatrix:
149149
is_merge_transition_complete(forkyState.data)
150150
else:
151151
false
@@ -757,7 +757,7 @@ proc currentSyncCommitteeForPeriod*(
757757
bsi = ? dag.getBlockIdAtSlot(syncCommitteeSlot)
758758
dag.withUpdatedState(tmpState, bsi) do:
759759
withState(updatedState):
760-
when stateFork >= ConsensusFork.Altair:
760+
when consensusFork >= ConsensusFork.Altair:
761761
ok forkyState.data.current_sync_committee
762762
else: err()
763763
do: err()
@@ -1037,7 +1037,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
10371037
quit 1
10381038

10391039
withState(dag.headState):
1040-
when stateFork >= ConsensusFork.Altair:
1040+
when consensusFork >= ConsensusFork.Altair:
10411041
dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache)
10421042

10431043
block:
@@ -1218,7 +1218,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
12181218

12191219
# If these aren't actually optimistic, the first fcU will resolve that
12201220
withState(dag.headState):
1221-
when stateFork >= ConsensusFork.Bellatrix:
1221+
when consensusFork >= ConsensusFork.Bellatrix:
12221222
template executionPayloadHeader(): auto =
12231223
forkyState().data.latest_execution_payload_header
12241224
const emptyExecutionPayloadHeader =
@@ -1735,7 +1735,7 @@ iterator syncSubcommitteePairs*(
17351735
func syncCommitteeParticipants*(dag: ChainDAGRef,
17361736
slot: Slot): seq[ValidatorIndex] =
17371737
withState(dag.headState):
1738-
when stateFork >= ConsensusFork.Altair:
1738+
when consensusFork >= ConsensusFork.Altair:
17391739
let
17401740
period = sync_committee_period(slot)
17411741
curPeriod = sync_committee_period(forkyState.data.slot)
@@ -1765,7 +1765,7 @@ func getSubcommitteePositions*(
17651765
subcommitteeIdx: SyncSubcommitteeIndex,
17661766
validatorIdx: uint64): seq[uint64] =
17671767
withState(dag.headState):
1768-
when stateFork >= ConsensusFork.Altair:
1768+
when consensusFork >= ConsensusFork.Altair:
17691769
let
17701770
period = sync_committee_period(slot)
17711771
curPeriod = sync_committee_period(forkyState.data.slot)
@@ -1954,9 +1954,9 @@ proc pruneHistory*(dag: ChainDAGRef, startup = false) =
19541954
# so as to "mostly" clean up the phase0 tables as well (which cannot be
19551955
# pruned easily by fork)
19561956

1957-
let stateFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch)
1958-
if stateFork > ConsensusFork.Phase0:
1959-
for fork in ConsensusFork.Phase0..<stateFork:
1957+
let consensusFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch)
1958+
if consensusFork > ConsensusFork.Phase0:
1959+
for fork in ConsensusFork.Phase0..<consensusFork:
19601960
dag.db.clearStates(fork)
19611961

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

19751975
withBlck(blockData):
1976-
when stateFork >= ConsensusFork.Bellatrix:
1976+
when consensusFork >= ConsensusFork.Bellatrix:
19771977
blck.message.body.execution_payload.block_hash
19781978
else:
19791979
ZERO_HASH
@@ -2099,7 +2099,7 @@ proc updateHead*(
20992099
updateBeaconMetrics(dag.headState, dag.head.bid, cache)
21002100

21012101
withState(dag.headState):
2102-
when stateFork >= ConsensusFork.Altair:
2102+
when consensusFork >= ConsensusFork.Altair:
21032103
dag.headSyncCommittees = forkyState.data.get_sync_committee_cache(cache)
21042104

21052105
let

beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ proc syncCommitteeRootForPeriod(
119119
bsi = ? dag.getExistingBlockIdAtSlot(syncCommitteeSlot)
120120
dag.withUpdatedExistingState(tmpState, bsi) do:
121121
withState(updatedState):
122-
when stateFork >= ConsensusFork.Altair:
122+
when consensusFork >= ConsensusFork.Altair:
123123
ok forkyState.syncCommitteeRoot
124124
else: raiseAssert "Unreachable"
125125
do: err()
@@ -213,8 +213,8 @@ proc initLightClientBootstrapForPeriod(
213213
res.err()
214214
continue
215215
withStateAndBlck(tmpState[], bdata):
216-
when stateFork >= ConsensusFork.Altair:
217-
const lcDataFork = lcDataForkAtStateFork(stateFork)
216+
when consensusFork >= ConsensusFork.Altair:
217+
const lcDataFork = lcDataForkAtStateFork(consensusFork)
218218
if not dag.lcDataStore.db.hasSyncCommittee(period):
219219
dag.lcDataStore.db.putSyncCommittee(
220220
period, forkyState.data.current_sync_committee)
@@ -274,7 +274,7 @@ proc initLightClientUpdateForPeriod(
274274
break
275275
numParticipants =
276276
withBlck(bdata):
277-
when stateFork >= ConsensusFork.Altair:
277+
when consensusFork >= ConsensusFork.Altair:
278278
blck.message.body.sync_aggregate.num_active_participants
279279
else: raiseAssert "Unreachable"
280280
if numParticipants >= maxParticipants:
@@ -332,7 +332,7 @@ proc initLightClientUpdateForPeriod(
332332
finalizedEpoch = block:
333333
dag.withUpdatedExistingState(tmpState[], attestedBid.atSlot) do:
334334
withState(updatedState):
335-
when stateFork >= ConsensusFork.Altair:
335+
when consensusFork >= ConsensusFork.Altair:
336336
forkyState.data.finalized_checkpoint.epoch
337337
else: raiseAssert "Unreachable"
338338
do:
@@ -364,8 +364,8 @@ proc initLightClientUpdateForPeriod(
364364
dag.handleUnexpectedLightClientError(bid.slot)
365365
return err()
366366
withStateAndBlck(updatedState, bdata):
367-
when stateFork >= ConsensusFork.Altair:
368-
const lcDataFork = lcDataForkAtStateFork(stateFork)
367+
when consensusFork >= ConsensusFork.Altair:
368+
const lcDataFork = lcDataForkAtStateFork(consensusFork)
369369
update = ForkedLightClientUpdate(kind: lcDataFork)
370370
template forkyUpdate: untyped = update.forky(lcDataFork)
371371
forkyUpdate.attested_header = blck.toLightClientHeader(lcDataFork)
@@ -386,14 +386,14 @@ proc initLightClientUpdateForPeriod(
386386
withBlck(bdata):
387387
withForkyUpdate(update):
388388
when lcDataFork > LightClientDataFork.None:
389-
when lcDataFork >= lcDataForkAtStateFork(stateFork):
389+
when lcDataFork >= lcDataForkAtStateFork(consensusFork):
390390
forkyUpdate.finalized_header = blck.toLightClientHeader(lcDataFork)
391391
else: raiseAssert "Unreachable"
392392
let bdata = dag.getExistingForkedBlock(signatureBid).valueOr:
393393
dag.handleUnexpectedLightClientError(signatureBid.slot)
394394
return err()
395395
withBlck(bdata):
396-
when stateFork >= ConsensusFork.Altair:
396+
when consensusFork >= ConsensusFork.Altair:
397397
withForkyUpdate(update):
398398
when lcDataFork > LightClientDataFork.None:
399399
forkyUpdate.sync_aggregate =
@@ -477,7 +477,7 @@ template lazy_header(name: untyped): untyped {.dirty.} =
477477
`name _ ok` = false
478478
else:
479479
withBlck(bdata.get):
480-
when data_fork >= lcDataForkAtStateFork(stateFork):
480+
when data_fork >= lcDataForkAtStateFork(consensusFork):
481481
obj.name = blck.toLightClientHeader(data_fork)
482482
else: raiseAssert "Unreachable"
483483
`name _ ptr` = addr obj.name
@@ -495,7 +495,7 @@ template lazy_header(name: untyped): untyped {.dirty.} =
495495
else:
496496
obj.migrateToDataFork(data_fork)
497497
withBlck(bdata.get):
498-
when data_fork >= lcDataForkAtStateFork(stateFork):
498+
when data_fork >= lcDataForkAtStateFork(consensusFork):
499499
obj.forky(data_fork).name = blck.toLightClientHeader(data_fork)
500500
else: raiseAssert "Unreachable"
501501
`name _ ptr` = addr obj.forky(data_fork).name
@@ -686,7 +686,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
686686
if dag.head.slot < dag.lcDataStore.cache.tailSlot:
687687
return
688688
withState(dag.headState):
689-
when stateFork >= ConsensusFork.Altair:
689+
when consensusFork >= ConsensusFork.Altair:
690690
dag.cacheLightClientData(forkyState, dag.head.bid)
691691
else: raiseAssert "Unreachable" # `tailSlot` cannot be before Altair
692692
if dag.lcDataStore.importMode == LightClientDataImportMode.OnlyNew:
@@ -737,7 +737,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
737737
res.err()
738738
continue
739739
withStateAndBlck(dag.headState, bdata):
740-
when stateFork >= ConsensusFork.Altair:
740+
when consensusFork >= ConsensusFork.Altair:
741741
# Cache light client data (non-finalized blocks may refer to this)
742742
if i != blocks.low:
743743
dag.cacheLightClientData(forkyState, bid) # `dag.head` already cached
@@ -826,7 +826,7 @@ proc processHeadChangeForLightClient*(dag: ChainDAGRef) =
826826
dag.lcDataStore.db.putBestUpdate(
827827
period, dag.lcDataStore.cache.pendingBest.getOrDefault(key))
828828
withState(dag.headState): # Common case separate to avoid `tmpState` copy
829-
when stateFork >= ConsensusFork.Altair:
829+
when consensusFork >= ConsensusFork.Altair:
830830
let key = (headPeriod, forkyState.syncCommitteeRoot)
831831
dag.lcDataStore.db.putBestUpdate(
832832
headPeriod, dag.lcDataStore.cache.pendingBest.getOrDefault(key))
@@ -862,7 +862,7 @@ proc processFinalizationForLightClient*(
862862
period = bid.slot.sync_committee_period
863863
if not dag.lcDataStore.db.hasSyncCommittee(period):
864864
let didPutSyncCommittee = withState(dag.headState):
865-
when stateFork >= ConsensusFork.Altair:
865+
when consensusFork >= ConsensusFork.Altair:
866866
if period == forkyState.data.slot.sync_committee_period:
867867
dag.lcDataStore.db.putSyncCommittee(
868868
period, forkyState.data.current_sync_committee)
@@ -880,8 +880,8 @@ proc processFinalizationForLightClient*(
880880
break
881881
dag.lcDataStore.db.putSyncCommittee(period, syncCommittee)
882882
withBlck(bdata):
883-
when stateFork >= ConsensusFork.Altair:
884-
const lcDataFork = lcDataForkAtStateFork(stateFork)
883+
when consensusFork >= ConsensusFork.Altair:
884+
const lcDataFork = lcDataForkAtStateFork(consensusFork)
885885
dag.lcDataStore.db.putHeader(blck.toLightClientHeader(lcDataFork))
886886
else: raiseAssert "Unreachable"
887887
dag.lcDataStore.db.putCurrentSyncCommitteeBranch(
@@ -949,7 +949,7 @@ proc getLightClientBootstrap(
949949
tmpState = assignClone(dag.headState)
950950
dag.withUpdatedExistingState(tmpState[], bsi) do:
951951
withState(updatedState):
952-
when stateFork >= ConsensusFork.Altair:
952+
when consensusFork >= ConsensusFork.Altair:
953953
if not dag.lcDataStore.db.hasSyncCommittee(period):
954954
dag.lcDataStore.db.putSyncCommittee(
955955
period, forkyState.data.current_sync_committee)
@@ -1003,8 +1003,8 @@ proc getLightClientBootstrap*(
10031003
debug "LC bootstrap unavailable: Block not found", blockRoot
10041004
return default(ForkedLightClientBootstrap)
10051005
withBlck(bdata):
1006-
when stateFork >= ConsensusFork.Altair:
1007-
const lcDataFork = lcDataForkAtStateFork(stateFork)
1006+
when consensusFork >= ConsensusFork.Altair:
1007+
const lcDataFork = lcDataForkAtStateFork(consensusFork)
10081008
let
10091009
header = blck.toLightClientHeader(lcDataFork)
10101010
bootstrap = dag.getLightClientBootstrap(header)

beacon_chain/consensus_object_pools/consensus_manager.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ proc runProposalForkchoiceUpdated*(
330330
feeRecipient = self[].getFeeRecipient(
331331
nextProposer, Opt.some(validatorIndex), nextWallSlot.epoch)
332332
withdrawals = withState(self.dag.headState):
333-
when stateFork >= ConsensusFork.Capella:
333+
when consensusFork >= ConsensusFork.Capella:
334334
Opt.some get_expected_withdrawals(forkyState.data)
335335
else:
336336
Opt.none(seq[Withdrawal])
@@ -352,7 +352,7 @@ proc runProposalForkchoiceUpdated*(
352352
debug "Fork-choice updated for proposal", status
353353

354354
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
355-
when stateFork >= ConsensusFork.Capella:
355+
when consensusFork >= ConsensusFork.Capella:
356356
callForkchoiceUpdated(PayloadAttributesV2(
357357
timestamp: Quantity timestamp,
358358
prevRandao: FixedBytes[32] randomData,

beacon_chain/gossip_processing/block_processor.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ proc storeBlock*(
420420
trustedBlock.message.slot)
421421

422422
withState(dag[].clearanceState):
423-
when stateFork >= ConsensusFork.Altair and
423+
when consensusFork >= ConsensusFork.Altair and
424424
Trusted isnot phase0.TrustedSignedBeaconBlock: # altair+
425425
for i in trustedBlock.message.body.sync_aggregate.sync_committee_bits.oneIndices():
426426
vm[].registerSyncAggregateInBlock(

beacon_chain/gossip_processing/gossip_validation.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ proc validateBlsToExecutionChange*(
765765
# [REJECT] All of the conditions within `process_bls_to_execution_change`
766766
# pass validation.
767767
withState(pool.dag.headState):
768-
when stateFork < ConsensusFork.Capella:
768+
when consensusFork < ConsensusFork.Capella:
769769
return errIgnore("validateBlsToExecutionChange: can't validate against pre-Capella state")
770770
else:
771771
let res = check_bls_to_execution_change(

beacon_chain/light_client.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ proc installMessageValidators*(
343343
ValidationResult.Ignore
344344

345345
let forkDigests = lightClient.forkDigests
346-
for stateFork in ConsensusFork:
347-
withLcDataFork(lcDataForkAtStateFork(stateFork)):
346+
for consensusFork in ConsensusFork:
347+
withLcDataFork(lcDataForkAtStateFork(consensusFork)):
348348
when lcDataFork > LightClientDataFork.None:
349349
let
350-
contextFork = stateFork # Copy to avoid capturing `Deneb` (Nim 1.6)
350+
contextFork = consensusFork # Avoid capturing `Deneb` (Nim 1.6)
351351
digest = forkDigests[].atStateFork(contextFork)
352352

353353
lightClient.network.addValidator(

beacon_chain/nimbus_beacon_node.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func hasSyncPubKey(node: BeaconNode, epoch: Epoch): auto =
862862

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

872872
func getNextSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
873873
let syncCommittee = withState(node.dag.headState):
874-
when stateFork >= ConsensusFork.Altair:
874+
when consensusFork >= ConsensusFork.Altair:
875875
forkyState.data.next_sync_committee
876876
else:
877877
return static(default(SyncnetBits))

beacon_chain/nimbus_light_client.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ programMain:
105105
opt = signedBlock.toBlockId(),
106106
wallSlot = getBeaconTime().slotOrZero
107107
withBlck(signedBlock):
108-
when stateFork >= ConsensusFork.Bellatrix:
108+
when consensusFork >= ConsensusFork.Bellatrix:
109109
if blck.message.is_execution_block:
110110
template payload(): auto = blck.message.body.execution_payload
111111

beacon_chain/rpc/rest_utils.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func syncCommitteeParticipants*(forkedState: ForkedHashedBeaconState,
233233
epoch: Epoch
234234
): Result[seq[ValidatorPubKey], cstring] =
235235
withState(forkedState):
236-
when stateFork >= ConsensusFork.Altair:
236+
when consensusFork >= ConsensusFork.Altair:
237237
let
238238
epochPeriod = sync_committee_period(epoch)
239239
curPeriod = sync_committee_period(forkyState.data.slot)

beacon_chain/rpc/rest_validator_api.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
247247
if qSyncPeriod == headSyncPeriod:
248248
let optimistic = node.getStateOptimistic(node.dag.headState)
249249
let res = withState(node.dag.headState):
250-
when stateFork >= ConsensusFork.Altair:
250+
when consensusFork >= ConsensusFork.Altair:
251251
produceResponse(indexList,
252252
forkyState.data.current_sync_committee.pubkeys.data,
253253
forkyState.data.validators.asSeq)
@@ -257,7 +257,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
257257
elif qSyncPeriod == (headSyncPeriod + 1):
258258
let optimistic = node.getStateOptimistic(node.dag.headState)
259259
let res = withState(node.dag.headState):
260-
when stateFork >= ConsensusFork.Altair:
260+
when consensusFork >= ConsensusFork.Altair:
261261
produceResponse(indexList,
262262
forkyState.data.next_sync_committee.pubkeys.data,
263263
forkyState.data.validators.asSeq)
@@ -288,7 +288,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
288288
node.withStateForBlockSlotId(bsi):
289289
let optimistic = node.getStateOptimistic(state)
290290
let res = withState(state):
291-
when stateFork >= ConsensusFork.Altair:
291+
when consensusFork >= ConsensusFork.Altair:
292292
produceResponse(indexList,
293293
forkyState.data.current_sync_committee.pubkeys.data,
294294
forkyState.data.validators.asSeq)

0 commit comments

Comments
 (0)