Skip to content

Commit

Permalink
chore: always return future time
Browse files Browse the repository at this point in the history
  • Loading branch information
darshankabariya committed Jan 6, 2025
1 parent 7b5040e commit 71d7e9e
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions waku/waku_rln_relay/rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,16 @@ proc calcEpoch*(rlnPeer: WakuRLNRelay, t: float64): Epoch =
return toEpoch(e)

proc nextEpoch*(rlnPeer: WakuRLNRelay, t: float64): float64 =
let currentEpoch = rlnPeer.calcEpoch(t)
var timePtr = t

# Increment by minutes until the epoch changes
while rlnPeer.calcEpoch(timePtr) == currentEpoch:
timePtr += 60 # 1 minute

# Backtrack to the last minute of the current epoch
timePtr -= 60

# Increment by seconds to find the exact transition
while rlnPeer.calcEpoch(timePtr) == currentEpoch:
timePtr += 1 # 1 second
let
currentEpoch = uint64(t / rlnPeer.rlnEpochSizeSec.float64)
nextEpochTime = float64(currentEpoch + 1) * rlnPeer.rlnEpochSizeSec.float64
currentTime = epochTime()

# Ensure the returned time is in the future
if timePtr > epochTime():
return timePtr
# Ensure we always return a future time
if nextEpochTime > currentTime:
return nextEpochTime
else:
return epochTime()
return currentTime

proc stop*(rlnPeer: WakuRLNRelay) {.async: (raises: [Exception]).} =
## stops the rln-relay protocol
Expand Down

0 comments on commit 71d7e9e

Please sign in to comment.