Extend error messages when voluntary exit errors because of present of lockfile (#3935)

* Extend error and Clean up

* Only showing the message to use --force to override in case of voluntary exit
This commit is contained in:
dadepo
2022-05-10 10:54:31 +02:00
committed by GitHub
parent 70ea8cdd58
commit 7fd5a4f416
12 changed files with 43 additions and 47 deletions

View File

@@ -117,7 +117,7 @@ has the '.json' extension will be attempted to be imported.",
}
const dir = getValidatorDirPath({keystoresDir, pubkey, prefixed: true});
if (fs.existsSync(dir) || fs.existsSync(getValidatorDirPath({keystoresDir, pubkey}))) {
console.log(`Skipping existing validator ${pubkey}`);
console.log(`Skipping existing validator ${pubkey}. Already exist in ${dir}`);
continue;
}
@@ -128,10 +128,11 @@ has the '.json' extension will be attempted to be imported.",
const passphrase = await getKeystorePassphrase(keystore, passphrasePaths, passphraseFile);
fs.mkdirSync(secretsDir, {recursive: true});
fs.mkdirSync(dir, {recursive: true});
fs.writeFileSync(path.join(dir, VOTING_KEYSTORE_FILE), keystore.stringify());
const votingKeystoreFile = path.join(dir, VOTING_KEYSTORE_FILE);
fs.writeFileSync(votingKeystoreFile, keystore.stringify());
writeValidatorPassphrase({secretsDir, pubkey, passphrase});
console.log(`Successfully imported validator ${pubkey}`);
console.log(`Successfully imported validator ${pubkey} to ${votingKeystoreFile}`);
numOfImportedValidators++;
}
@@ -202,3 +203,11 @@ required each time the validator client starts
return answers.password;
}
/**
* Extend an existing error by appending a string to its `e.message`
*/
export function extendError(e: Error, prependMessage: string): Error {
e.message = `${e.message} - ${prependMessage}`;
return e;
}

View File

@@ -91,7 +91,16 @@ BE UNTIL AT LEAST TWO YEARS AFTER THE PHASE 0 MAINNET LAUNCH.
console.log(`Initiating voluntary exit for validator ${publicKey}`);
const secretKey = await validatorDirManager.decryptValidator(publicKey, {force});
let secretKey;
try {
secretKey = await validatorDirManager.decryptValidator(publicKey, {force});
} catch (e) {
if ((e as Error).message.indexOf("EEXIST") !== -1) {
console.log(`Decrypting keystore failed with error ${e}. use --force to override`);
}
throw e;
}
console.log(`Decrypted keystore for validator ${publicKey}`);
const validatorPaths = getValidatorPaths(args);

View File

@@ -4,15 +4,13 @@ import bls, {SecretKey} from "@chainsafe/bls";
import {Keystore} from "@chainsafe/bls-keystore";
import {phase0} from "@chainsafe/lodestar-types";
import {lockFilepath, unlockFilepath} from "@chainsafe/lodestar-keymanager-server";
import {YargsError, readValidatorPassphrase} from "../util";
import {YargsError, readValidatorPassphrase, add0xPrefix} from "../util";
import {decodeEth1TxData} from "../depositContract/depositData";
import {add0xPrefix} from "../util/format";
import {
VOTING_KEYSTORE_FILE,
WITHDRAWAL_KEYSTORE_FILE,
ETH1_DEPOSIT_DATA_FILE,
ETH1_DEPOSIT_AMOUNT_FILE,
ETH1_DEPOSIT_TX_HASH_FILE,
} from "./paths";
export interface IValidatorDirOptions {
@@ -116,28 +114,6 @@ export class ValidatorDir {
return bls.SecretKey.fromBytes(privKey);
}
/**
* Indicates if there is a file containing an eth1 deposit transaction. This can be used to
* check if a deposit transaction has been created.
*
* *Note*: It's possible to submit an Eth1 deposit without creating this file, so use caution
* when relying upon this value.
*/
eth1DepositTxHashExists(): boolean {
return fs.existsSync(path.join(this.dirpath, ETH1_DEPOSIT_TX_HASH_FILE));
}
/**
* Saves the `tx_hash` to a file in `this.dir`.
*/
saveEth1DepositTxHash(txHash: string): void {
const filepath = path.join(this.dirpath, ETH1_DEPOSIT_TX_HASH_FILE);
if (fs.existsSync(filepath)) throw new YargsError(`ETH1_DEPOSIT_TX_HASH_FILE ${filepath} already exists`);
fs.writeFileSync(filepath, txHash);
}
/**
* Attempts to read files in `this.dir` and return an `Eth1DepositData` that can be used for
* submitting an Eth1 deposit.

View File

@@ -48,3 +48,11 @@ export class TimeoutError extends Error {
export function isErrorAborted(e: unknown): e is ErrorAborted {
return e instanceof ErrorAborted;
}
/**
* Extend an existing error by appending a string to its `e.message`
*/
export function extendError(e: Error, appendMessage: string): Error {
e.message = `${e.message} - ${appendMessage}`;
return e;
}

View File

@@ -1,9 +1,9 @@
import {AbortSignal} from "@chainsafe/abort-controller";
import {phase0, Slot, ssz} from "@chainsafe/lodestar-types";
import {computeEpochAtSlot} from "@chainsafe/lodestar-beacon-state-transition";
import {sleep} from "@chainsafe/lodestar-utils";
import {extendError, sleep} from "@chainsafe/lodestar-utils";
import {Api} from "@chainsafe/lodestar-api";
import {extendError, IClock, ILoggerVc} from "../util";
import {IClock, ILoggerVc} from "../util";
import {ValidatorStore} from "./validatorStore";
import {AttestationDutiesService, AttDutyAndProof} from "./attestationDuties";
import {groupAttDutiesByCommitteeIndex} from "./utils";

View File

@@ -1,11 +1,11 @@
import {SLOTS_PER_EPOCH} from "@chainsafe/lodestar-params";
import {sleep} from "@chainsafe/lodestar-utils";
import {extendError, sleep} from "@chainsafe/lodestar-utils";
import {computeEpochAtSlot, isAggregatorFromCommitteeLength} from "@chainsafe/lodestar-beacon-state-transition";
import {BLSSignature, Epoch, Slot, ValidatorIndex, RootHex} from "@chainsafe/lodestar-types";
import {Api, routes} from "@chainsafe/lodestar-api";
import {toHexString} from "@chainsafe/ssz";
import {IndicesService} from "./indices";
import {IClock, extendError, ILoggerVc} from "../util";
import {IClock, ILoggerVc} from "../util";
import {ValidatorStore} from "./validatorStore";
import {ChainHeaderTracker, HeadEventData} from "./chainHeaderTracker";
import {PubkeyHex} from "../types";

View File

@@ -1,10 +1,10 @@
import {BLSPubkey, Slot} from "@chainsafe/lodestar-types";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ForkName} from "@chainsafe/lodestar-params";
import {prettyBytes} from "@chainsafe/lodestar-utils";
import {extendError, prettyBytes} from "@chainsafe/lodestar-utils";
import {toHexString} from "@chainsafe/ssz";
import {Api} from "@chainsafe/lodestar-api";
import {IClock, extendError, ILoggerVc} from "../util";
import {IClock, ILoggerVc} from "../util";
import {ValidatorStore} from "./validatorStore";
import {BlockDutiesService, GENESIS_SLOT} from "./blockDuties";
import {PubkeyHex} from "../types";

View File

@@ -2,7 +2,8 @@ import {computeEpochAtSlot} from "@chainsafe/lodestar-beacon-state-transition";
import {BLSPubkey, Epoch, Root, Slot, ssz} from "@chainsafe/lodestar-types";
import {toHexString} from "@chainsafe/ssz";
import {Api, routes} from "@chainsafe/lodestar-api";
import {IClock, extendError, differenceHex, ILoggerVc} from "../util";
import {extendError} from "@chainsafe/lodestar-utils";
import {IClock, differenceHex, ILoggerVc} from "../util";
import {ValidatorStore} from "./validatorStore";
import {PubkeyHex} from "../types";
import {Metrics} from "../metrics";

View File

@@ -1,10 +1,10 @@
import {AbortSignal} from "@chainsafe/abort-controller";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {Slot, CommitteeIndex, altair, Root} from "@chainsafe/lodestar-types";
import {sleep} from "@chainsafe/lodestar-utils";
import {extendError, sleep} from "@chainsafe/lodestar-utils";
import {computeEpochAtSlot} from "@chainsafe/lodestar-beacon-state-transition";
import {Api} from "@chainsafe/lodestar-api";
import {IClock, extendError, ILoggerVc} from "../util";
import {IClock, ILoggerVc} from "../util";
import {ValidatorStore} from "./validatorStore";
import {SyncCommitteeDutiesService, SyncDutyAndProofs} from "./syncCommitteeDuties";
import {groupSyncDutiesBySubcommitteeIndex, SubcommitteeDuty} from "./utils";

View File

@@ -8,8 +8,9 @@ import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {BLSSignature, Epoch, Root, Slot, SyncPeriod, ValidatorIndex} from "@chainsafe/lodestar-types";
import {toHexString} from "@chainsafe/ssz";
import {Api, routes} from "@chainsafe/lodestar-api";
import {extendError} from "@chainsafe/lodestar-utils";
import {IndicesService} from "./indices";
import {IClock, extendError, ILoggerVc} from "../util";
import {IClock, ILoggerVc} from "../util";
import {ValidatorStore} from "./validatorStore";
import {PubkeyHex} from "../types";
import {Metrics} from "../metrics";

View File

@@ -1,7 +0,0 @@
/**
* Extend an existing error by appending a string to its `e.message`
*/
export function extendError(e: Error, prependMessage: string): Error {
e.message = `${prependMessage} - ${e.message}`;
return e;
}

View File

@@ -1,6 +1,5 @@
export * from "./clock";
export * from "./difference";
export * from "./error";
export * from "./logger";
export * from "./params";
export * from "./url";