From 6f0845f8eb8d5aa1c4b552f4c3c7113f3e962b65 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 7 May 2024 16:40:30 +0800 Subject: [PATCH 1/4] Update keystore_management.nim show some fail tips on import invalid keys --- beacon_chain/validators/keystore_management.nim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/beacon_chain/validators/keystore_management.nim b/beacon_chain/validators/keystore_management.nim index 9610c439dd..091aab3284 100644 --- a/beacon_chain/validators/keystore_management.nim +++ b/beacon_chain/validators/keystore_management.nim @@ -1811,9 +1811,15 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, burnMem(singleSaltSalt) try: - for file in walkDirRec(importedDir): + let importedFiles = walkDirRec(importedDir).toSeq + if importedFiles.len == 0: + fatal "No keystore file found at kyes path" + var invalidFlag = false + var hasValid = false + for file in importedFiles: let filenameParts = splitFile(file) if toLowerAscii(filenameParts.ext) != ".json": + invalidFlag = true continue # In case we are importing from eth2.0-deposits-cli, the imported @@ -1821,8 +1827,11 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, # intended for uploading to the launchpad. We'll skip it to avoid # the "Invalid keystore" warning that it will trigger. if filenameParts.name.startsWith("deposit_data"): + invalidFlag = true continue + hasValid = true + let keystore = try: Json.loadFile(file, Keystore, @@ -1892,6 +1901,8 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, if password.len == 0: break + if not hasValid and invalidFlag: + fatal "Not found valid file,the keystore file must ending by .json and not start with deposit_data" except OSError: fatal "Failed to access the imported deposits directory" quit 1 From 0968559fa6ff910ee08aa4fdec61963f884ac949 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 7 May 2024 22:04:30 +0800 Subject: [PATCH 2/4] fix quit with exit code 1 --- beacon_chain/validators/keystore_management.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/beacon_chain/validators/keystore_management.nim b/beacon_chain/validators/keystore_management.nim index 091aab3284..f04a461a49 100644 --- a/beacon_chain/validators/keystore_management.nim +++ b/beacon_chain/validators/keystore_management.nim @@ -1814,6 +1814,8 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, let importedFiles = walkDirRec(importedDir).toSeq if importedFiles.len == 0: fatal "No keystore file found at kyes path" + quit 1 + var invalidFlag = false var hasValid = false for file in importedFiles: @@ -1903,6 +1905,8 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, break if not hasValid and invalidFlag: fatal "Not found valid file,the keystore file must ending by .json and not start with deposit_data" + quit 1 + except OSError: fatal "Failed to access the imported deposits directory" quit 1 From d85bb22ffce1a10614dd3f9366413d5e3cf5b502 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 7 May 2024 22:07:35 +0800 Subject: [PATCH 3/4] fix typically style --- beacon_chain/validators/keystore_management.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beacon_chain/validators/keystore_management.nim b/beacon_chain/validators/keystore_management.nim index f04a461a49..19f6d8e45a 100644 --- a/beacon_chain/validators/keystore_management.nim +++ b/beacon_chain/validators/keystore_management.nim @@ -1816,8 +1816,9 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, fatal "No keystore file found at kyes path" quit 1 - var invalidFlag = false - var hasValid = false + var + invalidFlag = false + hasValid = false for file in importedFiles: let filenameParts = splitFile(file) if toLowerAscii(filenameParts.ext) != ".json": From b642db966c254cc900b5644c7f13a378df15eae4 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 30 May 2024 22:12:46 +0800 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: tersec --- beacon_chain/validators/keystore_management.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon_chain/validators/keystore_management.nim b/beacon_chain/validators/keystore_management.nim index 19f6d8e45a..6bf74e3782 100644 --- a/beacon_chain/validators/keystore_management.nim +++ b/beacon_chain/validators/keystore_management.nim @@ -1813,7 +1813,7 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, try: let importedFiles = walkDirRec(importedDir).toSeq if importedFiles.len == 0: - fatal "No keystore file found at kyes path" + fatal "No keystore file found at keystore path" quit 1 var @@ -1905,7 +1905,7 @@ proc importKeystoresFromDir*(rng: var HmacDrbgContext, meth: ImportMethod, if password.len == 0: break if not hasValid and invalidFlag: - fatal "Not found valid file,the keystore file must ending by .json and not start with deposit_data" + fatal "No valid keystore file found; the keystore file must have a .json extension and not start with deposit_data" quit 1 except OSError: