Skip to content

Commit

Permalink
fix: improve error logging of voluntary-exit command (#5756)
Browse files Browse the repository at this point in the history
* fix: improve error logging of voluntary-exit command

* Update packages/cli/src/cmds/validator/voluntaryExit.ts

Co-authored-by: Phil Ngo <58080811+philknows@users.noreply.github.com>

---------

Co-authored-by: Phil Ngo <58080811+philknows@users.noreply.github.com>
  • Loading branch information
nflaig and philknows authored Jul 13, 2023
1 parent 3921c2f commit fbe9beb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export async function decryptKeystoreDefinitions(
keystoreDefinitions: LocalKeystoreDefinition[],
opts: KeystoreDecryptOptions
): Promise<SignerLocal[]> {
if (keystoreDefinitions.length === 0) {
return [];
}

if (opts.cacheFilePath) {
try {
const signers = await loadKeystoreCache(opts.cacheFilePath, keystoreDefinitions);
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/cmds/validator/voluntaryExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If no `pubkeys` are provided, it will exit all validators that have been importe

examples: [
{
command: "validator voluntary-exit --pubkeys 0xF00",
command: "validator voluntary-exit --network goerli --pubkeys 0xF00",
description: "Perform a voluntary exit for the validator who has a public key 0xF00",
},
],
Expand Down Expand Up @@ -78,6 +78,11 @@ If no `pubkeys` are provided, it will exit all validators that have been importe

// Select signers to exit
const signers = await getSignersFromArgs(args, network, {logger: console, signal: new AbortController().signal});
if (signers.length === 0) {
throw new YargsError(`No local keystores found with current args.
Ensure --dataDir and --network match values used when importing keys via validator import
or alternatively, import keys by providing --importKeystores arg to voluntary-exit command.`);
}
const signersToExit = selectSignersToExit(args, signers);
const validatorsToExit = await resolveValidatorIndexes(client, signersToExit);

Expand Down Expand Up @@ -153,7 +158,8 @@ async function resolveValidatorIndexes(client: Api, signersToExit: SignerLocalPu
return signersToExit.map(({signer, pubkey}) => {
const item = dataByPubkey.get(pubkey);
if (!item) {
throw Error(`beacon node did not return status for pubkey ${pubkey}`);
throw new YargsError(`Validator with pubkey ${pubkey} is unknown.
Re-check the pubkey submitted or wait until the validator is activated on the beacon chain to voluntary exit.`);
}

return {
Expand Down

0 comments on commit fbe9beb

Please sign in to comment.