mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-18 10:31:04 +00:00
extend addTestBlock
with Capella/Deneb support (#4728)
* extend `addTestBlock` with Capella/Deneb support * bump copyright years * fix
This commit is contained in:
parent
fd8e86972d
commit
f0dcbaacff
@ -278,6 +278,16 @@ template BeaconBlockType*(fork: static ConsensusFork): auto =
|
||||
template BeaconBlockBodyType*(fork: static ConsensusFork): auto =
|
||||
getSymbolFromForkModule(fork, "BeaconBlockBody")
|
||||
|
||||
template ExecutionPayloadForSigning*(kind: static ConsensusFork): auto =
|
||||
when kind == ConsensusFork.Deneb:
|
||||
typedesc[deneb.ExecutionPayloadForSigning]
|
||||
elif kind == ConsensusFork.Capella:
|
||||
typedesc[capella.ExecutionPayloadForSigning]
|
||||
elif kind == ConsensusFork.Bellatrix:
|
||||
typedesc[bellatrix.ExecutionPayloadForSigning]
|
||||
else:
|
||||
static: raiseAssert "Unreachable"
|
||||
|
||||
template withConsensusFork*(
|
||||
x: ConsensusFork, body: untyped): untyped =
|
||||
case x
|
||||
|
@ -26,8 +26,8 @@ suite "Light client" & preset():
|
||||
var res = defaultRuntimeConfig
|
||||
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
||||
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
||||
# $capellaImplementationMissing res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
||||
# $denebImplementationMissing res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
||||
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
||||
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
||||
res
|
||||
altairStartSlot = cfg.ALTAIR_FORK_EPOCH.start_slot
|
||||
|
||||
@ -88,7 +88,7 @@ suite "Light client" & preset():
|
||||
let
|
||||
validatorMonitor = newClone(ValidatorMonitor.init())
|
||||
dag = ChainDAGRef.init(
|
||||
cfg, makeTestDB(num_validators), validatorMonitor, {},
|
||||
cfg, makeTestDB(num_validators, cfg = cfg), validatorMonitor, {},
|
||||
lcDataConfig = LightClientDataConfig(
|
||||
serve: true,
|
||||
importMode: LightClientDataImportMode.OnlyNew))
|
||||
@ -237,7 +237,7 @@ suite "Light client" & preset():
|
||||
dag.advanceToSlot(finalizedSlot, verifier, quarantine[])
|
||||
|
||||
# Initialize new DAG from checkpoint
|
||||
let cpDb = BeaconChainDB.new("", inMemory = true)
|
||||
let cpDb = BeaconChainDB.new("", cfg = cfg, inMemory = true)
|
||||
ChainDAGRef.preInit(cpDb, genesisState[])
|
||||
ChainDAGRef.preInit(cpDb, dag.headState) # dag.getForkedBlock(dag.head.bid).get)
|
||||
let cpDag = ChainDAGRef.init(
|
||||
|
@ -29,15 +29,15 @@ suite "Light client processor" & preset():
|
||||
var res = defaultRuntimeConfig
|
||||
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
||||
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
||||
# $capellaImplementationMissing res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
||||
# $denebImplementationMissing res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
||||
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
||||
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
||||
res
|
||||
|
||||
const numValidators = SLOTS_PER_EPOCH
|
||||
let
|
||||
validatorMonitor = newClone(ValidatorMonitor.init())
|
||||
dag = ChainDAGRef.init(
|
||||
cfg, makeTestDB(numValidators), validatorMonitor, {},
|
||||
cfg, makeTestDB(numValidators, cfg = cfg), validatorMonitor, {},
|
||||
lcDataConfig = LightClientDataConfig(
|
||||
serve: true,
|
||||
importMode: LightClientDataImportMode.OnlyNew))
|
||||
|
@ -137,14 +137,16 @@ proc addTestBlock*(
|
||||
else:
|
||||
ValidatorSig()
|
||||
|
||||
let message = withState(state):
|
||||
let execution_payload =
|
||||
when consensusFork > ConsensusFork.Bellatrix:
|
||||
default(consensusFork.ExecutionPayloadForSigning)
|
||||
elif consensusFork == ConsensusFork.Bellatrix:
|
||||
if cfg.CAPELLA_FORK_EPOCH != FAR_FUTURE_EPOCH:
|
||||
# Can't keep correctly doing this once Capella happens, but LVH search
|
||||
# test relies on merging. So, merge only if no Capella transition.
|
||||
default(bellatrix.ExecutionPayloadForSigning)
|
||||
else:
|
||||
withState(state):
|
||||
when consensusFork == ConsensusFork.Bellatrix:
|
||||
# Merge shortly after Bellatrix
|
||||
if forkyState.data.slot >
|
||||
cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH + 10:
|
||||
@ -158,8 +160,7 @@ proc addTestBlock*(
|
||||
else:
|
||||
default(bellatrix.ExecutionPayloadForSigning)
|
||||
|
||||
let
|
||||
message = makeBeaconBlock(
|
||||
makeBeaconBlock(
|
||||
cfg,
|
||||
state,
|
||||
proposer_index,
|
||||
@ -167,7 +168,7 @@ proc addTestBlock*(
|
||||
# Keep deposit counts internally consistent.
|
||||
Eth1Data(
|
||||
deposit_root: eth1_data.deposit_root,
|
||||
deposit_count: getStateField(state, eth1_deposit_index) + deposits.lenu64,
|
||||
deposit_count: forkyState.data.eth1_deposit_index + deposits.lenu64,
|
||||
block_hash: eth1_data.block_hash),
|
||||
graffiti,
|
||||
attestations,
|
||||
|
@ -1,5 +1,5 @@
|
||||
# beacon_chain
|
||||
# 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).
|
||||
@ -16,18 +16,19 @@ import
|
||||
|
||||
export beacon_chain_db, testblockutil, kvstore, kvstore_sqlite3
|
||||
|
||||
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
||||
proc makeTestDB*(
|
||||
validators: Natural, cfg = defaultRuntimeConfig): BeaconChainDB =
|
||||
let
|
||||
genState = (ref ForkedHashedBeaconState)(
|
||||
kind: ConsensusFork.Phase0,
|
||||
phase0Data: initialize_hashed_beacon_state_from_eth1(
|
||||
defaultRuntimeConfig,
|
||||
cfg,
|
||||
ZERO_HASH,
|
||||
0,
|
||||
makeInitialDeposits(validators.uint64, flags = {skipBlsValidation}),
|
||||
{skipBlsValidation}))
|
||||
|
||||
result = BeaconChainDB.new("", inMemory = true)
|
||||
result = BeaconChainDB.new("", cfg = cfg, inMemory = true)
|
||||
ChainDAGRef.preInit(result, genState[])
|
||||
|
||||
proc getEarliestInvalidBlockRoot*(
|
||||
|
Loading…
x
Reference in New Issue
Block a user