Skip to content

Commit

Permalink
Fix the validator abort error
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jul 13, 2023
1 parent 3921c2f commit 68c5e2e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 53 deletions.
106 changes: 55 additions & 51 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MonitoringService,
} from "@lodestar/beacon-node";
import {getNodeLogger} from "@lodestar/logger/node";
import {isErrorAborted} from "@lodestar/utils";
import {getBeaconConfigFromArgs} from "../../config/index.js";
import {GlobalArgs} from "../../options/index.js";
import {YargsError, cleanOldLogFiles, getDefaultGraffiti, mkdir, parseLoggerArgs} from "../../util/index.js";
Expand Down Expand Up @@ -150,60 +151,63 @@ export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Pr

// This promise resolves once genesis is available.
// It will wait for genesis, so this promise can be potentially very long

const validator = await Validator.initializeFromBeaconNode(
{
db,
config,
slashingProtection,
api: args.beaconNodes,
logger,
processShutdownCallback,
signers,
abortController,
doppelgangerProtection,
afterBlockDelaySlotFraction: args.afterBlockDelaySlotFraction,
scAfterBlockDelaySlotFraction: args.scAfterBlockDelaySlotFraction,
disableAttestationGrouping: args.disableAttestationGrouping,
valProposerConfig,
distributed: args.distributed,
},
metrics
);

onGracefulShutdownCbs.push(() => validator.close());

// Start keymanager API backend
// Only if keymanagerEnabled flag is set to true
if (args["keymanager"]) {
// if proposerSettingsFile provided disable the key proposerConfigWrite in keymanager
const proposerConfigWriteDisabled = args.proposerSettingsFile !== undefined;
if (proposerConfigWriteDisabled) {
logger.warn(
"Proposer data updates (feeRecipient/gasLimit etc) will not be available via Keymanager API as proposerSettingsFile has been set"
);
}

const keymanagerApi = new KeymanagerApi(
validator,
persistedKeysBackend,
abortController.signal,
proposerConfigWriteDisabled
);
const keymanagerServer = new KeymanagerRestApiServer(
// During the wait time user can abort the process with Ctrl+C
// So we have to wrap this code with the try/catch
try {
const validator = await Validator.initializeFromBeaconNode(
{
address: args["keymanager.address"],
port: args["keymanager.port"],
cors: args["keymanager.cors"],
isAuthEnabled: args["keymanager.authEnabled"],
headerLimit: args["keymanager.headerLimit"],
bodyLimit: args["keymanager.bodyLimit"],
tokenDir: dbPath,
db,
config,
slashingProtection,
api: args.beaconNodes,
logger,
processShutdownCallback,
signers,
abortController,
doppelgangerProtection,
afterBlockDelaySlotFraction: args.afterBlockDelaySlotFraction,
scAfterBlockDelaySlotFraction: args.scAfterBlockDelaySlotFraction,
disableAttestationGrouping: args.disableAttestationGrouping,
valProposerConfig,
distributed: args.distributed,
},
{config, logger, api: keymanagerApi, metrics: metrics ? metrics.keymanagerApiRest : null}
metrics
);
onGracefulShutdownCbs.push(() => keymanagerServer.close());
await keymanagerServer.listen();
onGracefulShutdownCbs.push(() => validator.close());
// Start keymanager API backend
// Only if keymanagerEnabled flag is set to true
if (args["keymanager"]) {
// if proposerSettingsFile provided disable the key proposerConfigWrite in keymanager
const proposerConfigWriteDisabled = args.proposerSettingsFile !== undefined;
if (proposerConfigWriteDisabled) {
logger.warn(
"Proposer data updates (feeRecipient/gasLimit etc) will not be available via Keymanager API as proposerSettingsFile has been set"
);
}

const keymanagerApi = new KeymanagerApi(
validator,
persistedKeysBackend,
abortController.signal,
proposerConfigWriteDisabled
);
const keymanagerServer = new KeymanagerRestApiServer(
{
address: args["keymanager.address"],
port: args["keymanager.port"],
cors: args["keymanager.cors"],
isAuthEnabled: args["keymanager.authEnabled"],
headerLimit: args["keymanager.headerLimit"],
bodyLimit: args["keymanager.bodyLimit"],
tokenDir: dbPath,
},
{config, logger, api: keymanagerApi, metrics: metrics ? metrics.keymanagerApiRest : null}
);
onGracefulShutdownCbs.push(() => keymanagerServer.close());
await keymanagerServer.listen();
}
} catch (err) {
if (!isErrorAborted(err)) throw err;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cmds/validator/signers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function getSignersFromArgs(
const needle = showProgress({
total: keystoreDefinitions.length,
frequencyMs: KEYSTORE_IMPORT_PROGRESS_MS,
signal: signal,
signal,
progress: ({ratePerSec, percentage, current, total}) => {
logger.info(
`${percentage.toFixed(0)}% of keystores imported. current=${current} total=${total} rate=${(
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function getSignersFromArgs(
const needle = showProgress({
total: keystoreDefinitions.length,
frequencyMs: KEYSTORE_IMPORT_PROGRESS_MS,
signal: signal,
signal,
progress: ({ratePerSec, percentage, current, total}) => {
logger.info(
`${percentage.toFixed(0)}% of local keystores imported. current=${current} total=${total} rate=${(
Expand Down

0 comments on commit 68c5e2e

Please sign in to comment.