mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-18 09:27:05 +00:00
Much better error reporting on snapshot deserialization problems
This commit is contained in:
parent
b454501595
commit
6ec8ffe0ff
@ -1,6 +1,6 @@
|
|||||||
import
|
import
|
||||||
std_shims/[os_shims, objects], net, sequtils, options, tables, osproc, random,
|
std_shims/[os_shims, objects], net, sequtils, options, tables, osproc, random,
|
||||||
chronos, chronicles, confutils,
|
chronos, chronicles, confutils, serialization/errors,
|
||||||
spec/[datatypes, digest, crypto, beaconstate, helpers, validator], conf, time,
|
spec/[datatypes, digest, crypto, beaconstate, helpers, validator], conf, time,
|
||||||
state_transition, fork_choice, ssz, beacon_chain_db, validator_pool, extras,
|
state_transition, fork_choice, ssz, beacon_chain_db, validator_pool, extras,
|
||||||
attestation_pool, block_pool, eth2_network, beacon_node_types,
|
attestation_pool, block_pool, eth2_network, beacon_node_types,
|
||||||
@ -41,7 +41,7 @@ template `//`(url, fragment: string): string =
|
|||||||
url & "/" & fragment
|
url & "/" & fragment
|
||||||
|
|
||||||
proc downloadFile(url: string): Future[string] {.async.} =
|
proc downloadFile(url: string): Future[string] {.async.} =
|
||||||
let (fileContents, errorCode) = execCmdEx("curl --fail " & url)
|
let (fileContents, errorCode) = execCmdEx("curl --fail " & url, options = {poUsePath})
|
||||||
if errorCode != 0:
|
if errorCode != 0:
|
||||||
raise newException(IOError, "Failed to download URL: " & url)
|
raise newException(IOError, "Failed to download URL: " & url)
|
||||||
return fileContents
|
return fileContents
|
||||||
@ -50,12 +50,12 @@ proc updateTestnetMetadata(conf: BeaconNodeConf): Future[NetworkMetadata] {.asyn
|
|||||||
let latestMetadata = await downloadFile(testnetsBaseUrl // $conf.network //
|
let latestMetadata = await downloadFile(testnetsBaseUrl // $conf.network //
|
||||||
netBackendName & "-" & networkMetadataFile)
|
netBackendName & "-" & networkMetadataFile)
|
||||||
|
|
||||||
|
result = Json.decode(latestMetadata, NetworkMetadata)
|
||||||
|
|
||||||
let localMetadataFile = conf.dataDir / networkMetadataFile
|
let localMetadataFile = conf.dataDir / networkMetadataFile
|
||||||
if fileExists(localMetadataFile) and readFile(localMetadataFile).string == latestMetadata:
|
if fileExists(localMetadataFile) and readFile(localMetadataFile).string == latestMetadata:
|
||||||
return
|
return
|
||||||
|
|
||||||
result = Json.decode(latestMetadata, NetworkMetadata)
|
|
||||||
|
|
||||||
info "New testnet genesis data received. Starting with a fresh database."
|
info "New testnet genesis data received. Starting with a fresh database."
|
||||||
removeDir conf.databaseDir
|
removeDir conf.databaseDir
|
||||||
writeFile localMetadataFile, latestMetadata
|
writeFile localMetadataFile, latestMetadata
|
||||||
@ -107,7 +107,7 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
|
|||||||
checkCompatibility result.networkMetadata.slotsPerEpoch , SLOTS_PER_EPOCH
|
checkCompatibility result.networkMetadata.slotsPerEpoch , SLOTS_PER_EPOCH
|
||||||
|
|
||||||
if metadataErrorMsg.len > 0:
|
if metadataErrorMsg.len > 0:
|
||||||
fail "To connect to the ", conf.network, " network, please compile with ", metadataErrorMsg
|
fail "To connect to the ", conf.network, " network, please compile with", metadataErrorMsg
|
||||||
|
|
||||||
result.attachedValidators = ValidatorPool.init
|
result.attachedValidators = ValidatorPool.init
|
||||||
init result.mainchainMonitor, "", Port(0) # TODO: specify geth address and port
|
init result.mainchainMonitor, "", Port(0) # TODO: specify geth address and port
|
||||||
@ -129,21 +129,33 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
|
|||||||
error "Nimbus database not initialized. Please specify the initial state snapshot file."
|
error "Nimbus database not initialized. Please specify the initial state snapshot file."
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
let
|
try:
|
||||||
tailState = Json.loadFile(snapshotFile, BeaconState)
|
info "Importing snapshot file", path = snapshotFile
|
||||||
tailBlock = get_initial_beacon_block(tailState)
|
|
||||||
blockRoot = hash_tree_root_final(tailBlock)
|
|
||||||
|
|
||||||
notice "Creating new database from snapshot",
|
let
|
||||||
blockRoot = shortLog(blockRoot),
|
tailState = Json.loadFile(snapshotFile, BeaconState)
|
||||||
stateRoot = shortLog(tailBlock.state_root),
|
tailBlock = get_initial_beacon_block(tailState)
|
||||||
fork = tailState.fork,
|
blockRoot = hash_tree_root_final(tailBlock)
|
||||||
validators = tailState.validator_registry.len()
|
|
||||||
|
|
||||||
result.db.putState(tailState)
|
notice "Creating new database from snapshot",
|
||||||
result.db.putBlock(tailBlock)
|
blockRoot = shortLog(blockRoot),
|
||||||
result.db.putTailBlock(blockRoot)
|
stateRoot = shortLog(tailBlock.state_root),
|
||||||
result.db.putHeadBlock(blockRoot)
|
fork = tailState.fork,
|
||||||
|
validators = tailState.validator_registry.len()
|
||||||
|
|
||||||
|
result.db.putState(tailState)
|
||||||
|
result.db.putBlock(tailBlock)
|
||||||
|
result.db.putTailBlock(blockRoot)
|
||||||
|
result.db.putHeadBlock(blockRoot)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
result.blockPool = BlockPool.init(result.db)
|
result.blockPool = BlockPool.init(result.db)
|
||||||
result.attestationPool = AttestationPool.init(result.blockPool)
|
result.attestationPool = AttestationPool.init(result.blockPool)
|
||||||
|
13
scripts/connect_to_testnet.sh
Executable file
13
scripts/connect_to_testnet.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
cd $(dirname "$0")
|
||||||
|
|
||||||
|
NETWORK_NAME=$1
|
||||||
|
source "$NETWORK_NAME.env"
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
NIM_FLAGS="-d:debug -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
|
||||||
|
nim c $NIM_FLAGS -r beacon_chain/beacon_node
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user