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 =
|
template BeaconBlockBodyType*(fork: static ConsensusFork): auto =
|
||||||
getSymbolFromForkModule(fork, "BeaconBlockBody")
|
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*(
|
template withConsensusFork*(
|
||||||
x: ConsensusFork, body: untyped): untyped =
|
x: ConsensusFork, body: untyped): untyped =
|
||||||
case x
|
case x
|
||||||
|
|
|
@ -26,8 +26,8 @@ suite "Light client" & preset():
|
||||||
var res = defaultRuntimeConfig
|
var res = defaultRuntimeConfig
|
||||||
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
||||||
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
||||||
# $capellaImplementationMissing res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
||||||
# $denebImplementationMissing res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
||||||
res
|
res
|
||||||
altairStartSlot = cfg.ALTAIR_FORK_EPOCH.start_slot
|
altairStartSlot = cfg.ALTAIR_FORK_EPOCH.start_slot
|
||||||
|
|
||||||
|
@ -55,13 +55,13 @@ suite "Light client" & preset():
|
||||||
if targetSlot > checkpointSlot and checkpointSlot > dag.head.slot:
|
if targetSlot > checkpointSlot and checkpointSlot > dag.head.slot:
|
||||||
var info: ForkedEpochInfo
|
var info: ForkedEpochInfo
|
||||||
doAssert process_slots(cfg, dag.headState, checkpointSlot,
|
doAssert process_slots(cfg, dag.headState, checkpointSlot,
|
||||||
cache, info, flags = {}).isOk()
|
cache, info, flags = {}).isOk()
|
||||||
slot = checkpointSlot
|
slot = checkpointSlot
|
||||||
|
|
||||||
# Create blocks for final few epochs
|
# Create blocks for final few epochs
|
||||||
let blocks = min(targetSlot - slot, maxAttestedSlotsPerPeriod)
|
let blocks = min(targetSlot - slot, maxAttestedSlotsPerPeriod)
|
||||||
for blck in makeTestBlocks(dag.headState, cache, blocks.int,
|
for blck in makeTestBlocks(dag.headState, cache, blocks.int,
|
||||||
attested, syncCommitteeRatio, cfg):
|
attested, syncCommitteeRatio, cfg):
|
||||||
let added =
|
let added =
|
||||||
case blck.kind
|
case blck.kind
|
||||||
of ConsensusFork.Phase0:
|
of ConsensusFork.Phase0:
|
||||||
|
@ -88,7 +88,7 @@ suite "Light client" & preset():
|
||||||
let
|
let
|
||||||
validatorMonitor = newClone(ValidatorMonitor.init())
|
validatorMonitor = newClone(ValidatorMonitor.init())
|
||||||
dag = ChainDAGRef.init(
|
dag = ChainDAGRef.init(
|
||||||
cfg, makeTestDB(num_validators), validatorMonitor, {},
|
cfg, makeTestDB(num_validators, cfg = cfg), validatorMonitor, {},
|
||||||
lcDataConfig = LightClientDataConfig(
|
lcDataConfig = LightClientDataConfig(
|
||||||
serve: true,
|
serve: true,
|
||||||
importMode: LightClientDataImportMode.OnlyNew))
|
importMode: LightClientDataImportMode.OnlyNew))
|
||||||
|
@ -237,7 +237,7 @@ suite "Light client" & preset():
|
||||||
dag.advanceToSlot(finalizedSlot, verifier, quarantine[])
|
dag.advanceToSlot(finalizedSlot, verifier, quarantine[])
|
||||||
|
|
||||||
# Initialize new DAG from checkpoint
|
# 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, genesisState[])
|
||||||
ChainDAGRef.preInit(cpDb, dag.headState) # dag.getForkedBlock(dag.head.bid).get)
|
ChainDAGRef.preInit(cpDb, dag.headState) # dag.getForkedBlock(dag.head.bid).get)
|
||||||
let cpDag = ChainDAGRef.init(
|
let cpDag = ChainDAGRef.init(
|
||||||
|
|
|
@ -29,15 +29,15 @@ suite "Light client processor" & preset():
|
||||||
var res = defaultRuntimeConfig
|
var res = defaultRuntimeConfig
|
||||||
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
||||||
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
||||||
# $capellaImplementationMissing res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
||||||
# $denebImplementationMissing res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
||||||
res
|
res
|
||||||
|
|
||||||
const numValidators = SLOTS_PER_EPOCH
|
const numValidators = SLOTS_PER_EPOCH
|
||||||
let
|
let
|
||||||
validatorMonitor = newClone(ValidatorMonitor.init())
|
validatorMonitor = newClone(ValidatorMonitor.init())
|
||||||
dag = ChainDAGRef.init(
|
dag = ChainDAGRef.init(
|
||||||
cfg, makeTestDB(numValidators), validatorMonitor, {},
|
cfg, makeTestDB(numValidators, cfg = cfg), validatorMonitor, {},
|
||||||
lcDataConfig = LightClientDataConfig(
|
lcDataConfig = LightClientDataConfig(
|
||||||
serve: true,
|
serve: true,
|
||||||
importMode: LightClientDataImportMode.OnlyNew))
|
importMode: LightClientDataImportMode.OnlyNew))
|
||||||
|
|
|
@ -137,14 +137,16 @@ proc addTestBlock*(
|
||||||
else:
|
else:
|
||||||
ValidatorSig()
|
ValidatorSig()
|
||||||
|
|
||||||
let execution_payload =
|
let message = withState(state):
|
||||||
if cfg.CAPELLA_FORK_EPOCH != FAR_FUTURE_EPOCH:
|
let execution_payload =
|
||||||
# Can't keep correctly doing this once Capella happens, but LVH search
|
when consensusFork > ConsensusFork.Bellatrix:
|
||||||
# test relies on merging. So, merge only if no Capella transition.
|
default(consensusFork.ExecutionPayloadForSigning)
|
||||||
default(bellatrix.ExecutionPayloadForSigning)
|
elif consensusFork == ConsensusFork.Bellatrix:
|
||||||
else:
|
if cfg.CAPELLA_FORK_EPOCH != FAR_FUTURE_EPOCH:
|
||||||
withState(state):
|
# Can't keep correctly doing this once Capella happens, but LVH search
|
||||||
when consensusFork == ConsensusFork.Bellatrix:
|
# test relies on merging. So, merge only if no Capella transition.
|
||||||
|
default(bellatrix.ExecutionPayloadForSigning)
|
||||||
|
else:
|
||||||
# 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:
|
||||||
|
@ -155,11 +157,10 @@ proc addTestBlock*(
|
||||||
build_empty_merge_execution_payload(forkyState.data)
|
build_empty_merge_execution_payload(forkyState.data)
|
||||||
else:
|
else:
|
||||||
default(bellatrix.ExecutionPayloadForSigning)
|
default(bellatrix.ExecutionPayloadForSigning)
|
||||||
else:
|
else:
|
||||||
default(bellatrix.ExecutionPayloadForSigning)
|
default(bellatrix.ExecutionPayloadForSigning)
|
||||||
|
|
||||||
let
|
makeBeaconBlock(
|
||||||
message = makeBeaconBlock(
|
|
||||||
cfg,
|
cfg,
|
||||||
state,
|
state,
|
||||||
proposer_index,
|
proposer_index,
|
||||||
|
@ -167,7 +168,7 @@ proc addTestBlock*(
|
||||||
# Keep deposit counts internally consistent.
|
# Keep deposit counts internally consistent.
|
||||||
Eth1Data(
|
Eth1Data(
|
||||||
deposit_root: eth1_data.deposit_root,
|
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),
|
block_hash: eth1_data.block_hash),
|
||||||
graffiti,
|
graffiti,
|
||||||
attestations,
|
attestations,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
# Copyright (c) 2018-2023 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * 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).
|
# * 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
|
export beacon_chain_db, testblockutil, kvstore, kvstore_sqlite3
|
||||||
|
|
||||||
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
proc makeTestDB*(
|
||||||
|
validators: Natural, cfg = defaultRuntimeConfig): BeaconChainDB =
|
||||||
let
|
let
|
||||||
genState = (ref ForkedHashedBeaconState)(
|
genState = (ref ForkedHashedBeaconState)(
|
||||||
kind: ConsensusFork.Phase0,
|
kind: ConsensusFork.Phase0,
|
||||||
phase0Data: initialize_hashed_beacon_state_from_eth1(
|
phase0Data: initialize_hashed_beacon_state_from_eth1(
|
||||||
defaultRuntimeConfig,
|
cfg,
|
||||||
ZERO_HASH,
|
ZERO_HASH,
|
||||||
0,
|
0,
|
||||||
makeInitialDeposits(validators.uint64, flags = {skipBlsValidation}),
|
makeInitialDeposits(validators.uint64, flags = {skipBlsValidation}),
|
||||||
{skipBlsValidation}))
|
{skipBlsValidation}))
|
||||||
|
|
||||||
result = BeaconChainDB.new("", inMemory = true)
|
result = BeaconChainDB.new("", cfg = cfg, inMemory = true)
|
||||||
ChainDAGRef.preInit(result, genState[])
|
ChainDAGRef.preInit(result, genState[])
|
||||||
|
|
||||||
proc getEarliestInvalidBlockRoot*(
|
proc getEarliestInvalidBlockRoot*(
|
||||||
|
|
Loading…
Reference in New Issue