Removed all code related to the old network metadata files

Also switched to a more "standard" naming convention for the
command-line parameters.
This commit is contained in:
Zahary Karadjov 2019-10-29 01:04:52 +02:00
parent 9d3889cbab
commit ba0037738b
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
15 changed files with 203 additions and 307 deletions

View File

@ -17,7 +17,6 @@ import
const
dataDirValidators = "validators"
networkMetadataFile = "network.json"
genesisFile = "genesis.json"
testnetsBaseUrl = "https://raw.githubusercontent.com/status-im/nim-eth2-testnet-data/master/www"
hasPrompt = not defined(withoutPrompt)
@ -57,51 +56,6 @@ func databaseDir(conf: BeaconNodeConf): string =
template `//`(url, fragment: string): string =
url & "/" & fragment
proc downloadFile(url: string): Future[string] {.async.} =
# TODO We need a proper HTTP client able to perform HTTPS downloads
let tempFile = getTempDir() / "nimbus.download"
let cmd = "curl --fail -o " & quoteShell(tempFile) & " " & url
let (fileContents, errorCode) = execCmdEx(cmd, options = {poUsePath})
if errorCode != 0:
raise newException(IOError, "Failed external command: '" & cmd & "', exit code: " & $errorCode & ", output: '" & fileContents & "'")
return readFile(tempFile)
proc updateTestnetMetadata(conf: BeaconNodeConf): Future[NetworkMetadata] {.async.} =
let metadataUrl = testnetsBaseUrl // $conf.network // networkMetadataFile
let latestMetadata = await downloadFile(metadataUrl)
try:
result = Json.decode(latestMetadata, NetworkMetadata)
except SerializationError as err:
stderr.write "Error while loading the testnet metadata. Your client my be out of date.\n"
stderr.write err.formatMsg(metadataUrl), "\n"
stderr.write "Please follow the instructions at https://github.com/status-im/nim-beacon-chain " &
"in order to produce an up-to-date build.\n"
quit 1
let localMetadataFile = conf.dataDir / networkMetadataFile
if fileExists(localMetadataFile) and readFile(localMetadataFile).string == latestMetadata:
return
info "New testnet genesis data received. Starting with a fresh database."
createDir conf.dataDir.string
removeDir conf.databaseDir
writeFile localMetadataFile, latestMetadata
let newGenesis = await downloadFile(testnetsBaseUrl // $conf.network // genesisFile)
writeFile conf.dataDir / genesisFile, newGenesis
proc obtainTestnetKey(conf: BeaconNodeConf): Future[(string, string)] {.async.} =
let
metadata = await updateTestnetMetadata(conf)
privKeyName = validatorFileBaseName(rand(metadata.userValidatorsRange)) & ".privkey"
privKeyUrl = testnetsBaseUrl // $conf.network // privKeyName
privKeyContent = strip await downloadFile(privKeyUrl)
let key = ValidatorPrivKey.init(privKeyContent)
return (privKeyName, privKeyContent)
proc saveValidatorKey(keyName, key: string, conf: BeaconNodeConf) =
let validatorsDir = conf.dataDir / dataDirValidators
let outputFile = validatorsDir / keyName
@ -131,7 +85,7 @@ proc getStateFromSnapshot(node: BeaconNode, state: var BeaconState): bool =
elif cmpIgnoreCase(ext, ".json") == 0:
loadSnapshot Json
else:
error "The --stateSnapshot option expects a json or a ssz file."
error "The --state-snapshot option expects a json or a ssz file."
quit 1
except SerializationError as err:
stderr.write "Failed to import ", snapshotFile, "\n"
@ -152,68 +106,31 @@ proc commitGenesisState(node: BeaconNode, tailState: BeaconState) =
stderr.write getCurrentExceptionMsg(), "\n"
quit 1
proc addBootstrapNode(node: BeaconNode, bootstrapNode: BootstrapAddr) =
if bootstrapNode.isSameNode(node.networkIdentity):
node.isBootstrapNode = true
else:
node.bootstrapNodes.add bootstrapNode
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
new result
result.onBeaconBlock = onBeaconBlock
result.config = conf
result.networkIdentity = getPersistentNetIdentity(conf)
result.nickname = if conf.nodename == "auto": shortForm(result.networkIdentity)
else: conf.nodename
result.nickname = if conf.nodeName == "auto": shortForm(result.networkIdentity)
else: conf.nodeName
template fail(args: varargs[untyped]) =
stderr.write args, "\n"
quit 1
if not conf.quickStart:
case conf.network
of "mainnet":
fail "The Serenity mainnet hasn't been launched yet"
of "testnet0", "testnet1":
result.networkMetadata = await updateTestnetMetadata(conf)
else:
try:
result.networkMetadata = Json.loadFile(conf.network, NetworkMetadata)
except SerializationError as err:
fail "Failed to load network metadata: \n", err.formatMsg(conf.network)
var metadataErrorMsg = ""
template checkCompatibility(metadataField, LOCAL_CONSTANT) =
let metadataValue = metadataField
if metadataValue != LOCAL_CONSTANT:
if metadataErrorMsg.len > 0: metadataErrorMsg.add " and"
metadataErrorMsg.add " -d:" & astToStr(LOCAL_CONSTANT) & "=" & $metadataValue &
" (instead of " & $LOCAL_CONSTANT & ")"
if result.networkMetadata.networkGeneration != semanticVersion:
let newerVersionRequired = result.networkMetadata.networkGeneration.int > semanticVersion
let newerOrOlder = if newerVersionRequired: "a newer" else: "an older"
stderr.write &"Connecting to '{conf.network}' requires {newerOrOlder} version of Nimbus. "
if newerVersionRequired:
stderr.write "Please follow the instructions at https://github.com/status-im/nim-beacon-chain " &
"in order to produce an up-to-date build.\n"
quit 1
checkCompatibility result.networkMetadata.numShards , SHARD_COUNT
checkCompatibility result.networkMetadata.slotDuration , SECONDS_PER_SLOT
checkCompatibility result.networkMetadata.slotsPerEpoch , SLOTS_PER_EPOCH
if metadataErrorMsg.len > 0:
fail "To connect to the ", conf.network, " network, please compile with", metadataErrorMsg
for bootNode in result.networkMetadata.bootstrapNodes:
if bootNode.isSameNode(result.networkIdentity):
result.isBootstrapNode = true
else:
result.bootstrapNodes.add bootNode
for bootNode in conf.bootstrapNodes:
result.bootstrapNodes.add BootstrapAddr.init(bootNode)
result.addBootstrapNode BootstrapAddr.init(bootNode)
let bootstrapFile = string conf.bootstrapNodesFile
if bootstrapFile.len > 0:
for ln in lines(bootstrapFile):
result.bootstrapNodes.add BootstrapAddr.init(string ln)
result.addBootstrapNode BootstrapAddr.init(string ln)
result.attachedValidators = ValidatorPool.init
@ -907,7 +824,7 @@ when hasPrompt:
else: Slot(0)
proc initPrompt(node: BeaconNode) =
if isatty(stdout) and node.config.statusbar:
if isatty(stdout) and node.config.statusBarEnabled:
enableTrueColors()
# TODO: nim-prompt seems to have threading issues at the moment
@ -962,7 +879,7 @@ when hasPrompt:
"$" & expr
var statusBar = StatusBarView.init(
node.config.statusbarContents,
node.config.statusBarContents,
dataResolver)
defaultChroniclesStream.output.writer =
@ -1047,42 +964,24 @@ when isMainModule:
bootstrapAddress = getPersistenBootstrapAddr(
config, parseIpAddress(config.bootstrapAddress), Port config.bootstrapPort)
testnetMetadata = NetworkMetadata(
networkGeneration: semanticVersion,
genesisRoot:
if config.withGenesisRoot:
some(hash_tree_root(initialState))
else: none(Eth2Digest),
bootstrapNodes: @[bootstrapAddress],
numShards: SHARD_COUNT,
slotDuration: SECONDS_PER_SLOT,
slotsPerEpoch: SLOTS_PER_EPOCH,
totalValidators: config.totalValidators,
lastUserValidator: config.lastUserValidator)
if config.depositContractAddress.len != 0:
testnetMetadata.depositContractAddress = hexToByteArray[20](config.depositContractAddress).some
Json.saveFile(config.outputNetworkMetadata.string, testnetMetadata, pretty = true)
echo "Wrote ", config.outputNetworkMetadata.string
let bootstrapFile = config.outputBootstrapNodes.string
let bootstrapFile = config.outputBootstrapFile.string
if bootstrapFile.len > 0:
let bootstrapAddrLine = when networkBackend == libp2pBackend:
let bootstrapAddrLine = when networkBackend != rlpxBackend:
$bootstrapAddress.addresses[0] & "/p2p/" & bootstrapAddress.peer.pretty
else:
$bootstrapAddress
writeFile(bootstrapFile, bootstrapAddrLine)
echo "Wrote ", bootstrapFile
of updateTestnet:
discard waitFor updateTestnetMetadata(config)
of importValidator:
template reportFailureFor(keyExpr) =
error "Failed to import validator key", key = keyExpr
programResult = 1
if config.keyFiles.len == 0:
stderr.write "Please specify at least one keyfile to import."
quit 1
for keyFile in config.keyFiles:
try:
saveValidatorKey(keyFile.string.extractFilename,
@ -1090,18 +989,6 @@ when isMainModule:
except:
reportFailureFor keyFile.string
if config.keyFiles.len == 0:
if config.network in ["testnet0", "testnet1"]:
try:
let (keyName, key) = waitFor obtainTestnetKey(config)
saveValidatorKey(keyName, key, config)
except:
stderr.write "Failed to download key\n", getCurrentExceptionMsg()
quit 1
else:
echo "Validator keys can be downloaded only for testnets"
quit 1
of noCommand:
createPidFile(config.dataDir.string / "beacon_node.pid")

View File

@ -16,7 +16,6 @@ type
network*: Eth2Node
forkVersion*: array[4, byte]
networkIdentity*: Eth2NodeIdentity
networkMetadata*: NetworkMetadata
requestManager*: RequestManager
isBootstrapNode*: bool
bootstrapNodes*: seq[BootstrapAddr]
@ -244,23 +243,9 @@ type
RequestManager* = object
network*: Eth2Node
NetworkMetadata* = object
networkGeneration*: uint64
genesisRoot*: Option[Eth2Digest]
depositContractAddress*: Option[array[20, byte]]
bootstrapNodes*: seq[BootstrapAddr]
numShards*: uint64
slotDuration*: uint64
slotsPerEpoch*: uint64
totalValidators*: uint64
lastUserValidator*: uint64
FetchRecord* = object
root*: Eth2Digest
historySlots*: uint64
proc userValidatorsRange*(d: NetworkMetadata): HSlice[int, int] =
0 .. d.lastUserValidator.int
proc shortLog*(v: AttachedValidator): string = shortLog(v.pubKey)

View File

@ -16,48 +16,58 @@ type
noCommand
importValidator
createTestnet
updateTestnet
makeDeposits
Eth1Network* = enum
custom
mainnet
rinkeby
goerli
BeaconNodeConf* = object
logLevel* {.
desc: "Sets the log level",
defaultValue: enabledLogLevel }: LogLevel
desc: "Sets the log level."
defaultValue: enabledLogLevel
longform: "log-level" }: LogLevel
network* {.
desc: "The network Nimbus should connect to. " &
"Possible values: testnet0, testnet1, mainnet, custom-network.json"
longform: "network"
shortform: "n"
defaultValue: DEFAULT_NETWORK }: string
eth1Network* {.
desc: "The Eth1 network tracked by the beacon node."
defaultValue: goerli
longform: "eth1-network" }: Eth1Network
quickStart* {.
desc: "Run in quickstart mode",
defaultValue: false }: bool
desc: "Run in quickstart mode"
defaultValue: false
longform: "quick-start" }: bool
dataDir* {.
desc: "The directory where nimbus will store all blockchain data."
defaultValue: config.defaultDataDir()
shortform: "d"
defaultValue: config.defaultDataDir() }: OutDir
longform: "data-dir" }: OutDir
depositWeb3Url* {.
desc: "URL of the Web3 server to observe Eth1",
defaultValue: "" }: string
desc: "URL of the Web3 server to observe Eth1."
defaultValue: ""
longform: "web3-url" }: string
depositContractAddress* {.
desc: "Address of the deposit contract",
defaultValue: "" }: string
desc: "Address of the deposit contract."
defaultValue: ""
longform: "deposit-contract" }: string
statusbar* {.
desc: "Display a status bar at the bottom of the terminal screen"
defaultValue: true }: bool
statusBarEnabled* {.
desc: "Display a status bar at the bottom of the terminal screen."
defaultValue: true
longform: "status-bar" }: bool
statusbarContents* {.
statusBarContents* {.
desc: ""
defaultValue: "peers: $connected_peers; " &
"epoch: $epoch, slot: $epoch_slot/$slots_per_epoch (..$slot_trailing_digits); " &
"finalized epoch: $last_finalized_epoch |" &
"ETH: $attached_validators_balance" }: string
"ETH: $attached_validators_balance"
longform: "status-bar-contents" }: string
case cmd* {.
command
@ -66,115 +76,132 @@ type
of noCommand:
bootstrapNodes* {.
desc: "Specifies one or more bootstrap nodes to use when connecting to the network."
longform: "bootstrapNode"
shortform: "b" }: seq[string]
shortform: "b"
longform: "bootstrap-node" }: seq[string]
bootstrapNodesFile* {.
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses"
shortform: "f"
defaultValue: "" }: InputFile
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses."
defaultValue: ""
longform: "bootstrap-file" }: InputFile
tcpPort* {.
desc: "TCP listening port"
defaultValue: defaultPort(config) }: int
desc: "TCP listening port."
defaultValue: defaultPort(config)
longform: "tcp-port" }: int
udpPort* {.
desc: "UDP listening port",
defaultValue: defaultPort(config) }: int
desc: "UDP listening port."
defaultValue: defaultPort(config)
longform: "udp-port" }: int
nat* {.
desc: "Specify method to use for determining public address. Must be one of: any, none, upnp, pmp, extip:<IP>"
defaultValue: "any" .}: string
desc: "Specify method to use for determining public address. " &
"Must be one of: any, none, upnp, pmp, extip:<IP>."
defaultValue: "any" }: string
validators* {.
required
desc: "Path to a validator private key, as generated by makeDeposits"
longform: "validator"
shortform: "v".}: seq[ValidatorKeyPath]
desc: "Path to a validator private key, as generated by makeDeposits."
shortform: "v"
longform: "validator" }: seq[ValidatorKeyPath]
stateSnapshot* {.
desc: "Json file specifying a recent state snapshot"
shortform: "s".}: Option[InputFile]
desc: "Json file specifying a recent state snapshot."
shortform: "s"
longform: "state-snapshot" }: Option[InputFile]
nodename* {.
nodeName* {.
desc: "A name for this node that will appear in the logs. " &
"If you set this to 'auto', a persistent automatically generated ID will be seleceted for each --dataDir folder"
defaultValue: ""}: string
"If you set this to 'auto', a persistent automatically generated ID will be seleceted for each --dataDir folder."
defaultValue: ""
longform: "node-name" }: string
metricsServer* {.
desc: "Enable the metrics server"
defaultValue: false.}: bool
desc: "Enable the metrics server."
defaultValue: false
longform: "metrics-server" }: bool
metricsServerAddress* {.
desc: "Listening address of the metrics server"
defaultValue: "0.0.0.0".}: string # TODO: use a validated type here
desc: "Listening address of the metrics server."
defaultValue: "0.0.0.0"
longform: "metrics-server-address" }: string # TODO: use a validated type here
metricsServerPort* {.
desc: "Listening HTTP port of the metrics server"
defaultValue: 8008 .}: uint16
desc: "Listening HTTP port of the metrics server."
defaultValue: 8008
longform: "metrics-server-port" }: uint16
of createTestnet:
validatorsDir* {.
desc: "Directory containing validator descriptors named vXXXXXXX.deposit.json"
shortform: "d".}: InputDir
desc: "Directory containing validator descriptors named 'vXXXXXXX.deposit.json'."
shortform: "d"
longform: "validators-dir" }: InputDir
totalValidators* {.
desc: "The number of validators in the newly created chain".}: uint64
desc: "The number of validators in the newly created chain."
longform: "total-validators" }: uint64
firstValidator* {.
desc: "Index of first validator to add to validator list"
defaultValue: 0 .}: uint64
desc: "Index of first validator to add to validator list."
defaultValue: 0
longform: "first-validator" }: uint64
lastUserValidator* {.
desc: "The last validator index that will free for taking from a testnet participant"
defaultValue: config.totalValidators - 1 .}: uint64
desc: "The last validator index that will free for taking from a testnet participant."
defaultValue: config.totalValidators - 1,
longform: "last-user-validator" }: uint64
bootstrapAddress* {.
desc: "The public IP address that will be advertised as a bootstrap node for the testnet"
defaultValue: "127.0.0.1".}: string
desc: "The public IP address that will be advertised as a bootstrap node for the testnet."
defaultValue: "127.0.0.1"
longform: "bootstrap-address" }: string
bootstrapPort* {.
desc: "The TCP/UDP port that will be used by the bootstrap node"
defaultValue: defaultPort(config) .}: int
desc: "The TCP/UDP port that will be used by the bootstrap node."
defaultValue: defaultPort(config)
longform: "bootstrap-port" }: int
genesisOffset* {.
desc: "Seconds from now to add to genesis time"
desc: "Seconds from now to add to genesis time."
defaultValue: 5
shortForm: "g"
defaultValue: 5 .}: int
longform: "genesis-offset" }: int
outputGenesis* {.
desc: "Output file where to write the initial state snapshot".}: OutFile
outputNetworkMetadata* {.
desc: "Output file where to write the initial state snapshot".}: OutFile
desc: "Output file where to write the initial state snapshot."
longform: "output-genesis" }: OutFile
withGenesisRoot* {.
desc: "Include a genesis root in network.json", defaultValue: false.}: bool
desc: "Include a genesis root in 'network.json'."
defaultValue: false
longform: "with-genesis-root" }: bool
outputBootstrapNodes* {.
desc: "Output file with list of bootstrap nodes for the network".}: OutFile
outputBootstrapFile* {.
desc: "Output file with list of bootstrap nodes for the network."
longform: "output-bootstrap-file" }: OutFile
of importValidator:
keyFiles* {.
longform: "keyfile"
desc: "File with validator key to be imported (in hex form)".}: seq[ValidatorKeyPath]
of updateTestnet:
discard
desc: "File with validator key to be imported (in hex form)."
longform: "keyfile" }: seq[ValidatorKeyPath]
of makeDeposits:
totalDeposits* {.
desc: "Total number of deposits and keys to generate".}: int
desc: "Total number of deposits and keys to generate."
longform: "total-deposits" }: int
depositsDir* {.
desc: "Folder to write deposits to", defaultValue: "validators".}: string
desc: "Folder to write deposits to."
defaultValue: "validators"
longform: "deposits-dir" }: string
randomKeys* {.
desc: "Use random keys (instead of interop keys)", defaultValue: false.}: bool
desc: "Use random keys (instead of interop keys)."
defaultValue: false
longform: "random-keys" }: bool
proc defaultPort*(config: BeaconNodeConf): int =
if config.network == "testnet1": 9100
else: 9000
9000
proc defaultDataDir*(conf: BeaconNodeConf): string =
let dataDir = when defined(windows):
@ -184,14 +211,7 @@ proc defaultDataDir*(conf: BeaconNodeConf): string =
else:
".cache" / "nimbus"
let networkDir = if conf.network in ["testnet0", "testnet1", "mainnet"]:
conf.network
else:
# TODO: This seems silly. Perhaps we should error out here and ask
# the user to specify dataDir as well.
"tempnet"
getHomeDir() / dataDir / "BeaconNode" / networkDir
getHomeDir() / dataDir / "BeaconNode"
proc validatorFileBaseName*(validatorIdx: int): string =
# there can apparently be tops 4M validators so we use 7 digits..

View File

@ -131,8 +131,9 @@ when networkBackend == rlpxBackend:
else:
import
os, random, stew/io,
eth/async_utils, ssz, libp2p/crypto/crypto
os, random,
stew/io, eth/async_utils, libp2p/crypto/crypto,
ssz
when networkBackend == libp2pBackend:
import
@ -157,7 +158,15 @@ else:
Eth2NodeIdentity* = PeerInfo
proc init*(T: type BootstrapAddr, str: string): T =
Json.decode(str, PeerInfo)
# TODO: The code below is quite awkward.
# How do we parse a PeerInfo object out of a bootstrap MultiAddress string such as:
# /ip4/10.20.30.40/tcp/9100/p2p/16Uiu2HAmEAmp4FdpPzypKwTMmsbCdnUafDvXZCpFrUDbYJZNk7hX
var parts = str.split("/p2p/")
if parts.len == 2:
result.peer = PeerID.init(parts[1])
result.addresses.add MultiAddress.init(parts[0])
else:
raise newException(ValueError, "Invalid bootstrap multi-address")
proc ensureNetworkIdFile(conf: BeaconNodeConf): string =
result = conf.dataDir / networkKeyFilename

View File

@ -56,7 +56,7 @@ RUN cd nim-beacon-chain \
FROM debian:9-slim
RUN apt update \
&& apt install -y librocksdb-dev curl psmisc \
&& apt install -y librocksdb-dev psmisc \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

View File

@ -33,23 +33,22 @@ LAST_VALIDATOR="$VALIDATORS_DIR/v$(printf '%07d' $LAST_VALIDATOR_NUM).deposit.js
if [ ! -f "${LAST_VALIDATOR}" ]; then
$BEACON_NODE_BIN makeDeposits \
--totalDeposits="${NUM_VALIDATORS}" \
--depositsDir="$VALIDATORS_DIR" \
--randomKeys=false
--total-deposits="${NUM_VALIDATORS}" \
--deposits-dir="$VALIDATORS_DIR" \
--random-keys=no
fi
if [ ! -f "${SNAPSHOT_FILE}" ]; then
$BEACON_NODE_BIN \
--dataDir="${SIMULATION_DIR}/node-0" \
--data-dir="${SIMULATION_DIR}/node-0" \
createTestnet \
--validatorsDir="${VALIDATORS_DIR}" \
--totalValidators="${NUM_VALIDATORS}" \
--outputGenesis="${SNAPSHOT_FILE}" \
--outputNetworkMetadata="${NETWORK_METADATA_FILE}" \
--outputBootstrapNodes="${SIMULATION_DIR}/bootstrap_nodes.txt" \
--bootstrapAddress=127.0.0.1 \
--bootstrapPort=50000 \
--genesisOffset=30 # Delay in seconds
--validators-dir="${VALIDATORS_DIR}" \
--total-validators="${NUM_VALIDATORS}" \
--output-genesis="${SNAPSHOT_FILE}" \
--output-bootstrap-file="${SIMULATION_DIR}/bootstrap_nodes.txt" \
--bootstrap-address=127.0.0.1 \
--bootstrap-port=50000 \
--genesis-offset=30 # Delay in seconds
fi
# Delete any leftover address files from a previous session

View File

@ -34,11 +34,10 @@ set -x
trap 'kill -9 -- -$$' SIGINT EXIT SIGTERM
./env.sh $BEACON_NODE_BIN \
--statusbar:off \
--network:$NETWORK_METADATA_FILE \
--dataDir:$DATA_DIR \
--nodename:0 \
--tcpPort:$PORT \
--udpPort:$PORT \
--status-bar:off \
--data-dir:$DATA_DIR \
--node-name:0 \
--tcp-port:$PORT \
--udp-port:$PORT \
$NAT_FLAG \
--stateSnapshot:$SNAPSHOT_FILE
--state-snapshot:$SNAPSHOT_FILE

View File

@ -20,6 +20,6 @@ NUM_MISSING_NODES=${MISSING_NODES:-2}
SIMULATION_DIR="${SIM_ROOT}/data"
VALIDATORS_DIR="${SIM_ROOT}/validators"
SNAPSHOT_FILE="${SIMULATION_DIR}/state_snapshot.json"
NETWORK_METADATA_FILE="${SIMULATION_DIR}/network.json"
NETWORK_BOOTSTRAP_FILE="${SIMULATION_DIR}/bootstrap_nodes.txt"
BEACON_NODE_BIN="${SIMULATION_DIR}/beacon_node"
MASTER_NODE_ADDRESS_FILE="${SIMULATION_DIR}/node-0/beacon_node.address"

View File

@ -15,16 +15,15 @@ The `beacon_node` binary has a `createTestnet` command.
```bash
nim c -r beacon_chain/beacon_node \
--network=$NETWORK_NAME \
--dataDir=$DATA_DIR/node-0 \
--data-dir=$DATA_DIR/node-0 \
createTestnet \
--validatorsDir=$NETWORK_DIR \
--totalValidators=$VALIDATOR_COUNT \
--lastUserValidator=$LAST_USER_VALIDATOR \
--outputGenesis=$NETWORK_DIR/genesis.json \
--outputNetworkMetadata=$NETWORK_DIR/network.json \
--outputBootstrapNodes=$NETWORK_DIR/bootstrap_nodes.txt \
--bootstrapAddress=$PUBLIC_IP \
--genesisOffset=600 # Delay in seconds
--validators-dir=$NETWORK_DIR \
--total-validators=$VALIDATOR_COUNT \
--last-user-validator=$LAST_USER_VALIDATOR \
--output-genesis=$NETWORK_DIR/genesis.json \
--output-bootstrap-file=$NETWORK_DIR/bootstrap_nodes.txt \
--bootstrap-address=$PUBLIC_IP \
--genesis-offset=600 # Delay in seconds
```
Replace ENV vars with values that make sense to you.

View File

@ -18,7 +18,7 @@ NETWORK_DIR=$WWW_DIR/$NETWORK_NAME
for i in $(seq $FIRST_VALIDATOR $LAST_VALIDATOR); do
VALIDATOR=v$(printf '%07d' $i)
beacon_chain/beacon_node --dataDir="$DATA_DIR/node-$NODE_ID" importValidator \
beacon_chain/beacon_node --data-dir="$DATA_DIR/node-$NODE_ID" importValidator \
--keyfile="$NETWORK_DIR/$VALIDATOR.privkey"
done

View File

@ -42,7 +42,7 @@ DATA_DIR_ABS=$(mkdir -p "$DATA_DIR"; cd "$DATA_DIR"; pwd)
NETWORK_DIR_ABS="$ETH2_TESTNET_DATA_DIR_ABS/www/$NETWORK_NAME"
if [ "$WEB3_URL" != "" ]; then
WEB3_URL_ARG="--depositWeb3Url=$WEB3_URL"
WEB3_URL_ARG="--web3-url=$WEB3_URL"
fi
DOCKER_BEACON_NODE="docker run -v $NETWORK_DIR_ABS:/network_dir -v $DATA_DIR_ABS:/data_dir statusteam/nimbus_beacon_node:$NETWORK_NAME"
@ -51,7 +51,7 @@ make deposit_contract
if [ "$ETH1_PRIVATE_KEY" != "" ]; then
DEPOSIT_CONTRACT_ADDRESS=$(./build/deposit_contract deploy $WEB3_URL_ARG --privateKey=$ETH1_PRIVATE_KEY)
DEPOSIT_CONTRACT_ADDRESS_ARG="--depositContractAddress=$DEPOSIT_CONTRACT_ADDRESS"
DEPOSIT_CONTRACT_ADDRESS_ARG="--deposit_contract=$DEPOSIT_CONTRACT_ADDRESS"
fi
cd docker
@ -62,25 +62,24 @@ make build
if [ ! -f $NETWORK_DIR_ABS/genesis.ssz ]; then
rm -f $NETWORK_DIR_ABS/*
$DOCKER_BEACON_NODE makeDeposits \
--totalDeposits=$VALIDATOR_COUNT \
--depositsDir=/network_dir \
--randomKeys=false
--total-deposits=$VALIDATOR_COUNT \
--deposits-dir=/network_dir \
--random-keys=no
fi
$DOCKER_BEACON_NODE \
--network=$NETWORK_NAME \
--dataDir=/data_dir \
--data-dir=/data_dir \
createTestnet \
--validatorsDir=/network_dir \
--totalValidators=$VALIDATOR_COUNT \
--lastUserValidator=$LAST_USER_VALIDATOR \
--outputGenesis=/network_dir/genesis.json \
--outputBootstrapNodes=/network_dir/bootstrap_nodes.txt \
--outputNetworkMetadata=/network_dir/network.json \
--bootstrapAddress=$BOOTSTRAP_IP \
--bootstrapPort=$BOOTSTRAP_PORT \
--validators-dir=/network_dir \
--total-validators=$VALIDATOR_COUNT \
--last-user-validator=$LAST_USER_VALIDATOR \
--output-genesis=/network_dir/genesis.json \
--output-bootstrap-file=/network_dir/bootstrap_nodes.txt \
--bootstrap-address=$BOOTSTRAP_IP \
--bootstrap-port=$BOOTSTRAP_PORT \
$WEB3_URL_ARG $DEPOSIT_CONTRACT_ADDRESS_ARG \
--genesisOffset=60 # Delay in seconds
--genesis-offset=60 # Delay in seconds
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
echo Persisting testnet data to git...

View File

@ -29,17 +29,17 @@ pushd $VALIDATORS_DIR >/dev/null
popd >/dev/null
$BEACON_NODE_BIN \
--network:$NETWORK_METADATA_FILE \
--dataDir:$DATA_DIR \
--nodename:$NODE_ID \
--tcpPort:$PORT \
--udpPort:$PORT \
--bootstrap-file=$NETWORK_BOOTSTRAP_FILE \
--data-dir=$DATA_DIR \
--node-name=$NODE_ID \
--tcp-port=$PORT \
--udp-port=$PORT \
$NAT_FLAG \
--stateSnapshot:$SNAPSHOT_FILE \
--state-snapshot=$SNAPSHOT_FILE \
$DEPOSIT_WEB3_URL_ARG \
--depositContractAddress=$DEPOSIT_CONTRACT_ADDRESS \
--metricsServer=true \
--metricsServerAddress="127.0.0.1" \
--metricsServerPort="$(( $BASE_METRICS_PORT + $NODE_ID ))" \
--deposit-contract=$DEPOSIT_CONTRACT_ADDRESS \
--metrics-server=on \
--metrics-server-address="127.0.0.1" \
--metrics-server-port="$(( $BASE_METRICS_PORT + $NODE_ID ))" \
"$@"

View File

@ -9,7 +9,7 @@ source "$(dirname "$0")/vars.sh"
source "${SIM_ROOT}/../../env.sh"
# 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_WEB3_URL_ARG=--web3-url=ws://localhost:8545
export DEPOSIT_WEB3_URL_ARG=
export DEPOSIT_CONTRACT_ADDRESS=0x
@ -44,25 +44,24 @@ if [ ! -f "${LAST_VALIDATOR}" ]; then
fi
$BEACON_NODE_BIN makeDeposits \
--totalDeposits="${NUM_VALIDATORS}" \
--depositsDir="$VALIDATORS_DIR" \
--randomKeys=false \
--total-deposits="${NUM_VALIDATORS}" \
--deposits-dir="$VALIDATORS_DIR" \
--random-keys=no \
$DEPOSIT_WEB3_URL_ARG \
--depositContractAddress="${DEPOSIT_CONTRACT_ADDRESS}"
--deposit-contract="${DEPOSIT_CONTRACT_ADDRESS}"
fi
if [ ! -f "${SNAPSHOT_FILE}" ]; then
$BEACON_NODE_BIN \
--dataDir="${SIMULATION_DIR}/node-0" \
--data-dir="${SIMULATION_DIR}/node-0" \
createTestnet \
--validatorsDir="${VALIDATORS_DIR}" \
--totalValidators="${NUM_VALIDATORS}" \
--outputGenesis="${SNAPSHOT_FILE}" \
--outputNetworkMetadata="${NETWORK_METADATA_FILE}" \
--outputBootstrapNodes="${SIMULATION_DIR}/bootstrap_nodes.txt" \
--bootstrapAddress=127.0.0.1 \
--bootstrapPort=50000 \
--genesisOffset=5 # Delay in seconds
--validators-dir="${VALIDATORS_DIR}" \
--total-validators="${NUM_VALIDATORS}" \
--output-genesis="${SNAPSHOT_FILE}" \
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
--bootstrap-address=127.0.0.1 \
--bootstrap-port=50000 \
--genesis-offset=5 # Delay in seconds
fi
# Delete any leftover address files from a previous session
@ -117,7 +116,7 @@ for i in $(seq 0 $LAST_NODE); do
done
fi
CMD="${SIM_ROOT}/run_node.sh $i --statusbar:off"
CMD="${SIM_ROOT}/run_node.sh $i --status-bar:off"
if [[ "$USE_MULTITAIL" != "no" ]]; then
if [[ "$i" == "0" ]]; then

View File

@ -23,7 +23,7 @@ SIMULATION_DIR="${SIM_ROOT}/data"
METRICS_DIR="${SIM_ROOT}/prometheus"
VALIDATORS_DIR="${SIM_ROOT}/validators"
SNAPSHOT_FILE="${SIMULATION_DIR}/state_snapshot.json"
NETWORK_METADATA_FILE="${SIMULATION_DIR}/network.json"
NETWORK_BOOTSTRAP_FILE="${SIMULATION_DIR}/bootstrap_nodes.txt"
BEACON_NODE_BIN="${SIMULATION_DIR}/beacon_node"
DEPLOY_DEPOSIT_CONTRACT_BIN="${SIMULATION_DIR}/deploy_deposit_contract"
MASTER_NODE_ADDRESS_FILE="${SIMULATION_DIR}/node-0/beacon_node.address"

@ -1 +1 @@
Subproject commit adc63e8aff3fc4fb9154de448f46031a1ab18ac6
Subproject commit 36645f1322c64deba03432d34dd75a9dafbd95ed