Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistNetworkIdentity cli option #5175

Merged
merged 4 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/cli/src/cmds/beacon/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {ACTIVE_PRESET, PresetName} from "@lodestar/params";
import {ProcessShutdownCallback} from "@lodestar/validator";

import {GlobalArgs, parseBeaconNodeArgs} from "../../options/index.js";
import {BeaconNodeOptions, exportToJSON, getBeaconConfigFromArgs} from "../../config/index.js";
import {BeaconNodeOptions, exportToJSON, getBeaconConfigFromArgs, readPeerId} from "../../config/index.js";
import {getNetworkBootnodes, getNetworkData, isKnownNetworkName, readBootnodes} from "../../networks/index.js";
import {onGracefulShutdown, getCliLogger, mkdir, writeFile600Perm, cleanOldLogFiles} from "../../util/index.js";
import {getVersionData} from "../../util/version.js";
Expand Down Expand Up @@ -42,10 +42,6 @@ export async function beaconHandler(args: BeaconArgs & GlobalArgs): Promise<void
logger.debug("Not able to delete log files", logParams, e as Error);
}

onGracefulShutdown(async () => {
abortController.abort();
}, logger.info.bind(logger));

logger.info("Lodestar", {network, version, commit});
// Callback for beacon to request forced exit, for e.g. in case of irrecoverable
// forkchoice errors
Expand Down Expand Up @@ -97,6 +93,15 @@ export async function beaconHandler(args: BeaconArgs & GlobalArgs): Promise<void

if (args.attachToGlobalThis) ((globalThis as unknown) as {bn: BeaconNode}).bn = node;

onGracefulShutdown(async () => {
const enr = await node.network.getEnr();
if (args.peerIdFile && enr) {
const enrPath = path.join(beaconPaths.beaconDir, "enr");
writeFile600Perm(enrPath, enr.encodeTxt());
}
abortController.abort();
}, logger.info.bind(logger));

abortController.signal.addEventListener("abort", () => node.close(), {once: true});
} catch (e) {
await db.stop();
Expand Down Expand Up @@ -140,7 +145,7 @@ export async function beaconHandlerInit(args: BeaconArgs & GlobalArgs) {
}

// Create new PeerId everytime by default, unless peerIdFile is provided
const peerId = await createSecp256k1PeerId();
const peerId = args.peerIdFile ? await readPeerId(args.peerIdFile) : await createSecp256k1PeerId();
const enr = SignableENR.createV4(createKeypairFromPeerId(peerId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need something like:

// If peerIdFile
//   attempt to read enr from disk, beaconDir/enr
//   accept enr if enr.peerId == peerId
// else
//    create new enr

Otherwise, when using peerIdFile, then restarting, the discv5 network will ignore our enr updates since the enr seqno has been reset.

overwriteEnrWithCliArgs(enr, args);

Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/options/globalOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {paramsOptions, IParamsArgs} from "./paramsOptions.js";
type GlobalSingleArgs = {
dataDir?: string;
network?: NetworkName;
peerIdFile?: string;
paramsFile: string;
preset: string;
};
Expand All @@ -25,6 +26,11 @@ const globalSingleOptions: CliCommandOptions<GlobalSingleArgs> = {
choices: networkNames,
},

peerIdFile: {
description: "Peer id file path",
type: "string",
},

paramsFile: {
description: "Network configuration file",
type: "string",
Expand Down