Fix: Avoid downloading genesis multiple times, for holesky testnet. (#6452)

This commit is contained in:
Eugene Kabanov 2024-07-26 17:54:03 +03:00 committed by GitHub
parent 09f3882672
commit b345c4fa72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 14 deletions

View File

@ -567,7 +567,9 @@ proc init*(T: type BeaconNode,
config: BeaconNodeConf, config: BeaconNodeConf,
metadata: Eth2NetworkMetadata): Future[BeaconNode] metadata: Eth2NetworkMetadata): Future[BeaconNode]
{.async.} = {.async.} =
var taskpool: TaskPoolPtr var
taskpool: TaskPoolPtr
genesisState: ref ForkedHashedBeaconState = nil
template cfg: auto = metadata.cfg template cfg: auto = metadata.cfg
template eth1Network: auto = metadata.eth1Network template eth1Network: auto = metadata.eth1Network
@ -575,10 +577,10 @@ proc init*(T: type BeaconNode,
if not(isDir(config.databaseDir)): if not(isDir(config.databaseDir)):
# If database directory missing, we going to use genesis state to check # If database directory missing, we going to use genesis state to check
# for weak_subjectivity_period. # for weak_subjectivity_period.
genesisState =
await fetchGenesisState(
metadata, config.genesisState, config.genesisStateUrl)
let let
genesisState =
await fetchGenesisState(
metadata, config.genesisState, config.genesisStateUrl)
genesisTime = getStateField(genesisState[], genesis_time) genesisTime = getStateField(genesisState[], genesis_time)
beaconClock = BeaconClock.init(genesisTime).valueOr: beaconClock = BeaconClock.init(genesisTime).valueOr:
fatal "Invalid genesis time in genesis state", genesisTime fatal "Invalid genesis time in genesis state", genesisTime
@ -633,15 +635,15 @@ proc init*(T: type BeaconNode,
db = BeaconChainDB.new(config.databaseDir, cfg, inMemory = false) db = BeaconChainDB.new(config.databaseDir, cfg, inMemory = false)
if config.externalBeaconApiUrl.isSome and ChainDAGRef.isInitialized(db).isErr: if config.externalBeaconApiUrl.isSome and ChainDAGRef.isInitialized(db).isErr:
var genesisState: ref ForkedHashedBeaconState
let trustedBlockRoot = let trustedBlockRoot =
if config.trustedStateRoot.isSome or config.trustedBlockRoot.isSome: if config.trustedStateRoot.isSome or config.trustedBlockRoot.isSome:
config.trustedBlockRoot config.trustedBlockRoot
elif cfg.ALTAIR_FORK_EPOCH == GENESIS_EPOCH: elif cfg.ALTAIR_FORK_EPOCH == GENESIS_EPOCH:
# Sync can be bootstrapped from the genesis block root # Sync can be bootstrapped from the genesis block root
genesisState = await fetchGenesisState( if genesisState.isNil:
metadata, config.genesisState, config.genesisStateUrl) genesisState = await fetchGenesisState(
if genesisState != nil: metadata, config.genesisState, config.genesisStateUrl)
if not genesisState.isNil:
let genesisBlockRoot = get_initial_beacon_block(genesisState[]).root let genesisBlockRoot = get_initial_beacon_block(genesisState[]).root
notice "Neither `--trusted-block-root` nor `--trusted-state-root` " & notice "Neither `--trusted-block-root` nor `--trusted-state-root` " &
"provided with `--external-beacon-api-url`, " & "provided with `--external-beacon-api-url`, " &
@ -662,7 +664,7 @@ proc init*(T: type BeaconNode,
trustedBlockRoot = config.trustedBlockRoot, trustedBlockRoot = config.trustedBlockRoot,
trustedStateRoot = config.trustedStateRoot trustedStateRoot = config.trustedStateRoot
else: else:
if genesisState == nil: if genesisState.isNil:
genesisState = await fetchGenesisState( genesisState = await fetchGenesisState(
metadata, config.genesisState, config.genesisStateUrl) metadata, config.genesisState, config.genesisStateUrl)
await db.doRunTrustedNodeSync( await db.doRunTrustedNodeSync(
@ -728,15 +730,18 @@ proc init*(T: type BeaconNode,
var networkGenesisValidatorsRoot = metadata.bakedGenesisValidatorsRoot var networkGenesisValidatorsRoot = metadata.bakedGenesisValidatorsRoot
if not ChainDAGRef.isInitialized(db).isOk(): if not ChainDAGRef.isInitialized(db).isOk():
let genesisState = genesisState =
if checkpointState != nil and if not checkpointState.isNil and
getStateField(checkpointState[], slot) == 0: getStateField(checkpointState[], slot) == 0:
checkpointState checkpointState
else: else:
await fetchGenesisState( if genesisState.isNil:
metadata, config.genesisState, config.genesisStateUrl) await fetchGenesisState(
metadata, config.genesisState, config.genesisStateUrl)
else:
genesisState
if genesisState == nil and checkpointState == nil: if genesisState.isNil and checkpointState.isNil:
fatal "No database and no genesis snapshot found. Please supply a genesis.ssz " & fatal "No database and no genesis snapshot found. Please supply a genesis.ssz " &
"with the network configuration" "with the network configuration"
quit 1 quit 1