diff --git a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim index 41bdc7774..cd842ad49 100644 --- a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim +++ b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim @@ -406,11 +406,10 @@ proc fromEpoch*(epoch: Epoch): uint64 = let t = fromBytesLE(uint64, array[32,byte](epoch)) return t -proc calcEpoch*(t: int64): Epoch = - ## gets time `t` as `int64` with milliseconds resolution +proc calcEpoch*(t: float64): Epoch = + ## gets time `t` as `flaot64` with subseconds resolution in the fractional part ## and returns its corresponding rln `Epoch` value - ## TODO: check the uint64 cast doesn't induce overflows - let e = uint64(t/(EPOCH_UNIT_SECONDS*1000)) + let e = uint64(t/EPOCH_UNIT_SECONDS) return toEpoch(e) proc getCurrentEpoch*(): Epoch = @@ -428,7 +427,7 @@ proc compare*(e1, e2: Epoch): int64 = return int64(epoch1) - int64(epoch2) -proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption: Option[int64] = none(int64)): MessageValidationResult = +proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption: Option[float64] = none(float64)): MessageValidationResult = ## validate the supplied `msg` based on the waku-rln-relay routing protocol i.e., ## the `msg`'s epoch is within MAX_EPOCH_GAP of the current epoch ## the `msg` has valid rate limit proof @@ -474,10 +473,10 @@ proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption: Optio return MessageValidationResult.Valid -proc appendRLNProof*(rlnPeer: WakuRLNRelay, msg: var WakuMessage, senderEpochTime: int64): bool = +proc appendRLNProof*(rlnPeer: WakuRLNRelay, msg: var WakuMessage, senderEpochTime: float64): bool = ## returns true if it can create and append a `RateLimitProof` to the supplied `msg` ## returns false otherwise - ## `senderEpochTime` indicates the number of milliseconds passed since Unix epoch. + ## `senderEpochTime` indicates the number of seconds passed since Unix epoch. The fractional part holds sub-seconds. ## The `epoch` field of `RateLimitProof` is derived from the provided `senderEpochTime` (using `calcEpoch()`) let