From 96fe621fae89c0c7bcc620db2ebc08510185ef22 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 24 Jul 2023 19:54:19 +0700 Subject: [PATCH] chore: refactor function name msToNextEpoch --- packages/beacon-node/src/api/impl/validator/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 3b9fa0332419..d988af66a691 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -119,8 +119,8 @@ export function getValidatorApi({ * Prevents a validator from not being able to get the attestater duties correctly if the beacon and validator clocks are off */ async function waitForNextClosestEpoch(): Promise { - const msToNextEpoch = timeToNextEpochInMs(); - if (msToNextEpoch > 0 && msToNextEpoch < MAX_API_CLOCK_DISPARITY_MS) { + const toNextEpochMs = msToNextEpoch(); + if (toNextEpochMs > 0 && toNextEpochMs < MAX_API_CLOCK_DISPARITY_MS) { const nextEpoch = chain.clock.currentEpoch + 1; await chain.clock.waitForSlot(computeStartSlotAtEpoch(nextEpoch)); } @@ -129,7 +129,7 @@ export function getValidatorApi({ /** * Compute ms to the next epoch. */ - function timeToNextEpochInMs(): number { + function msToNextEpoch(): number { const nextEpoch = chain.clock.currentEpoch + 1; const secPerEpoch = SLOTS_PER_EPOCH * config.SECONDS_PER_SLOT; const nextEpochStartSec = chain.genesisTime + nextEpoch * secPerEpoch; @@ -405,9 +405,10 @@ export function getValidatorApi({ let state: CachedBeaconStateAllForks | undefined = undefined; const prepareNextSlotLookAheadMs = (config.SECONDS_PER_SLOT * 1000) / SCHEDULER_LOOKAHEAD_FACTOR; const cpState = chain.regen.getCheckpointStateSync({rootHex: head.blockRoot, epoch}); + const toNextEpochMs = msToNextEpoch(); // validators may request next epoch's duties when it's close to next epoch // return that asap if PrepareNextSlot already compute beacon proposers for next epoch - if (epoch === nextEpoch && timeToNextEpochInMs() < prepareNextSlotLookAheadMs) { + if (epoch === nextEpoch && toNextEpochMs < prepareNextSlotLookAheadMs) { if (cpState) { state = cpState; metrics?.duties.requestNextEpochProposalDutiesHit.inc();