mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-20 10:18:35 +00:00
Update local_testnet and simulation scripts to use netkey-file and insecure-netkey-password.
Add more logging
This commit is contained in:
parent
e1182f8000
commit
add22a20e1
@ -82,6 +82,18 @@ type
|
|||||||
desc: "Do not display interative prompts. Quit on missing configuration"
|
desc: "Do not display interative prompts. Quit on missing configuration"
|
||||||
name: "non-interactive" }: bool
|
name: "non-interactive" }: bool
|
||||||
|
|
||||||
|
netKeyFile* {.
|
||||||
|
defaultValue: "random",
|
||||||
|
desc: "Source of network (secp256k1) private key file " &
|
||||||
|
"(random|<path>) (default: random)"
|
||||||
|
name: "netkey-file" }: string
|
||||||
|
|
||||||
|
netKeyInsecurePassword* {.
|
||||||
|
defaultValue: false,
|
||||||
|
desc: "Use pre-generated INSECURE password for network private key " &
|
||||||
|
"file (default: false)"
|
||||||
|
name: "insecure-netkey-password" }: bool
|
||||||
|
|
||||||
case cmd* {.
|
case cmd* {.
|
||||||
command
|
command
|
||||||
defaultValue: noCommand }: BNStartUpCmd
|
defaultValue: noCommand }: BNStartUpCmd
|
||||||
@ -218,18 +230,6 @@ type
|
|||||||
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
|
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
|
||||||
name: "dump" }: bool
|
name: "dump" }: bool
|
||||||
|
|
||||||
netKeyFile* {.
|
|
||||||
defaultValue: "random",
|
|
||||||
desc: "Source of network (secp256k1) private key file " &
|
|
||||||
"(random|<path>) (default: random)"
|
|
||||||
name: "netkey-file" }: string
|
|
||||||
|
|
||||||
netKeyInsecurePassword* {.
|
|
||||||
defaultValue: false,
|
|
||||||
desc: "Use pre-generated INSECURE password for network private key " &
|
|
||||||
"file (default: false)"
|
|
||||||
name: "insecure-netkey-password" }: bool
|
|
||||||
|
|
||||||
of createTestnet:
|
of createTestnet:
|
||||||
testnetDepositsFile* {.
|
testnetDepositsFile* {.
|
||||||
desc: "A LaunchPad deposits file for the genesis state validators"
|
desc: "A LaunchPad deposits file for the genesis state validators"
|
||||||
@ -277,16 +277,6 @@ type
|
|||||||
desc: "Output file with list of bootstrap nodes for the network"
|
desc: "Output file with list of bootstrap nodes for the network"
|
||||||
name: "output-bootstrap-file" }: OutFile
|
name: "output-bootstrap-file" }: OutFile
|
||||||
|
|
||||||
outputNetkeyFile* {.
|
|
||||||
desc: "Output file with network private key for the network"
|
|
||||||
name: "netkey-file" }: OutFile
|
|
||||||
|
|
||||||
outputNetKeyInsecurePassword* {.
|
|
||||||
defaultValue: false,
|
|
||||||
desc: "Use pre-generated INSECURE password for network private key " &
|
|
||||||
"file (default: false)"
|
|
||||||
name: "insecure-netkey-password" }: bool
|
|
||||||
|
|
||||||
of wallets:
|
of wallets:
|
||||||
case walletsCmd* {.command.}: WalletsCmd
|
case walletsCmd* {.command.}: WalletsCmd
|
||||||
of WalletsCmd.create:
|
of WalletsCmd.create:
|
||||||
|
@ -1214,6 +1214,9 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||||||
fatal "Could not generate random network key file"
|
fatal "Could not generate random network key file"
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
let privKey = res.get()
|
let privKey = res.get()
|
||||||
|
let pubKey = privKey.getKey().tryGet()
|
||||||
|
info "Using random network key",
|
||||||
|
network_public_key = byteutils.toHex(pubKey.getBytes().tryGet())
|
||||||
return KeyPair(seckey: privKey, pubkey: privKey.getKey().tryGet())
|
return KeyPair(seckey: privKey, pubkey: privKey.getKey().tryGet())
|
||||||
else:
|
else:
|
||||||
let keyPath =
|
let keyPath =
|
||||||
@ -1270,12 +1273,15 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||||||
return KeyPair(seckey: privKey, pubkey: pubKey)
|
return KeyPair(seckey: privKey, pubkey: pubKey)
|
||||||
|
|
||||||
of createTestnet:
|
of createTestnet:
|
||||||
let netKeyFile = string(conf.outputNetkeyFile)
|
if conf.netKeyFile == "random":
|
||||||
|
fatal "Could not create testnet using `random` network key"
|
||||||
|
quit QuitFailure
|
||||||
|
|
||||||
let keyPath =
|
let keyPath =
|
||||||
if isAbsolute(netKeyFile):
|
if isAbsolute(conf.netKeyFile):
|
||||||
netKeyFile
|
conf.netKeyFile
|
||||||
else:
|
else:
|
||||||
conf.dataDir / netKeyFile
|
conf.dataDir / conf.netKeyFile
|
||||||
|
|
||||||
let rres = PrivateKey.random(Secp256k1, rng)
|
let rres = PrivateKey.random(Secp256k1, rng)
|
||||||
if rres.isErr():
|
if rres.isErr():
|
||||||
@ -1287,14 +1293,14 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||||||
|
|
||||||
# Insecure password used only for automated testing.
|
# Insecure password used only for automated testing.
|
||||||
let insecurePassword =
|
let insecurePassword =
|
||||||
if conf.outputNetKeyInsecurePassword:
|
if conf.netKeyInsecurePassword:
|
||||||
some(NetworkInsecureKeyPassword)
|
some(NetworkInsecureKeyPassword)
|
||||||
else:
|
else:
|
||||||
none[string]()
|
none[string]()
|
||||||
|
|
||||||
let sres = saveNetKeystore(rng, keyPath, privKey, insecurePassword)
|
let sres = saveNetKeystore(rng, keyPath, privKey, insecurePassword)
|
||||||
if sres.isErr():
|
if sres.isErr():
|
||||||
fatal "Could not create network key file"
|
fatal "Could not create network key file", key_path = keyPath
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
|
|
||||||
info "New network key storage was created", key_path = keyPath,
|
info "New network key storage was created", key_path = keyPath,
|
||||||
|
@ -202,7 +202,8 @@ proc saveNetKeystore*(rng: var BrHmacDrbgContext, keyStorePath: string,
|
|||||||
): Result[void, KeystoreGenerationError] =
|
): Result[void, KeystoreGenerationError] =
|
||||||
var password, confirmedPassword: TaintedString
|
var password, confirmedPassword: TaintedString
|
||||||
if insecurePwd.isSome():
|
if insecurePwd.isSome():
|
||||||
warn "Using insecure password to lock networking key"
|
warn "Using insecure password to lock networking key",
|
||||||
|
key_path = keyStorePath
|
||||||
password = insecurePwd.get()
|
password = insecurePwd.get()
|
||||||
else:
|
else:
|
||||||
while true:
|
while true:
|
||||||
@ -244,12 +245,14 @@ proc saveNetKeystore*(rng: var BrHmacDrbgContext, keyStorePath: string,
|
|||||||
try:
|
try:
|
||||||
encodedStorage = Json.encode(keyStore)
|
encodedStorage = Json.encode(keyStore)
|
||||||
except SerializationError:
|
except SerializationError:
|
||||||
|
error "Could not serialize network key storage", key_path = keyStorePath
|
||||||
return err(FailedToCreateKeystoreFile)
|
return err(FailedToCreateKeystoreFile)
|
||||||
|
|
||||||
let res = writeFile(keyStorePath, encodedStorage, 0o600)
|
let res = writeFile(keyStorePath, encodedStorage, 0o600)
|
||||||
if res.isOk():
|
if res.isOk():
|
||||||
ok()
|
ok()
|
||||||
else:
|
else:
|
||||||
|
error "Could not write to network key storage file", key_path = keyStorePath
|
||||||
err(FailedToCreateKeystoreFile)
|
err(FailedToCreateKeystoreFile)
|
||||||
|
|
||||||
proc saveKeystore(rng: var BrHmacDrbgContext,
|
proc saveKeystore(rng: var BrHmacDrbgContext,
|
||||||
|
@ -218,6 +218,8 @@ if [[ $USE_GANACHE == "0" ]]; then
|
|||||||
--output-bootstrap-file="${NETWORK_DIR}/bootstrap_nodes.txt" \
|
--output-bootstrap-file="${NETWORK_DIR}/bootstrap_nodes.txt" \
|
||||||
--bootstrap-address=${BOOTSTRAP_IP} \
|
--bootstrap-address=${BOOTSTRAP_IP} \
|
||||||
--bootstrap-port=${BASE_PORT} \
|
--bootstrap-port=${BASE_PORT} \
|
||||||
|
--netkey-file=network_key.json \
|
||||||
|
--insecure-netkey-password=true \
|
||||||
--genesis-offset=${GENESIS_OFFSET} # Delay in seconds
|
--genesis-offset=${GENESIS_OFFSET} # Delay in seconds
|
||||||
|
|
||||||
STATE_SNAPSHOT_ARG="--state-snapshot=${NETWORK_DIR}/genesis.ssz"
|
STATE_SNAPSHOT_ARG="--state-snapshot=${NETWORK_DIR}/genesis.ssz"
|
||||||
@ -315,7 +317,7 @@ BOOTSTRAP_ENR="${DATA_DIR}/node${BOOTSTRAP_NODE}/beacon_node.enr"
|
|||||||
|
|
||||||
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=""
|
BOOTSTRAP_ARG="--netkey-file=network_key.json --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
|
||||||
|
@ -29,6 +29,8 @@ BOOTSTRAP_ADDRESS_FILE="${SIMULATION_DIR}/node-${BOOTSTRAP_NODE_ID}/beacon_node.
|
|||||||
|
|
||||||
if [[ "$NODE_ID" != "$BOOTSTRAP_NODE" ]]; then
|
if [[ "$NODE_ID" != "$BOOTSTRAP_NODE" ]]; then
|
||||||
BOOTSTRAP_ARG="--bootstrap-file=$BOOTSTRAP_ADDRESS_FILE"
|
BOOTSTRAP_ARG="--bootstrap-file=$BOOTSTRAP_ADDRESS_FILE"
|
||||||
|
else
|
||||||
|
BOOTSTRAP_ARG="--netkey-file=network_key.json --insecure-netkey-password"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set up the environment
|
# set up the environment
|
||||||
|
@ -143,6 +143,8 @@ if [ ! -f "${SNAPSHOT_FILE}" ]; then
|
|||||||
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
|
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
|
||||||
--bootstrap-address=127.0.0.1 \
|
--bootstrap-address=127.0.0.1 \
|
||||||
--bootstrap-port=$(( BASE_P2P_PORT + BOOTSTRAP_NODE )) \
|
--bootstrap-port=$(( BASE_P2P_PORT + BOOTSTRAP_NODE )) \
|
||||||
|
--netkey-file=network_key.json \
|
||||||
|
--insecure-netkey-password=true \
|
||||||
--genesis-offset=30 # Delay in seconds
|
--genesis-offset=30 # Delay in seconds
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user