From ce54e327824832da537e473fb5098b224fd5d5d4 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 29 Sep 2023 16:02:41 +0200 Subject: [PATCH] fix: run sync notifier once every slot pre-genesis (#6002) --- packages/beacon-node/src/node/notifier.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/src/node/notifier.ts b/packages/beacon-node/src/node/notifier.ts index ae68d66834da..33ff1d185bb1 100644 --- a/packages/beacon-node/src/node/notifier.ts +++ b/packages/beacon-node/src/node/notifier.ts @@ -148,7 +148,12 @@ function timeToNextHalfSlot(config: BeaconConfig, chain: IBeaconChain, isFirstTi const msPerSlot = config.SECONDS_PER_SLOT * 1000; const msPerHalfSlot = msPerSlot / 2; const msFromGenesis = Date.now() - chain.genesisTime * 1000; - const msToNextSlot = msPerSlot - (msFromGenesis % msPerSlot); + const msToNextSlot = + msFromGenesis < 0 + ? // For future genesis time, calculate time left in the slot + -msFromGenesis % msPerSlot + : // For past genesis time, calculate time until the next slot + msPerSlot - (msFromGenesis % msPerSlot); if (isFirstTime) { // at the 1st time we may miss middle of the current clock slot return msToNextSlot > msPerHalfSlot ? msToNextSlot - msPerHalfSlot : msToNextSlot + msPerHalfSlot;