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

View File

@ -29,22 +29,21 @@ proc loadKeyStore(conf: BeaconNodeConf|ValidatorClientConf,
error "Failed to read keystore", err = err.msg, path = keystorePath
return
if conf.secretsDir.isSome:
let passphrasePath = conf.secretsDir.get / keyName
if fileExists(passphrasePath):
let
passphrase = KeyStorePass:
try: readFile(passphrasePath)
except IOError as err:
error "Failed to read passphrase file", err = err.msg, path = passphrasePath
return
let passphrasePath = conf.secretsDir / keyName
if fileExists(passphrasePath):
let
passphrase = KeyStorePass:
try: readFile(passphrasePath)
except IOError as err:
error "Failed to read passphrase file", err = err.msg, path = passphrasePath
return
let res = decryptKeystore(keystoreContents, passphrase)
if res.isOk:
return res.get.some
else:
error "Failed to decrypt keystore", keystorePath, passphrasePath
return
let res = decryptKeystore(keystoreContents, passphrase)
if res.isOk:
return res.get.some
else:
error "Failed to decrypt keystore", keystorePath, passphrasePath
return
if conf.nonInteractive:
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
quit 1
let validatorsDir = conf.localValidatorsDir
let validatorsDir = conf.validatorsDir
try:
for kind, file in walkDir(validatorsDir):
if kind == pcDir:

View File

@ -34,7 +34,7 @@ declareCounter beacon_blocks_proposed,
logScope: topics = "beacval"
proc saveValidatorKey*(keyName, key: string, conf: BeaconNodeConf) =
let validatorsDir = conf.localValidatorsDir
let validatorsDir = conf.validatorsDir
let outputFile = validatorsDir / keyName
createDir validatorsDir
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
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 -a "${SECRETS_DIR}/${VALIDATOR}" "${NODE_DATA_DIR}/secrets"
cp -a "${SECRETS_DIR}/${VALIDATOR}" "${NODE_DATA_DIR}/secrets/"
done
fi