Skip to content

Commit

Permalink
Merge 839f7bd into edb327d
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths authored Oct 5, 2022
2 parents edb327d + 839f7bd commit f3310bc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
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

0 comments on commit f3310bc

Please sign in to comment.