Skip to content

Commit

Permalink
fix: run sync notifier once every slot pre-genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Sep 26, 2023
1 parent e9d57cd commit ab2e1ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/beacon-node/src/node/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ab2e1ff

Please sign in to comment.