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