mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-25 12:45:37 +00:00
Fix localtestnet simulation.
This commit is contained in:
parent
28630a1d71
commit
20f695515a
@ -898,47 +898,6 @@ proc createPidFile(filename: string) =
|
|||||||
gPidFile = filename
|
gPidFile = filename
|
||||||
addQuitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
|
addQuitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
|
||||||
|
|
||||||
proc checkDataDir(conf: BeaconNodeConf) =
|
|
||||||
## Checks `conf.dataDir`.
|
|
||||||
## If folder exists, procedure will check it for access and
|
|
||||||
## permissions `0750 (rwxr-x---)`, if folder do not exists it will be created
|
|
||||||
## with permissions `0750 (rwxr-x---)`.
|
|
||||||
let dataDir = string(conf.dataDir)
|
|
||||||
when defined(posix):
|
|
||||||
let amask = {AccessFlags.Read, AccessFlags.Write, AccessFlags.Execute}
|
|
||||||
if fileAccessible(dataDir, amask):
|
|
||||||
let gmask = {UserRead, UserWrite, UserExec, GroupRead, GroupExec}
|
|
||||||
let pmask = {OtherRead, OtherWrite, OtherExec, GroupWrite}
|
|
||||||
let pres = getPermissionsSet(dataDir)
|
|
||||||
if pres.isErr():
|
|
||||||
fatal "Could not check data folder permissions",
|
|
||||||
data_dir = dataDir, errorCode = $pres.error,
|
|
||||||
errorMsg = ioErrorMsg(pres.error)
|
|
||||||
quit QuitFailure
|
|
||||||
let insecurePermissions = pres.get() * pmask
|
|
||||||
if insecurePermissions != {}:
|
|
||||||
fatal "Data folder has insecure permissions",
|
|
||||||
data_dir = dataDir,
|
|
||||||
insecure_permissions = $insecurePermissions,
|
|
||||||
current_permissions = pres.get().toString(),
|
|
||||||
required_permissions = gmask.toString()
|
|
||||||
quit QuitFailure
|
|
||||||
else:
|
|
||||||
let res = createPath(dataDir, 0o750)
|
|
||||||
if res.isErr():
|
|
||||||
fatal "Could not create data folder", data_dir = dataDir,
|
|
||||||
errorMsg = ioErrorMsg(res.error), errorCode = $res.error
|
|
||||||
quit QuitFailure
|
|
||||||
elif defined(windows):
|
|
||||||
let res = createPath(dataDir, 0o750)
|
|
||||||
if res.isErr():
|
|
||||||
fatal "Could not create data folder", data_dir = dataDir,
|
|
||||||
errorMsg = ioErrorMsg(res.error), errorCode = $res.error
|
|
||||||
quit QuitFailure
|
|
||||||
else:
|
|
||||||
fatal "Unsupported operation system"
|
|
||||||
quit QuitFailure
|
|
||||||
|
|
||||||
proc initializeNetworking(node: BeaconNode) {.async.} =
|
proc initializeNetworking(node: BeaconNode) {.async.} =
|
||||||
await node.network.startListening()
|
await node.network.startListening()
|
||||||
|
|
||||||
@ -1136,7 +1095,10 @@ programMain:
|
|||||||
# This is ref so we can mutate it (to erase it) after the initial loading.
|
# This is ref so we can mutate it (to erase it) after the initial loading.
|
||||||
stateSnapshotContents: ref string
|
stateSnapshotContents: ref string
|
||||||
|
|
||||||
checkDataDir(config)
|
if not(checkAndCreateDataDir(config)):
|
||||||
|
# We are unable to access/create data folder or data folder's
|
||||||
|
# permissions are insecure.
|
||||||
|
quit QuitFailure
|
||||||
|
|
||||||
setupLogging(config.logLevel, config.logFile)
|
setupLogging(config.logLevel, config.logFile)
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import
|
import
|
||||||
std/[os, strutils, terminal, wordwrap],
|
std/[os, strutils, terminal, wordwrap],
|
||||||
chronicles, chronos, web3, stint, json_serialization, stew/byteutils,
|
chronicles, chronos, web3, stint, json_serialization,
|
||||||
serialization, blscurve, eth/common/eth_types, eth/keys, confutils, bearssl,
|
serialization, blscurve, eth/common/eth_types, eth/keys, confutils, bearssl,
|
||||||
spec/[datatypes, digest, crypto, keystore],
|
spec/[datatypes, digest, crypto, keystore],
|
||||||
stew/io2, libp2p/crypto/crypto as lcrypto,
|
stew/[byteutils, io2], libp2p/crypto/crypto as lcrypto,
|
||||||
nimcrypto/utils as ncrutils,
|
nimcrypto/utils as ncrutils,
|
||||||
conf, ssz/merkleization, network_metadata
|
conf, ssz/merkleization, network_metadata
|
||||||
|
|
||||||
@ -36,6 +36,47 @@ const
|
|||||||
template echo80(msg: string) =
|
template echo80(msg: string) =
|
||||||
echo wrapWords(msg, 80)
|
echo wrapWords(msg, 80)
|
||||||
|
|
||||||
|
proc checkAndCreateDataDir*(dataDir: string): bool =
|
||||||
|
## Checks `conf.dataDir`.
|
||||||
|
## If folder exists, procedure will check it for access and
|
||||||
|
## permissions `0750 (rwxr-x---)`, if folder do not exists it will be created
|
||||||
|
## with permissions `0750 (rwxr-x---)`.
|
||||||
|
when defined(posix):
|
||||||
|
let amask = {AccessFlags.Read, AccessFlags.Write, AccessFlags.Execute}
|
||||||
|
if fileAccessible(dataDir, amask):
|
||||||
|
let gmask = {UserRead, UserWrite, UserExec, GroupRead, GroupExec}
|
||||||
|
let pmask = {OtherRead, OtherWrite, OtherExec, GroupWrite}
|
||||||
|
let pres = getPermissionsSet(dataDir)
|
||||||
|
if pres.isErr():
|
||||||
|
fatal "Could not check data folder permissions",
|
||||||
|
data_dir = dataDir, errorCode = $pres.error,
|
||||||
|
errorMsg = ioErrorMsg(pres.error)
|
||||||
|
return false
|
||||||
|
let insecurePermissions = pres.get() * pmask
|
||||||
|
if insecurePermissions != {}:
|
||||||
|
fatal "Data folder has insecure permissions",
|
||||||
|
data_dir = dataDir,
|
||||||
|
insecure_permissions = $insecurePermissions,
|
||||||
|
current_permissions = pres.get().toString(),
|
||||||
|
required_permissions = gmask.toString()
|
||||||
|
return false
|
||||||
|
else:
|
||||||
|
let res = createPath(dataDir, 0o750)
|
||||||
|
if res.isErr():
|
||||||
|
fatal "Could not create data folder", data_dir = dataDir,
|
||||||
|
errorMsg = ioErrorMsg(res.error), errorCode = $res.error
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
elif defined(windows):
|
||||||
|
let res = createPath(dataDir, 0o750)
|
||||||
|
if res.isErr():
|
||||||
|
fatal "Could not create data folder", data_dir = dataDir,
|
||||||
|
errorMsg = ioErrorMsg(res.error), errorCode = $res.error
|
||||||
|
return false
|
||||||
|
else:
|
||||||
|
fatal "Unsupported operation system"
|
||||||
|
return false
|
||||||
|
|
||||||
proc loadKeystore(validatorsDir, secretsDir, keyName: string,
|
proc loadKeystore(validatorsDir, secretsDir, keyName: string,
|
||||||
nonInteractive: bool): Option[ValidatorPrivKey] =
|
nonInteractive: bool): Option[ValidatorPrivKey] =
|
||||||
let
|
let
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
tables, random, strutils, os, typetraits,
|
tables, random, strutils, typetraits,
|
||||||
|
|
||||||
# Nimble packages
|
# Nimble packages
|
||||||
chronos, confutils/defs,
|
chronos, confutils/defs,
|
||||||
|
@ -213,6 +213,7 @@ if [[ $USE_GANACHE == "0" ]]; then
|
|||||||
BOOTSTRAP_IP="127.0.0.1"
|
BOOTSTRAP_IP="127.0.0.1"
|
||||||
|
|
||||||
./build/beacon_node createTestnet \
|
./build/beacon_node createTestnet \
|
||||||
|
--data-dir="${DATA_DIR}" \
|
||||||
--deposits-file="${DEPOSITS_FILE}" \
|
--deposits-file="${DEPOSITS_FILE}" \
|
||||||
--total-validators=${TOTAL_VALIDATORS} \
|
--total-validators=${TOTAL_VALIDATORS} \
|
||||||
--last-user-validator=${USER_VALIDATORS} \
|
--last-user-validator=${USER_VALIDATORS} \
|
||||||
@ -316,10 +317,11 @@ fi
|
|||||||
VALIDATORS_PER_VALIDATOR=$(( (SYSTEM_VALIDATORS / NODES_WITH_VALIDATORS) / 2 ))
|
VALIDATORS_PER_VALIDATOR=$(( (SYSTEM_VALIDATORS / NODES_WITH_VALIDATORS) / 2 ))
|
||||||
VALIDATOR_OFFSET=$((SYSTEM_VALIDATORS / 2))
|
VALIDATOR_OFFSET=$((SYSTEM_VALIDATORS / 2))
|
||||||
BOOTSTRAP_ENR="${DATA_DIR}/node${BOOTSTRAP_NODE}/beacon_node.enr"
|
BOOTSTRAP_ENR="${DATA_DIR}/node${BOOTSTRAP_NODE}/beacon_node.enr"
|
||||||
|
NETWORK_KEYFILE="../network_key.json"
|
||||||
|
|
||||||
for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
|
for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
|
||||||
if [[ ${NUM_NODE} == ${BOOTSTRAP_NODE} ]]; then
|
if [[ ${NUM_NODE} == ${BOOTSTRAP_NODE} ]]; then
|
||||||
BOOTSTRAP_ARG="--netkey-file=network_key.json --insecure-netkey-password=true"
|
BOOTSTRAP_ARG="--netkey-file=${NETWORK_KEYFILE} --insecure-netkey-password=true"
|
||||||
else
|
else
|
||||||
BOOTSTRAP_ARG="--bootstrap-file=${BOOTSTRAP_ENR}"
|
BOOTSTRAP_ARG="--bootstrap-file=${BOOTSTRAP_ENR}"
|
||||||
# Wait for the master node to write out its address file
|
# Wait for the master node to write out its address file
|
||||||
@ -339,6 +341,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
|
|||||||
# The first $NODES_WITH_VALIDATORS nodes split them equally between them, after skipping the first $USER_VALIDATORS.
|
# The first $NODES_WITH_VALIDATORS nodes split them equally between them, after skipping the first $USER_VALIDATORS.
|
||||||
NODE_DATA_DIR="${DATA_DIR}/node${NUM_NODE}"
|
NODE_DATA_DIR="${DATA_DIR}/node${NUM_NODE}"
|
||||||
rm -rf "${NODE_DATA_DIR}"
|
rm -rf "${NODE_DATA_DIR}"
|
||||||
|
mkdir -m 0750 -p "${NODE_DATA_DIR}"
|
||||||
mkdir -p "${NODE_DATA_DIR}/validators"
|
mkdir -p "${NODE_DATA_DIR}/validators"
|
||||||
mkdir -p "${NODE_DATA_DIR}/secrets"
|
mkdir -p "${NODE_DATA_DIR}/secrets"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user