mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-11 06:46:10 +00:00
added the --network=<x> option to the tools for which it matters
This commit is contained in:
parent
3bb2bcdfc9
commit
9a8e81ceec
@ -1038,35 +1038,7 @@ programMain:
|
||||
setupLogging(config.logLevel, config.logFile)
|
||||
|
||||
if config.eth2Network.isSome:
|
||||
let
|
||||
networkName = config.eth2Network.get
|
||||
metadata = case toLowerAscii(networkName)
|
||||
of "mainnet":
|
||||
mainnetMetadata
|
||||
of "altona":
|
||||
altonaMetadata
|
||||
of "medalla":
|
||||
medallaMetadata
|
||||
of "testnet0":
|
||||
testnet0Metadata
|
||||
of "testnet1":
|
||||
testnet1Metadata
|
||||
else:
|
||||
if fileExists(networkName):
|
||||
try:
|
||||
Json.loadFile(networkName, Eth2NetworkMetadata)
|
||||
except SerializationError as err:
|
||||
echo err.formatMsg(networkName)
|
||||
quit 1
|
||||
else:
|
||||
fatal "Unrecognized network name", networkName
|
||||
quit 1
|
||||
|
||||
if metadata.incompatible:
|
||||
fatal "The selected network is not compatible with the current build",
|
||||
reason = metadata.incompatibilityDesc
|
||||
quit 1
|
||||
|
||||
let metadata = getMetadataForNetwork(config.eth2Network.get)
|
||||
config.runtimePreset = metadata.runtimePreset
|
||||
|
||||
if config.cmd == noCommand:
|
||||
@ -1083,7 +1055,7 @@ programMain:
|
||||
# regular command-line options (that may conflict).
|
||||
if config.fieldName.isSome:
|
||||
fatal "Invalid CLI arguments specified. You must not specify '--network' and '" & flagName & "' at the same time",
|
||||
networkParam = networkName, `flagName` = config.fieldName.get
|
||||
networkParam = config.eth2Network.get, `flagName` = config.fieldName.get
|
||||
quit 1
|
||||
|
||||
checkForIncompatibleOption "deposit-contract", depositContractAddress
|
||||
@ -1120,7 +1092,7 @@ programMain:
|
||||
else: (waitFor getEth1BlockHash(config.web3Url, blockId("latest"))).asEth2Digest
|
||||
var
|
||||
initialState = initialize_beacon_state_from_eth1(
|
||||
defaultRuntimePreset, eth1Hash, startTime, deposits, {skipBlsValidation})
|
||||
config.runtimePreset, eth1Hash, startTime, deposits, {skipBlsValidation})
|
||||
|
||||
# https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state
|
||||
initialState.genesis_time = startTime
|
||||
@ -1140,7 +1112,7 @@ programMain:
|
||||
if bootstrapFile.len > 0:
|
||||
let
|
||||
networkKeys = getPersistentNetKeys(rng[], config)
|
||||
metadata = getPersistentNetMetadata(config)
|
||||
netMetadata = getPersistentNetMetadata(config)
|
||||
bootstrapEnr = enr.Record.init(
|
||||
1, # sequence number
|
||||
networkKeys.seckey.asEthKey,
|
||||
@ -1148,7 +1120,7 @@ programMain:
|
||||
config.bootstrapPort,
|
||||
config.bootstrapPort,
|
||||
[toFieldPair("eth2", SSZ.encode(enrForkIdFromState initialState[])),
|
||||
toFieldPair("attnets", SSZ.encode(metadata.attnets))])
|
||||
toFieldPair("attnets", SSZ.encode(netMetadata.attnets))])
|
||||
|
||||
writeFile(bootstrapFile, bootstrapEnr.tryGet().toURI)
|
||||
echo "Wrote ", bootstrapFile
|
||||
|
@ -1,6 +1,7 @@
|
||||
import
|
||||
os, sequtils, strutils, options, json, terminal, random,
|
||||
chronos, chronicles, confutils, stint, json_serialization,
|
||||
../beacon_chain/network_metadata,
|
||||
web3, web3/confutils_defs, eth/keys,
|
||||
spec/[datatypes, crypto, presets], ssz/merkleization, keystore_management
|
||||
|
||||
@ -34,6 +35,10 @@ type
|
||||
desc: "Ask for an Eth1 private key interactively"
|
||||
name: "ask-for-key" }: bool
|
||||
|
||||
eth2Network* {.
|
||||
desc: "The Eth2 network preset to use"
|
||||
name: "network" }: Option[string]
|
||||
|
||||
case cmd* {.command.}: StartUpCommand
|
||||
of deploy:
|
||||
discard
|
||||
@ -171,7 +176,7 @@ proc main() {.async.} =
|
||||
if cfg.cmd == StartUpCommand.generateSimulationDeposits:
|
||||
let
|
||||
mnemonic = generateMnemonic(rng[])
|
||||
runtimePreset = defaultRuntimePreset
|
||||
runtimePreset = getRuntimePresetForNetwork(cfg.eth2Network)
|
||||
|
||||
createDir(string cfg.outValidatorsDir)
|
||||
createDir(string cfg.outSecretsDir)
|
||||
|
@ -1,8 +1,12 @@
|
||||
import
|
||||
tables, strutils, os, options,
|
||||
tables, strutils, os,
|
||||
stew/shims/macros, nimcrypto/hash,
|
||||
web3/[ethtypes, conversions],
|
||||
spec/presets
|
||||
chronicles,
|
||||
spec/presets,
|
||||
spec/datatypes,
|
||||
json_serialization,
|
||||
json_serialization/std/[options, sets, net], serialization/errors
|
||||
|
||||
# ATTENTION! This file will produce a large C file, because we are inlining
|
||||
# genesis states as C literals in the generated code (and blobs in the final
|
||||
@ -166,3 +170,39 @@ const
|
||||
testnet1Metadata* = loadEth2NetworkMetadata(
|
||||
currentSourcePath.parentDir / ".." / "vendor" / "eth2-testnets" / "nimbus" / "testnet1")
|
||||
|
||||
{.pop.} # the following pocedures raise more than just `Defect`
|
||||
|
||||
proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
|
||||
let
|
||||
metadata = case toLowerAscii(networkName)
|
||||
of "mainnet":
|
||||
mainnetMetadata
|
||||
of "altona":
|
||||
altonaMetadata
|
||||
of "medalla":
|
||||
medallaMetadata
|
||||
of "testnet0":
|
||||
testnet0Metadata
|
||||
of "testnet1":
|
||||
testnet1Metadata
|
||||
else:
|
||||
if fileExists(networkName):
|
||||
try:
|
||||
Json.loadFile(networkName, Eth2NetworkMetadata)
|
||||
except SerializationError as err:
|
||||
echo err.formatMsg(networkName)
|
||||
quit 1
|
||||
else:
|
||||
fatal "Unrecognized network name", networkName
|
||||
quit 1
|
||||
|
||||
if metadata.incompatible:
|
||||
fatal "The selected network is not compatible with the current build",
|
||||
reason = metadata.incompatibilityDesc
|
||||
quit 1
|
||||
return metadata
|
||||
|
||||
proc getRuntimePresetForNetwork*(eth2Network: Option[string]): RuntimePreset =
|
||||
if eth2Network.isSome:
|
||||
return getMetadataForNetwork(eth2Network.get).runtimePreset
|
||||
return defaultRuntimePreset
|
||||
|
@ -3,6 +3,7 @@ import
|
||||
stew/byteutils,
|
||||
../beacon_chain/spec/[crypto, datatypes, digest, state_transition],
|
||||
../beacon_chain/extras,
|
||||
../beacon_chain/network_metadata,
|
||||
../beacon_chain/ssz/[merkleization, ssz_serialization]
|
||||
|
||||
type
|
||||
@ -12,6 +13,11 @@ type
|
||||
transition = "Run state transition function"
|
||||
|
||||
NcliConf* = object
|
||||
|
||||
eth2Network* {.
|
||||
desc: "The Eth2 network preset to use"
|
||||
name: "network" }: Option[string]
|
||||
|
||||
# TODO confutils argument pragma doesn't seem to do much; also, the cases
|
||||
# are largely equivalent, but this helps create command line usage text
|
||||
case cmd* {.command}: Cmd
|
||||
@ -61,7 +67,8 @@ proc doTransition(conf: NcliConf) =
|
||||
|
||||
stateY.root = hash_tree_root(stateY.data)
|
||||
|
||||
if not state_transition(defaultRuntimePreset, stateY[], blckX, flags, noRollback):
|
||||
if not state_transition(getRuntimePresetForNetwork(conf.eth2Network),
|
||||
stateY[], blckX, flags, noRollback):
|
||||
error "State transition failed"
|
||||
quit 1
|
||||
else:
|
||||
|
@ -1,6 +1,7 @@
|
||||
import
|
||||
confutils, stats, chronicles, strformat, tables,
|
||||
stew/byteutils,
|
||||
../beacon_chain/network_metadata,
|
||||
../beacon_chain/[beacon_chain_db, extras],
|
||||
../beacon_chain/block_pools/[chain_dag],
|
||||
../beacon_chain/spec/[crypto, datatypes, digest, helpers,
|
||||
@ -31,6 +32,10 @@ type
|
||||
desc: "Directory where `nbc.sqlite` is stored"
|
||||
name: "db" }: InputDir
|
||||
|
||||
eth2Network* {.
|
||||
desc: "The Eth2 network preset to use"
|
||||
name: "network" }: Option[string]
|
||||
|
||||
case cmd* {.
|
||||
command
|
||||
desc: ""
|
||||
@ -63,7 +68,7 @@ type
|
||||
argument
|
||||
desc: "Slot".}: uint64
|
||||
|
||||
proc cmdBench(conf: DbConf) =
|
||||
proc cmdBench(conf: DbConf, runtimePreset: RuntimePreset) =
|
||||
var timers: array[Timers, RunningStat]
|
||||
|
||||
echo "Opening database..."
|
||||
@ -79,7 +84,7 @@ proc cmdBench(conf: DbConf) =
|
||||
|
||||
echo "Initializing block pool..."
|
||||
let pool = withTimerRet(timers[tInit]):
|
||||
ChainDAGRef.init(defaultRuntimePreset, db, {})
|
||||
ChainDAGRef.init(runtimePreset, db, {})
|
||||
|
||||
echo &"Loaded {pool.blocks.len} blocks, head slot {pool.head.slot}"
|
||||
|
||||
@ -111,7 +116,7 @@ proc cmdBench(conf: DbConf) =
|
||||
isEpoch = state[].data.get_current_epoch() !=
|
||||
b.message.slot.compute_epoch_at_slot
|
||||
withTimer(timers[if isEpoch: tApplyEpochBlock else: tApplyBlock]):
|
||||
if not state_transition(defaultRuntimePreset, state[], b, {}, noRollback):
|
||||
if not state_transition(runtimePreset, state[], b, {}, noRollback):
|
||||
dump("./", b)
|
||||
echo "State transition failed (!)"
|
||||
quit 1
|
||||
@ -152,7 +157,7 @@ proc cmdDumpBlock(conf: DbConf) =
|
||||
except CatchableError as e:
|
||||
echo "Couldn't load ", blockRoot, ": ", e.msg
|
||||
|
||||
proc cmdRewindState(conf: DbConf) =
|
||||
proc cmdRewindState(conf: DbConf, runtimePreset: RuntimePreset) =
|
||||
echo "Opening database..."
|
||||
let
|
||||
db = BeaconChainDB.init(
|
||||
@ -163,7 +168,7 @@ proc cmdRewindState(conf: DbConf) =
|
||||
quit 1
|
||||
|
||||
echo "Initializing block pool..."
|
||||
let dag = init(ChainDAGRef, defaultRuntimePreset, db)
|
||||
let dag = init(ChainDAGRef, runtimePreset, db)
|
||||
|
||||
let blckRef = dag.getRef(fromHex(Eth2Digest, conf.blockRoot))
|
||||
if blckRef == nil:
|
||||
@ -175,15 +180,16 @@ proc cmdRewindState(conf: DbConf) =
|
||||
dump("./", hashedState, blck)
|
||||
|
||||
when isMainModule:
|
||||
let
|
||||
var
|
||||
conf = DbConf.load()
|
||||
runtimePreset = getRuntimePresetForNetwork(conf.eth2Network)
|
||||
|
||||
case conf.cmd
|
||||
of bench:
|
||||
cmdBench(conf)
|
||||
cmdBench(conf, runtimePreset)
|
||||
of dumpState:
|
||||
cmdDumpState(conf)
|
||||
of dumpBlock:
|
||||
cmdDumpBlock(conf)
|
||||
of rewindState:
|
||||
cmdRewindState(conf)
|
||||
cmdRewindState(conf, runtimePreset)
|
||||
|
Loading…
x
Reference in New Issue
Block a user