Make web3 way of getting genesis optional
This commit is contained in:
parent
68c4cbf078
commit
24cbc0710f
|
@ -79,6 +79,38 @@ proc saveValidatorKey(keyName, key: string, conf: BeaconNodeConf) =
|
|||
writeFile(outputFile, key)
|
||||
info "Imported validator key", file = outputFile
|
||||
|
||||
proc initGenesis(node: BeaconNode) {.async.} =
|
||||
template conf: untyped = node.config
|
||||
var tailState: BeaconState
|
||||
if conf.depositWeb3Url.len != 0:
|
||||
info "Waiting for genesis state from eth1"
|
||||
tailState = await getGenesisFromEth1(conf)
|
||||
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)
|
||||
except SerializationError as err:
|
||||
stderr.write "Failed to import ", snapshotFile, "\n"
|
||||
stderr.write err.formatMsg(snapshotFile), "\n"
|
||||
quit 1
|
||||
|
||||
info "Got genesis state", hash = hash_tree_root(tailState)
|
||||
|
||||
try:
|
||||
let tailBlock = get_initial_beacon_block(tailState)
|
||||
BlockPool.preInit(node.db, tailState, tailBlock)
|
||||
|
||||
except:
|
||||
stderr.write "Failed to initialize database\n"
|
||||
stderr.write getCurrentExceptionMsg(), "\n"
|
||||
quit 1
|
||||
|
||||
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
|
||||
new result
|
||||
result.onBeaconBlock = onBeaconBlock
|
||||
|
@ -138,35 +170,8 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
|
|||
# specified on command line? potentially, this should be the other way
|
||||
# around...
|
||||
|
||||
let headBlock = result.db.getHeadBlock()
|
||||
if headBlock.isNone():
|
||||
var snapshotFile = conf.dataDir / genesisFile
|
||||
if conf.stateSnapshot.isSome:
|
||||
snapshotFile = conf.stateSnapshot.get.string
|
||||
elif not fileExists(snapshotFile):
|
||||
error "Nimbus database not initialized. Please specify the initial state snapshot file."
|
||||
quit 1
|
||||
|
||||
try:
|
||||
info "Importing snapshot file", path = snapshotFile
|
||||
info "Waiting for genesis state from eth1"
|
||||
|
||||
let
|
||||
tailState = await getGenesisFromEth1(conf)
|
||||
# tailState = Json.loadFile(snapshotFile, BeaconState)
|
||||
tailBlock = get_initial_beacon_block(tailState)
|
||||
|
||||
info "Got genesis state", hash = hash_tree_root(tailState)
|
||||
BlockPool.preInit(result.db, tailState, tailBlock)
|
||||
|
||||
except SerializationError as err:
|
||||
stderr.write "Failed to import ", snapshotFile, "\n"
|
||||
stderr.write err.formatMsg(snapshotFile), "\n"
|
||||
quit 1
|
||||
except:
|
||||
stderr.write "Failed to initialize database\n"
|
||||
stderr.write getCurrentExceptionMsg(), "\n"
|
||||
quit 1
|
||||
if result.db.getHeadBlock().isNone():
|
||||
await result.initGenesis()
|
||||
|
||||
result.blockPool = BlockPool.init(result.db)
|
||||
result.attestationPool = AttestationPool.init(result.blockPool)
|
||||
|
|
|
@ -33,5 +33,5 @@ $BEACON_NODE_BIN \
|
|||
--udpPort:$PORT \
|
||||
$NAT_FLAG \
|
||||
--stateSnapshot:$SNAPSHOT_FILE \
|
||||
--depositWeb3Url=$DEPOSIT_WEB3_URL \
|
||||
$DEPOSIT_WEB3_URL_ARG \
|
||||
--depositContractAddress=$DEPOSIT_CONTRACT_ADDRESS
|
||||
|
|
|
@ -11,8 +11,9 @@ export NUM_VALIDATORS=${VALIDATORS:-100}
|
|||
export NUM_NODES=${NODES:-9}
|
||||
export NUM_MISSING_NODES=${MISSING_NODES:-1}
|
||||
|
||||
export DEPOSIT_WEB3_URL=ws://localhost:8545
|
||||
export DEPOSIT_CONTRACT_ADDRESS=
|
||||
# Set DEPOSIT_WEB3_URL_ARG to empty to get genesis state from file, not using web3
|
||||
export DEPOSIT_WEB3_URL_ARG=--depositWeb3Url=ws://localhost:8545
|
||||
export DEPOSIT_CONTRACT_ADDRESS=0x
|
||||
|
||||
|
||||
cd "$SIM_ROOT"
|
||||
|
@ -37,13 +38,15 @@ if [ ! -f $LAST_VALIDATOR ]; then
|
|||
|
||||
fi
|
||||
|
||||
export DEPOSIT_CONTRACT_ADDRESS=$($DEPLOY_DEPOSIT_CONTRACT_BIN --depositWeb3Url=$DEPOSIT_WEB3_URL)
|
||||
if [ "$DEPOSIT_WEB3_URL_ARG" != "" ]; then
|
||||
export DEPOSIT_CONTRACT_ADDRESS=$($DEPLOY_DEPOSIT_CONTRACT_BIN $DEPOSIT_WEB3_URL_ARG)
|
||||
fi
|
||||
|
||||
$VALIDATOR_KEYGEN_BIN \
|
||||
--totalValidators=$NUM_VALIDATORS \
|
||||
--outputDir="$VALIDATORS_DIR" \
|
||||
--generateFakeKeys=yes \
|
||||
--depositWeb3Url=$DEPOSIT_WEB3_URL \
|
||||
$DEPOSIT_WEB3_URL_ARG \
|
||||
--depositContractAddress=$DEPOSIT_CONTRACT_ADDRESS
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue