From 98761afc645ba8c76e734426ca3e15a15dfe5950 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Thu, 2 Jul 2020 18:52:48 +0300 Subject: [PATCH] Run beacon_node --network=altona without initial Eth1 syncing --- beacon_chain/beacon_node.nim | 9 +++++++++ beacon_chain/conf.nim | 5 ++++- vendor/nim-confutils | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index cbcec4d63..339afcc8a 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -98,6 +98,8 @@ proc getStateFromSnapshot(conf: BeaconNodeConf): NilableBeaconStateRef = except CatchableError as err: error "Failed to read genesis file", err = err.msg quit 1 + elif conf.stateSnapshotContents != nil: + swap(snapshotContents, TaintedString conf.stateSnapshotContents[]) else: # No snapshot was provided. We should wait for genesis. return nil @@ -193,6 +195,10 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async error "Failed to initialize database", err = e.msg quit 1 + if conf.stateSnapshotContents != nil: + # The memory for the initial snapshot won't be needed anymore + conf.stateSnapshotContents[] = "" + # TODO check that genesis given on command line (if any) matches database let blockPool = BlockPool.init( db, @@ -1135,6 +1141,9 @@ programMain: for node in metadata.bootstrapNodes: config.bootstrapNodes.add node + if config.stateSnapshot.isNone: + config.stateSnapshotContents = newClone metadata.genesisData + template checkForIncompatibleOption(flagName, fieldName) = # TODO: This will have to be reworked slightly when we introduce config files. # We'll need to keep track of the "origin" of the config value, so we can diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index ccae46f86..0677a4b82 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -127,10 +127,13 @@ type name: "wallets-dir" }: Option[InputDir] stateSnapshot* {. - desc: "Json file specifying a recent state snapshot" + desc: "SSZ file specifying a recent state snapshot" abbr: "s" name: "state-snapshot" }: Option[InputFile] + stateSnapshotContents* {.hidden.}: ref string + # This is ref so we can mutate it (to erase it) after the initial loading. + nodeName* {. defaultValue: "" desc: "A name for this node that will appear in the logs. " & diff --git a/vendor/nim-confutils b/vendor/nim-confutils index f9415621f..39456fa3d 160000 --- a/vendor/nim-confutils +++ b/vendor/nim-confutils @@ -1 +1 @@ -Subproject commit f9415621f87287524d26aa99a94e2613b237cc3c +Subproject commit 39456fa3d5b637053b616e50a8350b2b932a1d4c