mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-11 06:46:10 +00:00
rename stateForkAtEpoch to consensusForkAtEpoch (#4627)
This commit is contained in:
parent
4597486dcc
commit
e342fdd97a
@ -650,7 +650,7 @@ proc getState(
|
||||
let state_root = db.getStateRoot(block_root, slot).valueOr:
|
||||
return false
|
||||
|
||||
db.getState(cfg.stateForkAtEpoch(slot.epoch), state_root, state, rollback)
|
||||
db.getState(cfg.consensusForkAtEpoch(slot.epoch), state_root, state, rollback)
|
||||
|
||||
proc containsState*(
|
||||
db: BeaconChainDB, cfg: RuntimeConfig, block_root: Eth2Digest,
|
||||
@ -659,7 +659,8 @@ proc containsState*(
|
||||
while slot >= slots.a:
|
||||
let state_root = db.getStateRoot(block_root, slot)
|
||||
if state_root.isSome() and
|
||||
db.containsState(cfg.stateForkAtEpoch(slot.epoch), state_root.get()):
|
||||
db.containsState(
|
||||
cfg.consensusForkAtEpoch(slot.epoch), state_root.get()):
|
||||
return true
|
||||
|
||||
if slot == slots.a: # avoid underflow at genesis
|
||||
@ -676,7 +677,8 @@ proc getState*(
|
||||
let state_root = db.getStateRoot(block_root, slot)
|
||||
if state_root.isSome() and
|
||||
db.getState(
|
||||
cfg.stateForkAtEpoch(slot.epoch), state_root.get(), state, rollback):
|
||||
cfg.consensusForkAtEpoch(slot.epoch), state_root.get(), state,
|
||||
rollback):
|
||||
return true
|
||||
|
||||
if slot == slots.a: # avoid underflow at genesis
|
||||
@ -831,7 +833,8 @@ proc putState(dag: ChainDAGRef, state: ForkedHashedBeaconState, bid: BlockId) =
|
||||
# Don't consider legacy tables here, they are slow to read so we'll want to
|
||||
# rewrite things in the new table anyway.
|
||||
if dag.db.containsState(
|
||||
dag.cfg.stateForkAtEpoch(slot.epoch), getStateRoot(state), legacy = false):
|
||||
dag.cfg.consensusForkAtEpoch(slot.epoch), getStateRoot(state),
|
||||
legacy = false):
|
||||
return
|
||||
|
||||
let startTick = Moment.now()
|
||||
@ -1612,7 +1615,8 @@ proc delState(dag: ChainDAGRef, bsi: BlockSlotId) =
|
||||
if (let root = dag.db.getStateRoot(bsi.bid.root, bsi.slot); root.isSome()):
|
||||
dag.db.withManyWrites:
|
||||
dag.db.delStateRoot(bsi.bid.root, bsi.slot)
|
||||
dag.db.delState(dag.cfg.stateForkAtEpoch(bsi.slot.epoch), root.get())
|
||||
dag.db.delState(
|
||||
dag.cfg.consensusForkAtEpoch(bsi.slot.epoch), root.get())
|
||||
|
||||
proc pruneBlockSlot(dag: ChainDAGRef, bs: BlockSlot) =
|
||||
# TODO: should we move that disk I/O to `onSlotEnd`
|
||||
@ -1944,7 +1948,7 @@ 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.stateForkAtEpoch(tailSlot.epoch)
|
||||
let stateFork = dag.cfg.consensusForkAtEpoch(tailSlot.epoch)
|
||||
if stateFork > ConsensusFork.Phase0:
|
||||
for fork in ConsensusFork.Phase0..<stateFork:
|
||||
dag.db.clearStates(fork)
|
||||
@ -2383,7 +2387,7 @@ proc rebuildIndex*(dag: ChainDAGRef) =
|
||||
junk.add((k, v))
|
||||
continue
|
||||
|
||||
if not dag.db.containsState(dag.cfg.stateForkAtEpoch(k[0].epoch), v):
|
||||
if not dag.db.containsState(dag.cfg.consensusForkAtEpoch(k[0].epoch), v):
|
||||
continue # If it's not in the database..
|
||||
|
||||
canonical[k[0].epoch div EPOCHS_PER_STATE_SNAPSHOT] = v
|
||||
@ -2423,7 +2427,8 @@ proc rebuildIndex*(dag: ChainDAGRef) =
|
||||
|
||||
else:
|
||||
if not dag.db.getState(
|
||||
dag.cfg.stateForkAtEpoch(slot.epoch), state_root, state[], noRollback):
|
||||
dag.cfg.consensusForkAtEpoch(slot.epoch), state_root, state[],
|
||||
noRollback):
|
||||
fatal "Cannot load state, database corrupt or created for a different network?",
|
||||
state_root, slot
|
||||
quit 1
|
||||
@ -2446,7 +2451,9 @@ proc rebuildIndex*(dag: ChainDAGRef) =
|
||||
slot, startStateRoot = canonical[i - 1], startSlot
|
||||
|
||||
if getStateRoot(state[]) != canonical[i - 1]:
|
||||
if not dag.db.getState(dag.cfg.stateForkAtEpoch(startSlot.epoch), canonical[i - 1], state[], noRollback):
|
||||
if not dag.db.getState(
|
||||
dag.cfg.consensusForkAtEpoch(startSlot.epoch), canonical[i - 1],
|
||||
state[], noRollback):
|
||||
error "Can't load start state, database corrupt?",
|
||||
startStateRoot = shortLog(canonical[i - 1]), slot = startSlot
|
||||
return
|
||||
@ -2491,4 +2498,4 @@ proc rebuildIndex*(dag: ChainDAGRef) =
|
||||
|
||||
for i in junk:
|
||||
dag.db.delStateRoot(i[0][1], i[0][0])
|
||||
dag.db.delState(dag.cfg.stateForkAtEpoch(i[0][0].epoch), i[1])
|
||||
dag.db.delState(dag.cfg.consensusForkAtEpoch(i[0][0].epoch), i[1])
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2023 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
@ -391,7 +391,7 @@ iterator getBlockIds*(
|
||||
while true:
|
||||
# `case` ensures we're on a fork for which the `PartialBeaconState`
|
||||
# definition is consistent
|
||||
case db.cfg.stateForkAtEpoch(slot.epoch)
|
||||
case db.cfg.consensusForkAtEpoch(slot.epoch)
|
||||
of ConsensusFork.Phase0 .. ConsensusFork.EIP4844:
|
||||
let stateSlot = (slot.era() + 1).start_slot()
|
||||
if not getPartialState(db, historical_roots, stateSlot, state[]):
|
||||
|
@ -287,7 +287,7 @@ proc installMessageValidators*(
|
||||
validatorProcName: untyped): ValidationResult =
|
||||
msg.logReceived()
|
||||
|
||||
if contextFork != lightClient.cfg.stateForkAtEpoch(msg.contextEpoch):
|
||||
if contextFork != lightClient.cfg.consensusForkAtEpoch(msg.contextEpoch):
|
||||
msg.logDropped(
|
||||
(ValidationResult.Reject, cstring "Invalid context fork"))
|
||||
return ValidationResult.Reject
|
||||
|
@ -151,7 +151,7 @@ proc loadChainDag(
|
||||
withForkyFinalityUpdate(data):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
let contextFork =
|
||||
dag.cfg.stateForkAtEpoch(forkyFinalityUpdate.contextEpoch)
|
||||
dag.cfg.consensusForkAtEpoch(forkyFinalityUpdate.contextEpoch)
|
||||
eventBus.finUpdateQueue.emit(
|
||||
RestVersioned[ForkedLightClientFinalityUpdate](
|
||||
data: data,
|
||||
@ -162,7 +162,7 @@ proc loadChainDag(
|
||||
withForkyOptimisticUpdate(data):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
let contextFork =
|
||||
dag.cfg.stateForkAtEpoch(forkyOptimisticUpdate.contextEpoch)
|
||||
dag.cfg.consensusForkAtEpoch(forkyOptimisticUpdate.contextEpoch)
|
||||
eventBus.optUpdateQueue.emit(
|
||||
RestVersioned[ForkedLightClientOptimisticUpdate](
|
||||
data: data,
|
||||
@ -889,7 +889,7 @@ func getSyncCommitteeSubnets(node: BeaconNode, epoch: Epoch): SyncnetBits =
|
||||
# but more than SYNC_COMMITTEE_SUBNET_COUNT epochs from when the next sync
|
||||
# committee period begins, in which case `epochsToNextSyncPeriod` is none.
|
||||
if epochsToSyncPeriod.isNone or
|
||||
node.dag.cfg.stateForkAtEpoch(epoch + epochsToSyncPeriod.get) <
|
||||
node.dag.cfg.consensusForkAtEpoch(epoch + epochsToSyncPeriod.get) <
|
||||
ConsensusFork.Altair:
|
||||
return subnets
|
||||
|
||||
|
@ -840,7 +840,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
|
||||
let
|
||||
currentEpochFork =
|
||||
node.dag.cfg.stateForkAtEpoch(node.currentSlot().epoch())
|
||||
node.dag.cfg.consensusForkAtEpoch(node.currentSlot().epoch())
|
||||
version = request.headers.getString("eth-consensus-version")
|
||||
body = contentBody.get()
|
||||
|
||||
|
@ -38,7 +38,7 @@ proc installLightClientApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
let
|
||||
contextEpoch = forkyBootstrap.contextEpoch
|
||||
contextFork = node.dag.cfg.stateForkAtEpoch(contextEpoch)
|
||||
contextFork = node.dag.cfg.consensusForkAtEpoch(contextEpoch)
|
||||
return
|
||||
if contentType == sszMediaType:
|
||||
let headers = [("eth-consensus-version", contextFork.toString())]
|
||||
@ -101,7 +101,7 @@ proc installLightClientApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
forkyUpdate.contextEpoch
|
||||
else:
|
||||
continue
|
||||
contextFork = node.dag.cfg.stateForkAtEpoch(contextEpoch)
|
||||
contextFork = node.dag.cfg.consensusForkAtEpoch(contextEpoch)
|
||||
updates.add RestVersioned[ForkedLightClientUpdate](
|
||||
data: update,
|
||||
jsonVersion: contextFork,
|
||||
@ -133,7 +133,7 @@ proc installLightClientApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
let
|
||||
contextEpoch = forkyFinalityUpdate.contextEpoch
|
||||
contextFork = node.dag.cfg.stateForkAtEpoch(contextEpoch)
|
||||
contextFork = node.dag.cfg.consensusForkAtEpoch(contextEpoch)
|
||||
return
|
||||
if contentType == sszMediaType:
|
||||
let headers = [("eth-consensus-version", contextFork.toString())]
|
||||
@ -164,7 +164,7 @@ proc installLightClientApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
let
|
||||
contextEpoch = forkyOptimisticUpdate.contextEpoch
|
||||
contextFork = node.dag.cfg.stateForkAtEpoch(contextEpoch)
|
||||
contextFork = node.dag.cfg.consensusForkAtEpoch(contextEpoch)
|
||||
return
|
||||
if contentType == sszMediaType:
|
||||
let headers = [("eth-consensus-version", contextFork.toString())]
|
||||
|
@ -638,7 +638,7 @@ func getStateRoot*(x: ForkedHashedBeaconState): Eth2Digest =
|
||||
func setStateRoot*(x: var ForkedHashedBeaconState, root: Eth2Digest) =
|
||||
withState(x): forkyState.root = root
|
||||
|
||||
func stateForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
|
||||
func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
|
||||
## Return the current fork for the given epoch.
|
||||
static:
|
||||
doAssert high(ConsensusFork) == ConsensusFork.EIP4844
|
||||
@ -695,7 +695,7 @@ func atStateFork*(
|
||||
|
||||
template atEpoch*(
|
||||
forkDigests: ForkDigests, epoch: Epoch, cfg: RuntimeConfig): ForkDigest =
|
||||
forkDigests.atStateFork(cfg.stateForkAtEpoch(epoch))
|
||||
forkDigests.atStateFork(cfg.consensusForkAtEpoch(epoch))
|
||||
|
||||
template asSigned*(
|
||||
x: ForkedMsgTrustedSignedBeaconBlock |
|
||||
@ -898,7 +898,7 @@ func denebFork*(cfg: RuntimeConfig): Fork =
|
||||
epoch: cfg.DENEB_FORK_EPOCH)
|
||||
|
||||
func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
|
||||
case cfg.stateForkAtEpoch(epoch)
|
||||
case cfg.consensusForkAtEpoch(epoch)
|
||||
of ConsensusFork.EIP4844: cfg.denebFork
|
||||
of ConsensusFork.Capella: cfg.capellaFork
|
||||
of ConsensusFork.Bellatrix: cfg.bellatrixFork
|
||||
@ -906,7 +906,7 @@ func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
|
||||
of ConsensusFork.Phase0: cfg.genesisFork
|
||||
|
||||
func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
|
||||
case cfg.stateForkAtEpoch(epoch)
|
||||
case cfg.consensusForkAtEpoch(epoch)
|
||||
of ConsensusFork.EIP4844: cfg.DENEB_FORK_VERSION
|
||||
of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION
|
||||
of ConsensusFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
|
||||
@ -914,7 +914,8 @@ func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
|
||||
of ConsensusFork.Phase0: cfg.GENESIS_FORK_VERSION
|
||||
|
||||
func nextForkEpochAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Epoch =
|
||||
case cfg.stateForkAtEpoch(epoch)
|
||||
static: doAssert high(ConsensusFork) == ConsensusFork.EIP4844
|
||||
case cfg.consensusForkAtEpoch(epoch)
|
||||
of ConsensusFork.EIP4844: FAR_FUTURE_EPOCH
|
||||
of ConsensusFork.Capella: cfg.DENEB_FORK_EPOCH
|
||||
of ConsensusFork.Bellatrix: cfg.CAPELLA_FORK_EPOCH
|
||||
@ -961,7 +962,7 @@ func readSszForkedHashedBeaconState*(
|
||||
ForkedHashedBeaconState {.raises: [Defect, SszError].} =
|
||||
# TODO https://github.com/nim-lang/Nim/issues/19357
|
||||
result = ForkedHashedBeaconState(
|
||||
kind: cfg.stateForkAtEpoch(slot.epoch()))
|
||||
kind: cfg.consensusForkAtEpoch(slot.epoch()))
|
||||
|
||||
withState(result):
|
||||
readSszBytes(data, forkyState.data)
|
||||
|
@ -173,7 +173,7 @@ proc readChunkPayload*(
|
||||
conn, peer, MsgType.Forky(lcDataFork))
|
||||
if res.isOk:
|
||||
if contextFork !=
|
||||
peer.network.cfg.stateForkAtEpoch(res.get.contextEpoch):
|
||||
peer.network.cfg.consensusForkAtEpoch(res.get.contextEpoch):
|
||||
return neterr InvalidContextBytes
|
||||
var obj = ok MsgType(kind: lcDataFork)
|
||||
obj.get.forky(lcDataFork) = res.get
|
||||
|
@ -83,7 +83,7 @@ proc doTrustedNodeSync*(
|
||||
genesisRoot = genesisRoot.get()
|
||||
quit 1
|
||||
genesisStateRoot = getForkedBlockField(genesisBlock, state_root)
|
||||
stateFork = cfg.stateForkAtEpoch(GENESIS_EPOCH)
|
||||
stateFork = cfg.consensusForkAtEpoch(GENESIS_EPOCH)
|
||||
|
||||
tmp = (ref ForkedHashedBeaconState)(kind: stateFork)
|
||||
if not db.getState(stateFork, genesisStateRoot, tmp[], noRollback):
|
||||
|
@ -700,7 +700,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
||||
|
||||
if blockRatio > 0.0:
|
||||
withTimer(timers[t]):
|
||||
case dag.cfg.stateForkAtEpoch(slot.epoch)
|
||||
case dag.cfg.consensusForkAtEpoch(slot.epoch)
|
||||
of ConsensusFork.EIP4844: proposeEIP4844Block(slot)
|
||||
of ConsensusFork.Capella: proposeCapellaBlock(slot)
|
||||
of ConsensusFork.Bellatrix: proposeBellatrixBlock(slot)
|
||||
|
Loading…
x
Reference in New Issue
Block a user