The --stateSnapshot option now accepts ssz files as well

This commit is contained in:
Zahary Karadjov 2019-09-09 14:10:19 -04:00
parent e470bbb52e
commit f583135a39
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 21 additions and 8 deletions

View File

@ -114,14 +114,27 @@ proc initGenesis(node: BeaconNode) {.async.} =
tailState = await node.mainchainMonitor.getGenesis()
else:
var snapshotFile = conf.dataDir / genesisFile
if conf.stateSnapshot.isSome:
snapshotFile = conf.stateSnapshot.get.string
info "Importing snapshot file", path = snapshotFile
if not fileExists(snapshotFile):
error "Nimbus database not initialized. Please specify the initial state snapshot file."
quit 1
try:
tailState = Json.loadFile(snapshotFile, BeaconState)
if conf.stateSnapshot.isSome:
snapshotFile = conf.stateSnapshot.get.string
if not fileExists(snapshotFile):
error "Nimbus database not initialized. Please specify the initial state snapshot file."
quit 1
template loadSnapshot(Format) =
info "Importing snapshot file", path = snapshotFile
tailState = loadFile(Format, snapshotFile, BeaconState)
let ext = splitFile(snapshotFile).ext
if cmpIgnoreCase(ext, ".ssz") == 0:
loadSnapshot SSZ
elif cmpIgnoreCase(ext, ".json") == 0:
loadSnapshot Json
else:
error "The --stateSnapshot option expects a json or a ssz file."
quit 1
except SerializationError as err:
stderr.write "Failed to import ", snapshotFile, "\n"
stderr.write err.formatMsg(snapshotFile), "\n"

View File

@ -79,7 +79,7 @@ type
stateSnapshot* {.
desc: "Json file specifying a recent state snapshot"
shortform: "s".}: Option[TypedInputFile[BeaconState, Json, "json"]]
shortform: "s".}: Option[InputFile]
nodename* {.
desc: "A name for this node that will appear in the logs. " &