Add CLI options `--genesis-state` and `--genesis-state-url`
This commit is contained in:
parent
53589b5a7d
commit
c7db7d0f2c
|
@ -344,6 +344,14 @@ type
|
|||
desc: "SSZ file specifying a recent finalized state"
|
||||
name: "finalized-checkpoint-state" .}: Option[InputFile]
|
||||
|
||||
genesisState* {.
|
||||
desc: "SSZ file specifying the genesis state of the network (for networks without a built-in genesis state)"
|
||||
name: "genesis-state" .}: Option[InputFile]
|
||||
|
||||
genesisStateUrl* {.
|
||||
desc: "URL for obtaining the genesis state of the network (for networks without a built-in genesis state)"
|
||||
name: "genesis-state-url" .}: Option[Uri]
|
||||
|
||||
finalizedDepositTreeSnapshot* {.
|
||||
desc: "SSZ file specifying a recent finalized EIP-4881 deposit tree snapshot"
|
||||
name: "finalized-deposit-tree-snapshot" .}: Option[InputFile]
|
||||
|
|
|
@ -320,7 +320,7 @@ elif const_preset == "mainnet":
|
|||
vendorDir & "/holesky/custom_config_data",
|
||||
some holesky,
|
||||
downloadGenesisFrom = some DownloadInfo(
|
||||
url: "https://github.com/status-im/nimbus-eth2/releases/download/v23.8.0/holesky-genesis.ssz.snappy-framed",
|
||||
url: "https://github.com/status-im/nimbus-eth2/releases/download/v23.9.0/holesky-genesis.ssz.sz",
|
||||
digest: Eth2Digest.fromHex "0x76631cd0b9ddc5b2c766b496e23f16759ce1181446a4efb40e5540cd15b78a07"))
|
||||
|
||||
sepoliaMetadata = loadCompileTimeNetworkMetadata(
|
||||
|
|
|
@ -29,14 +29,15 @@ proc downloadFile(url: Uri): Future[seq[byte]] {.async.} =
|
|||
msg: "Unexpected status code " & $response[0] & " when fetching " & $url,
|
||||
status: response[0])
|
||||
|
||||
proc fetchBytes*(metadata: GenesisMetadata): Future[seq[byte]] {.async.} =
|
||||
proc fetchBytes*(metadata: GenesisMetadata,
|
||||
genesisStateUrlOverride = none(Uri)): Future[seq[byte]] {.async.} =
|
||||
case metadata.kind
|
||||
of NoGenesis:
|
||||
raiseAssert "fetchBytes should be called only when metadata.hasGenesis is true"
|
||||
of BakedIn:
|
||||
result = @(metadata.bakedBytes)
|
||||
of BakedInUrl:
|
||||
result = decodeFramed(await downloadFile(parseUri metadata.url))
|
||||
result = decodeFramed(await downloadFile(genesisStateUrlOverride.get(parseUri metadata.url)))
|
||||
if eth2digest(result) != metadata.digest:
|
||||
raise (ref DigestMismatchError)(
|
||||
msg: "The downloaded genesis state cannot be verified (checksum mismatch)")
|
||||
|
|
|
@ -482,6 +482,13 @@ proc init*(T: type BeaconNode,
|
|||
except Exception as exc:
|
||||
raise newException(Defect, "Failure in taskpool initialization.")
|
||||
|
||||
if metadata.genesis.kind == BakedIn:
|
||||
if config.genesisState.isSome:
|
||||
warn "The --genesis-state option has no effect on networks with built-in genesis state"
|
||||
|
||||
if config.genesisStateUrl.isSome:
|
||||
warn "The --genesis-state-url option has no effect on networks with built-in genesis state"
|
||||
|
||||
let
|
||||
eventBus = EventBus(
|
||||
blocksQueue: newAsyncEventQueue[EventBeaconBlockObject](),
|
||||
|
@ -544,17 +551,29 @@ proc init*(T: type BeaconNode,
|
|||
var networkGenesisValidatorsRoot = metadata.bakedGenesisValidatorsRoot
|
||||
|
||||
if not ChainDAGRef.isInitialized(db).isOk():
|
||||
let genesisState =
|
||||
if metadata.hasGenesis:
|
||||
let genesisBytes = try:
|
||||
if metadata.genesis.kind == BakedInUrl:
|
||||
info "Obtaining genesis state", sourceUrl = metadata.genesis.url
|
||||
await metadata.genesis.fetchBytes()
|
||||
except CatchableError as err:
|
||||
error "Failed to obtain genesis state",
|
||||
source = metadata.genesis.sourceDesc,
|
||||
err = err.msg
|
||||
quit 1
|
||||
let genesisState = if checkpointState != nil and getStateField(checkpointState[], slot) == 0:
|
||||
checkpointState
|
||||
else:
|
||||
let genesisBytes = block:
|
||||
if metadata.genesis.kind != BakedIn and config.genesisState.isSome:
|
||||
let res = io2.readAllBytes(config.genesisState.get.string)
|
||||
res.valueOr:
|
||||
error "Failed to read genesis state file", err = res.error.ioErrorMsg
|
||||
quit 1
|
||||
elif metadata.hasGenesis:
|
||||
try:
|
||||
if metadata.genesis.kind == BakedInUrl:
|
||||
info "Obtaining genesis state", sourceUrl = metadata.genesis.url
|
||||
await metadata.genesis.fetchBytes(config.genesisStateUrl)
|
||||
except CatchableError as err:
|
||||
error "Failed to obtain genesis state",
|
||||
source = metadata.genesis.sourceDesc,
|
||||
err = err.msg
|
||||
quit 1
|
||||
else:
|
||||
@[]
|
||||
|
||||
if genesisBytes.len > 0:
|
||||
try:
|
||||
newClone readSszForkedHashedBeaconState(cfg, genesisBytes)
|
||||
except CatchableError as err:
|
||||
|
|
Loading…
Reference in New Issue