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

refactor: rename CLI flag to enable doppelganger protection #5676

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 14 additions & 14 deletions packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe.skip("doppelganger / doppelganger test", function () {

type TestConfig = {
genesisTime?: number;
doppelgangerProtectionEnabled?: boolean;
doppelgangerProtection?: boolean;
};

async function createBNAndVC(config?: TestConfig): Promise<{beaconNode: BeaconNode; validators: Validator[]}> {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe.skip("doppelganger / doppelganger test", function () {
startIndex: 0,
useRestApi: false,
testLoggerOpts,
doppelgangerProtectionEnabled: config?.doppelgangerProtectionEnabled,
doppelgangerProtection: config?.doppelgangerProtection,
});
afterEachCallbacks.push(() => Promise.all(validatorsWithDoppelganger.map((v) => v.close())));

Expand All @@ -83,7 +83,7 @@ describe.skip("doppelganger / doppelganger test", function () {
const validatorIndex = 0;

const {beaconNode: bn, validators: validatorsWithDoppelganger} = await createBNAndVC({
doppelgangerProtectionEnabled: true,
doppelgangerProtection: true,
});

const validatorUnderTest = validatorsWithDoppelganger[0];
Expand Down Expand Up @@ -118,7 +118,7 @@ describe.skip("doppelganger / doppelganger test", function () {

const {beaconNode: bn, validators: validatorsWithDoppelganger} = await createBNAndVC({
genesisTime,
doppelgangerProtectionEnabled: true,
doppelgangerProtection: true,
});

const {beaconNode: bn2, validators: validators} = await createBNAndVC({
Expand Down Expand Up @@ -148,15 +148,15 @@ describe.skip("doppelganger / doppelganger test", function () {
it("should shut down validator if same key is active with same BN and started after genesis", async function () {
this.timeout("10 min");

const doppelgangerProtectionEnabled = true;
const doppelgangerProtection = true;
const testLoggerOpts: TestLoggerOpts = {level: LogLevel.info};

// set genesis time to allow at least an epoch
const genesisTime = Math.floor(Date.now() / 1000) - SLOTS_PER_EPOCH * beaconParams.SECONDS_PER_SLOT;

const {beaconNode: bn, validators: validator0WithDoppelganger} = await createBNAndVC({
genesisTime,
doppelgangerProtectionEnabled,
doppelgangerProtection,
});

const {validators: validator0WithoutDoppelganger} = await getAndInitDevValidators({
Expand All @@ -166,7 +166,7 @@ describe.skip("doppelganger / doppelganger test", function () {
startIndex: 0,
useRestApi: false,
testLoggerOpts,
doppelgangerProtectionEnabled: false,
doppelgangerProtection: false,
});
afterEachCallbacks.push(() => Promise.all(validator0WithoutDoppelganger.map((v) => v.close())));

Expand Down Expand Up @@ -194,15 +194,15 @@ describe.skip("doppelganger / doppelganger test", function () {
it("should not shut down validator if key is different", async function () {
this.timeout("10 min");

const doppelgangerProtectionEnabled = true;
const doppelgangerProtection = true;

const {beaconNode: bn, validators: validatorsWithDoppelganger} = await createBNAndVC({
doppelgangerProtectionEnabled,
doppelgangerProtection,
});

const {beaconNode: bn2, validators: validators} = await createBNAndVC({
genesisTime: bn.chain.getHeadState().genesisTime,
doppelgangerProtectionEnabled: false,
doppelgangerProtection: false,
});

await connect(bn2.network, bn.network);
Expand All @@ -226,14 +226,14 @@ describe.skip("doppelganger / doppelganger test", function () {
it("should not sign block if doppelganger period has not passed and not started at genesis", async function () {
this.timeout("10 min");

const doppelgangerProtectionEnabled = true;
const doppelgangerProtection = true;

// set genesis time to allow at least an epoch
const genesisTime = Math.floor(Date.now() / 1000) - SLOTS_PER_EPOCH * beaconParams.SECONDS_PER_SLOT;

const {beaconNode: bn, validators: validatorsWithDoppelganger} = await createBNAndVC({
genesisTime,
doppelgangerProtectionEnabled,
doppelgangerProtection,
});

const validatorUnderTest = validatorsWithDoppelganger[0];
Expand All @@ -259,14 +259,14 @@ describe.skip("doppelganger / doppelganger test", function () {
it("should not sign attestations if doppelganger period has not passed and started after genesis", async function () {
this.timeout("10 min");

const doppelgangerProtectionEnabled = true;
const doppelgangerProtection = true;

// set genesis time to allow at least an epoch
const genesisTime = Math.floor(Date.now() / 1000) - SLOTS_PER_EPOCH * beaconParams.SECONDS_PER_SLOT;

const {beaconNode: bn, validators: validatorsWithDoppelganger} = await createBNAndVC({
genesisTime,
doppelgangerProtectionEnabled,
doppelgangerProtection,
});

const validatorUnderTest = validatorsWithDoppelganger[0];
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/test/utils/node/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function getAndInitDevValidators({
useRestApi,
testLoggerOpts,
externalSignerUrl,
doppelgangerProtectionEnabled = false,
doppelgangerProtection = false,
valProposerConfig,
}: {
node: BeaconNode;
Expand All @@ -26,7 +26,7 @@ export async function getAndInitDevValidators({
useRestApi?: boolean;
testLoggerOpts?: TestLoggerOpts;
externalSignerUrl?: string;
doppelgangerProtectionEnabled?: boolean;
doppelgangerProtection?: boolean;
valProposerConfig?: ValidatorProposerConfig;
}): Promise<{validators: Validator[]; secretKeys: SecretKey[]}> {
const validators: Promise<Validator>[] = [];
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function getAndInitDevValidators({
processShutdownCallback: () => {},
abortController,
signers,
doppelgangerProtectionEnabled,
doppelgangerProtection,
valProposerConfig,
})
);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {KeymanagerRestApiServer} from "./keymanager/server.js";
export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Promise<void> {
const {config, network} = getBeaconConfigFromArgs(args);

const doppelgangerProtectionEnabled = args.doppelgangerProtectionEnabled;
const {doppelgangerProtection} = args;

const validatorPaths = getValidatorPaths(args, network);
const accountPaths = getAccountPaths(args, network);
Expand Down Expand Up @@ -160,7 +160,7 @@ export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Pr
processShutdownCallback,
signers,
abortController,
doppelgangerProtectionEnabled,
doppelgangerProtection,
afterBlockDelaySlotFraction: args.afterBlockDelaySlotFraction,
scAfterBlockDelaySlotFraction: args.scAfterBlockDelaySlotFraction,
disableAttestationGrouping: args.disableAttestationGrouping,
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/cmds/validator/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type IValidatorCliArgs = AccountValidatorArgs &
suggestedFeeRecipient?: string;
proposerSettingsFile?: string;
strictFeeRecipientCheck?: boolean;
doppelgangerProtectionEnabled?: boolean;
doppelgangerProtection?: boolean;
defaultGasLimit?: number;

builder?: boolean;
Expand Down Expand Up @@ -256,7 +256,8 @@ export const validatorOptions: CliCommandOptions<IValidatorCliArgs> = {
type: "string",
},

doppelgangerProtectionEnabled: {
doppelgangerProtection: {
alias: ["doppelgangerProtectionEnabled"],
description: "Enables Doppelganger protection",
default: false,
type: "boolean",
Expand Down
4 changes: 2 additions & 2 deletions packages/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type ValidatorOptions = {
afterBlockDelaySlotFraction?: number;
scAfterBlockDelaySlotFraction?: number;
disableAttestationGrouping?: boolean;
doppelgangerProtectionEnabled?: boolean;
doppelgangerProtection?: boolean;
closed?: boolean;
valProposerConfig?: ValidatorProposerConfig;
distributed?: boolean;
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Validator {
}

const indicesService = new IndicesService(logger, api, metrics);
const doppelgangerService = opts.doppelgangerProtectionEnabled
const doppelgangerService = opts.doppelgangerProtection
? new DoppelgangerService(logger, clock, api, indicesService, opts.processShutdownCallback, metrics)
: null;

Expand Down