Provide a default value for secretsDir (similar to validatorsDir)

This commit is contained in:
Zahary Karadjov 2020-06-03 14:52:36 +03:00 committed by zah
parent a75c632f7a
commit 2acda1c115
4 changed files with 24 additions and 22 deletions

View File

@ -105,11 +105,11 @@ type
abbr: "v" abbr: "v"
name: "validator" }: seq[ValidatorKeyPath] name: "validator" }: seq[ValidatorKeyPath]
validatorsDir* {. validatorsDirFlag* {.
desc: "A directory containing validator keystores." desc: "A directory containing validator keystores."
name: "validators-dir" }: Option[InputDir] name: "validators-dir" }: Option[InputDir]
secretsDir* {. secretsDirFlag* {.
desc: "A directory containing validator keystore passwords." desc: "A directory containing validator keystore passwords."
name: "secrets-dir" }: Option[InputDir] name: "secrets-dir" }: Option[InputDir]
@ -324,8 +324,11 @@ proc defaultDataDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
func dumpDir*(conf: BeaconNodeConf|ValidatorClientConf): string = func dumpDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
conf.dataDir / "dump" conf.dataDir / "dump"
func localValidatorsDir*(conf: BeaconNodeConf|ValidatorClientConf): string = func validatorsDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
string conf.validatorsDir.get(InputDir(conf.dataDir / "validators")) string conf.validatorsDirFlag.get(InputDir(conf.dataDir / "validators"))
func secretsDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
string conf.secretsDirFlag.get(InputDir(conf.dataDir / "secrets"))
func databaseDir*(conf: BeaconNodeConf|ValidatorClientConf): string = func databaseDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
conf.dataDir / "db" conf.dataDir / "db"

View File

@ -29,22 +29,21 @@ proc loadKeyStore(conf: BeaconNodeConf|ValidatorClientConf,
error "Failed to read keystore", err = err.msg, path = keystorePath error "Failed to read keystore", err = err.msg, path = keystorePath
return return
if conf.secretsDir.isSome: let passphrasePath = conf.secretsDir / keyName
let passphrasePath = conf.secretsDir.get / keyName if fileExists(passphrasePath):
if fileExists(passphrasePath): let
let passphrase = KeyStorePass:
passphrase = KeyStorePass: try: readFile(passphrasePath)
try: readFile(passphrasePath) except IOError as err:
except IOError as err: error "Failed to read passphrase file", err = err.msg, path = passphrasePath
error "Failed to read passphrase file", err = err.msg, path = passphrasePath return
return
let res = decryptKeystore(keystoreContents, passphrase) let res = decryptKeystore(keystoreContents, passphrase)
if res.isOk: if res.isOk:
return res.get.some return res.get.some
else: else:
error "Failed to decrypt keystore", keystorePath, passphrasePath error "Failed to decrypt keystore", keystorePath, passphrasePath
return return
if conf.nonInteractive: if conf.nonInteractive:
error "Unable to load validator key store. Please ensure matching passphrase exists in the secrets dir", error "Unable to load validator key store. Please ensure matching passphrase exists in the secrets dir",
@ -76,7 +75,7 @@ iterator validatorKeys*(conf: BeaconNodeConf|ValidatorClientConf): ValidatorPriv
file = validatorKeyFile.string, err = err.msg file = validatorKeyFile.string, err = err.msg
quit 1 quit 1
let validatorsDir = conf.localValidatorsDir let validatorsDir = conf.validatorsDir
try: try:
for kind, file in walkDir(validatorsDir): for kind, file in walkDir(validatorsDir):
if kind == pcDir: if kind == pcDir:

View File

@ -34,7 +34,7 @@ declareCounter beacon_blocks_proposed,
logScope: topics = "beacval" logScope: topics = "beacval"
proc saveValidatorKey*(keyName, key: string, conf: BeaconNodeConf) = proc saveValidatorKey*(keyName, key: string, conf: BeaconNodeConf) =
let validatorsDir = conf.localValidatorsDir let validatorsDir = conf.validatorsDir
let outputFile = validatorsDir / keyName let outputFile = validatorsDir / keyName
createDir validatorsDir createDir validatorsDir
writeFile(outputFile, key) writeFile(outputFile, key)

View File

@ -212,7 +212,7 @@ for NUM_NODE in $(seq 0 $((NUM_NODES - 1))); do
if [[ $NUM_NODE -lt $NODES_WITH_VALIDATORS ]]; then if [[ $NUM_NODE -lt $NODES_WITH_VALIDATORS ]]; then
for VALIDATOR in $(ls ${DEPOSITS_DIR} | tail -n +$(( $USER_VALIDATORS + ($VALIDATORS_PER_NODE * $NUM_NODE) + 1 )) | head -n $VALIDATORS_PER_NODE); do for VALIDATOR in $(ls ${DEPOSITS_DIR} | tail -n +$(( $USER_VALIDATORS + ($VALIDATORS_PER_NODE * $NUM_NODE) + 1 )) | head -n $VALIDATORS_PER_NODE); do
cp -ar "${DEPOSITS_DIR}/$VALIDATOR" "${NODE_DATA_DIR}/validators/" cp -ar "${DEPOSITS_DIR}/$VALIDATOR" "${NODE_DATA_DIR}/validators/"
cp -a "${SECRETS_DIR}/${VALIDATOR}" "${NODE_DATA_DIR}/secrets" cp -a "${SECRETS_DIR}/${VALIDATOR}" "${NODE_DATA_DIR}/secrets/"
done done
fi fi