Update local_testnet and simulation scripts to use netkey-file and insecure-netkey-password.

Add more logging
This commit is contained in:
cheatfate 2020-08-25 15:49:05 +03:00 committed by zah
parent e1182f8000
commit add22a20e1
6 changed files with 35 additions and 30 deletions

View File

@ -82,6 +82,18 @@ type
desc: "Do not display interative prompts. Quit on missing configuration"
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* {.
command
defaultValue: noCommand }: BNStartUpCmd
@ -218,18 +230,6 @@ type
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
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:
testnetDepositsFile* {.
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"
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:
case walletsCmd* {.command.}: WalletsCmd
of WalletsCmd.create:

View File

@ -1214,6 +1214,9 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
fatal "Could not generate random network key file"
quit QuitFailure
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())
else:
let keyPath =
@ -1270,12 +1273,15 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
return KeyPair(seckey: privKey, pubkey: pubKey)
of createTestnet:
let netKeyFile = string(conf.outputNetkeyFile)
if conf.netKeyFile == "random":
fatal "Could not create testnet using `random` network key"
quit QuitFailure
let keyPath =
if isAbsolute(netKeyFile):
netKeyFile
if isAbsolute(conf.netKeyFile):
conf.netKeyFile
else:
conf.dataDir / netKeyFile
conf.dataDir / conf.netKeyFile
let rres = PrivateKey.random(Secp256k1, rng)
if rres.isErr():
@ -1287,14 +1293,14 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
# Insecure password used only for automated testing.
let insecurePassword =
if conf.outputNetKeyInsecurePassword:
if conf.netKeyInsecurePassword:
some(NetworkInsecureKeyPassword)
else:
none[string]()
let sres = saveNetKeystore(rng, keyPath, privKey, insecurePassword)
if sres.isErr():
fatal "Could not create network key file"
fatal "Could not create network key file", key_path = keyPath
quit QuitFailure
info "New network key storage was created", key_path = keyPath,

View File

@ -202,7 +202,8 @@ proc saveNetKeystore*(rng: var BrHmacDrbgContext, keyStorePath: string,
): Result[void, KeystoreGenerationError] =
var password, confirmedPassword: TaintedString
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()
else:
while true:
@ -244,12 +245,14 @@ proc saveNetKeystore*(rng: var BrHmacDrbgContext, keyStorePath: string,
try:
encodedStorage = Json.encode(keyStore)
except SerializationError:
error "Could not serialize network key storage", key_path = keyStorePath
return err(FailedToCreateKeystoreFile)
let res = writeFile(keyStorePath, encodedStorage, 0o600)
if res.isOk():
ok()
else:
error "Could not write to network key storage file", key_path = keyStorePath
err(FailedToCreateKeystoreFile)
proc saveKeystore(rng: var BrHmacDrbgContext,

View File

@ -218,6 +218,8 @@ if [[ $USE_GANACHE == "0" ]]; then
--output-bootstrap-file="${NETWORK_DIR}/bootstrap_nodes.txt" \
--bootstrap-address=${BOOTSTRAP_IP} \
--bootstrap-port=${BASE_PORT} \
--netkey-file=network_key.json \
--insecure-netkey-password=true \
--genesis-offset=${GENESIS_OFFSET} # Delay in seconds
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
if [[ ${NUM_NODE} == ${BOOTSTRAP_NODE} ]]; then
BOOTSTRAP_ARG=""
BOOTSTRAP_ARG="--netkey-file=network_key.json --insecure-netkey-password=true"
else
BOOTSTRAP_ARG="--bootstrap-file=${BOOTSTRAP_ENR}"
# Wait for the master node to write out its address file

View File

@ -29,6 +29,8 @@ BOOTSTRAP_ADDRESS_FILE="${SIMULATION_DIR}/node-${BOOTSTRAP_NODE_ID}/beacon_node.
if [[ "$NODE_ID" != "$BOOTSTRAP_NODE" ]]; then
BOOTSTRAP_ARG="--bootstrap-file=$BOOTSTRAP_ADDRESS_FILE"
else
BOOTSTRAP_ARG="--netkey-file=network_key.json --insecure-netkey-password"
fi
# set up the environment

View File

@ -143,6 +143,8 @@ if [ ! -f "${SNAPSHOT_FILE}" ]; then
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
--bootstrap-address=127.0.0.1 \
--bootstrap-port=$(( BASE_P2P_PORT + BOOTSTRAP_NODE )) \
--netkey-file=network_key.json \
--insecure-netkey-password=true \
--genesis-offset=30 # Delay in seconds
fi
fi