diff --git a/packages/beacon-node/src/node/notifier.ts b/packages/beacon-node/src/node/notifier.ts index ae68d66834da..5e9417b123ed 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 position in the future slot + -msFromGenesis % msPerSlot + : // For past genesis time, calculate time remaining 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;