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

vc: configure afterBlockDelaySlotFraction for Attestation and SyncCommitteeSignature #4626

Merged
merged 3 commits into from
Oct 5, 2022
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
1 change: 1 addition & 0 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export async function validatorHandler(args: IValidatorCliArgs & IGlobalArgs): P
abortController,
doppelgangerProtectionEnabled,
afterBlockDelaySlotFraction: args.afterBlockDelaySlotFraction,
scAfterBlockDelaySlotFraction: args.scAfterBlockDelaySlotFraction,
valProposerConfig,
},
metrics
Expand Down
11 changes: 10 additions & 1 deletion packages/cli/src/cmds/validator/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type IValidatorCliArgs = AccountValidatorArgs &
force: boolean;
graffiti: string;
afterBlockDelaySlotFraction?: number;
scAfterBlockDelaySlotFraction?: number;
suggestedFeeRecipient?: string;
proposerSettingsFile?: string;
strictFeeRecipientCheck?: boolean;
Expand Down Expand Up @@ -153,7 +154,15 @@ export const validatorOptions: ICliCommandOptions<IValidatorCliArgs> = {

afterBlockDelaySlotFraction: {
hidden: true,
description: "Delay before publishing attestations if block comes early, as a fraction of SECONDS_PER_SLOT",
description:
"Delay before publishing attestations if block comes early, as a fraction of SECONDS_PER_SLOT (value is from 0 inclusive to 1 exclusive)",
type: "number",
},

scAfterBlockDelaySlotFraction: {
hidden: true,
description:
"Delay before publishing SyncCommitteeSignature if block comes early, as a fraction of SECONDS_PER_SLOT (value is from 0 inclusive to 1 exclusive)",
type: "number",
},

Expand Down
4 changes: 2 additions & 2 deletions packages/validator/src/services/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class AttestationService {
// never beyond the 1/3 cutoff time.
// https://github.com/status-im/nimbus-eth2/blob/7b64c1dce4392731a4a59ee3a36caef2e0a8357a/beacon_chain/validators/validator_duties.nim#L1123
const msToOneThirdSlot = this.clock.msToSlot(slot + 1 / 3);
// Default = 6, which is half of attestation offset
const afterBlockDelayMs = (1000 * this.clock.secondsPerSlot) / (this.opts?.afterBlockDelaySlotFraction ?? 6);
// Default = 1/6, which is half of attestation offset
const afterBlockDelayMs = 1000 * this.clock.secondsPerSlot * (this.opts?.afterBlockDelaySlotFraction ?? 1 / 6);
await sleep(Math.min(msToOneThirdSlot, afterBlockDelayMs));

this.metrics?.attesterStepCallPublishAttestation.observe(this.clock.secFromSlot(slot + 1 / 3));
Expand Down
17 changes: 16 additions & 1 deletion packages/validator/src/services/syncCommittee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {groupSyncDutiesBySubcommitteeIndex, SubcommitteeDuty} from "./utils.js";
import {ChainHeaderTracker} from "./chainHeaderTracker.js";
import {ValidatorEventEmitter} from "./emitter.js";

type SyncCommitteeServiceOpts = {
scAfterBlockDelaySlotFraction?: number;
};

/**
* Service that sets up and handles validator sync duties.
*/
Expand All @@ -26,7 +30,8 @@ export class SyncCommitteeService {
private readonly validatorStore: ValidatorStore,
private readonly emitter: ValidatorEventEmitter,
private readonly chainHeaderTracker: ChainHeaderTracker,
private readonly metrics: Metrics | null
private readonly metrics: Metrics | null,
private readonly opts?: SyncCommitteeServiceOpts
) {
this.dutiesService = new SyncCommitteeDutiesService(config, logger, api, clock, validatorStore, metrics);

Expand Down Expand Up @@ -126,6 +131,16 @@ export class SyncCommitteeService {
})
);

// by default we want to submit SyncCommitteeSignature asap after we receive block
// provide a delay option just in case any client implementation validate the existence of block in
// SyncCommitteeSignature gossip validation.
const msToOneThirdSlot = this.clock.msToSlot(slot + 1 / 3);
const afterBlockDelayMs = 1000 * this.clock.secondsPerSlot * (this.opts?.scAfterBlockDelaySlotFraction ?? 0);
const toDelayMs = Math.min(msToOneThirdSlot, afterBlockDelayMs);
if (toDelayMs > 0) {
await sleep(toDelayMs);
}

this.metrics?.syncCommitteeStepCallPublishMessage.observe(this.clock.secFromSlot(slot + 1 / 3));

if (signatures.length > 0) {
Expand Down
4 changes: 3 additions & 1 deletion packages/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type ValidatorOptions = {
processShutdownCallback: ProcessShutdownCallback;
abortController: AbortController;
afterBlockDelaySlotFraction?: number;
scAfterBlockDelaySlotFraction?: number;
doppelgangerProtectionEnabled?: boolean;
closed?: boolean;
valProposerConfig?: ValidatorProposerConfig;
Expand Down Expand Up @@ -129,7 +130,8 @@ export class Validator {
validatorStore,
emitter,
chainHeaderTracker,
metrics
metrics,
{scAfterBlockDelaySlotFraction: opts.scAfterBlockDelaySlotFraction}
);

this.config = config;
Expand Down