Improve keystore loading log statements to show information about why keystore was not loaded. (#5480)
Fix checkKeyName issue for `00` case.
This commit is contained in:
parent
0cca65904d
commit
1da202156f
|
@ -603,16 +603,16 @@ proc removeValidator*(pool: var ValidatorPool,
|
||||||
pool.removeValidator(publicKey)
|
pool.removeValidator(publicKey)
|
||||||
ok(res.value())
|
ok(res.value())
|
||||||
|
|
||||||
func checkKeyName(keyName: string): bool =
|
func checkKeyName(keyName: string): Result[void, string] =
|
||||||
const keyAlphabet = {'a'..'f', 'A'..'F', '0'..'9'}
|
const keyAlphabet = {'a'..'f', 'A'..'F', '0'..'9'}
|
||||||
if len(keyName) != KeyNameSize:
|
if len(keyName) != KeyNameSize:
|
||||||
return false
|
return err("Length should be at least " & $KeyNameSize & " characters")
|
||||||
if keyName[0] != '0' and keyName[1] != 'x':
|
if keyName[0] != '0' or keyName[1] != 'x':
|
||||||
return false
|
return err("Name should be prefixed with '0x' characters")
|
||||||
for index in 2 ..< len(keyName):
|
for index in 2 ..< len(keyName):
|
||||||
if keyName[index] notin keyAlphabet:
|
if keyName[index] notin keyAlphabet:
|
||||||
return false
|
return err("Incorrect characters found in name")
|
||||||
true
|
ok()
|
||||||
|
|
||||||
proc existsKeystore(keystoreDir: string, keyKind: KeystoreKind): bool {.
|
proc existsKeystore(keystoreDir: string, keyKind: KeystoreKind): bool {.
|
||||||
raises: [].} =
|
raises: [].} =
|
||||||
|
@ -694,36 +694,46 @@ proc queryValidatorsSource*(web3signerUrl: Uri): Future[QueryResult] {.async.} =
|
||||||
|
|
||||||
iterator listLoadableKeys*(validatorsDir, secretsDir: string,
|
iterator listLoadableKeys*(validatorsDir, secretsDir: string,
|
||||||
keysMask: set[KeystoreKind]): CookedPubKey =
|
keysMask: set[KeystoreKind]): CookedPubKey =
|
||||||
|
const IncorrectName = "Incorrect keystore directory name, ignoring"
|
||||||
try:
|
try:
|
||||||
|
logScope:
|
||||||
|
keystore_dir = keystoreDir
|
||||||
|
|
||||||
for kind, file in walkDir(validatorsDir):
|
for kind, file in walkDir(validatorsDir):
|
||||||
if kind == pcDir:
|
if kind == pcDir:
|
||||||
let
|
let
|
||||||
keyName = splitFile(file).name
|
keyName = splitFile(file).name
|
||||||
keystoreDir = validatorsDir / keyName
|
keystoreDir = validatorsDir / keyName
|
||||||
|
nameres = checkKeyName(keyName)
|
||||||
|
|
||||||
if not(checkKeyName(keyName)):
|
if nameres.isErr():
|
||||||
# Skip folders which name do not satisfy "0x[a-fA-F0-9]{96, 96}".
|
notice IncorrectName, reason = nameres.error
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not(existsKeystore(keystoreDir, keysMask)):
|
if not(existsKeystore(keystoreDir, keysMask)):
|
||||||
# Skip folder which do not satisfy `keysMask`.
|
notice "Incorrect keystore directory, ignoring",
|
||||||
|
reason = "Missing keystore files ('keystore.json' or " &
|
||||||
|
"'remote_keystore.json')"
|
||||||
continue
|
continue
|
||||||
|
|
||||||
let kres = ValidatorPubKey.fromHex(keyName)
|
let kres = ValidatorPubKey.fromHex(keyName)
|
||||||
if kres.isErr():
|
if kres.isErr():
|
||||||
# Skip folders which could not be decoded to ValidatorPubKey.
|
let reason = "Directory name should be correct validators public key"
|
||||||
|
notice IncorrectName, reason = reason
|
||||||
continue
|
continue
|
||||||
|
|
||||||
let publicKey = kres.get()
|
let publicKey = kres.get()
|
||||||
|
|
||||||
let cres = publicKey.load().valueOr:
|
let cres = publicKey.load().valueOr:
|
||||||
# Skip folders which has invalid ValidatorPubKey
|
let reason = "Directory name should be correct validators public " &
|
||||||
# (point is not on curve).
|
"key (point is not in curve)"
|
||||||
|
notice IncorrectName, reason = reason
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield cres
|
yield cres
|
||||||
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
error "Validator keystores directory not accessible",
|
error "Validator keystores directory is not accessible",
|
||||||
path = validatorsDir, err = err.msg
|
path = validatorsDir, err = err.msg
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
|
@ -731,20 +741,26 @@ iterator listLoadableKeystores*(validatorsDir, secretsDir: string,
|
||||||
nonInteractive: bool,
|
nonInteractive: bool,
|
||||||
keysMask: set[KeystoreKind],
|
keysMask: set[KeystoreKind],
|
||||||
cache: KeystoreCacheRef): KeystoreData =
|
cache: KeystoreCacheRef): KeystoreData =
|
||||||
|
const IncorrectName = "Incorrect keystore directory name, ignoring"
|
||||||
try:
|
try:
|
||||||
|
logScope:
|
||||||
|
keystore_dir = keystoreDir
|
||||||
|
|
||||||
for kind, file in walkDir(validatorsDir):
|
for kind, file in walkDir(validatorsDir):
|
||||||
if kind == pcDir:
|
if kind == pcDir:
|
||||||
|
|
||||||
let
|
let
|
||||||
keyName = splitFile(file).name
|
keyName = splitFile(file).name
|
||||||
keystoreDir = validatorsDir / keyName
|
keystoreDir = validatorsDir / keyName
|
||||||
|
nameres = checkKeyName(keyName)
|
||||||
|
|
||||||
if not(checkKeyName(keyName)):
|
if nameres.isErr():
|
||||||
# Skip folders which name do not satisfy "0x[a-fA-F0-9]{96, 96}".
|
notice IncorrectName, reason = nameres.error
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not(existsKeystore(keystoreDir, keysMask)):
|
if not(existsKeystore(keystoreDir, keysMask)):
|
||||||
# Skip folders which do not have keystore file inside.
|
notice "Incorrect keystore directory, ignoring",
|
||||||
|
reason = "Missing keystore files ('keystore.json' or " &
|
||||||
|
"'remote_keystore.json')"
|
||||||
continue
|
continue
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -756,7 +772,7 @@ iterator listLoadableKeystores*(validatorsDir, secretsDir: string,
|
||||||
yield keystore
|
yield keystore
|
||||||
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
error "Validator keystores directory not accessible",
|
error "Validator keystores directory is not accessible",
|
||||||
path = validatorsDir, err = err.msg
|
path = validatorsDir, err = err.msg
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue