mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-18 17:37:33 +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
|
||||||
@ -129,6 +129,9 @@ 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
|
||||||
|
|
||||||
|
try:
|
||||||
|
info "Importing snapshot file", path = snapshotFile
|
||||||
|
|
||||||
let
|
let
|
||||||
tailState = Json.loadFile(snapshotFile, BeaconState)
|
tailState = Json.loadFile(snapshotFile, BeaconState)
|
||||||
tailBlock = get_initial_beacon_block(tailState)
|
tailBlock = get_initial_beacon_block(tailState)
|
||||||
@ -145,6 +148,15 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
|
|||||||
result.db.putTailBlock(blockRoot)
|
result.db.putTailBlock(blockRoot)
|
||||||
result.db.putHeadBlock(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