Revert epochs to float64

This commit is contained in:
s1fr0 2022-02-03 20:31:39 +01:00
parent a3a0a09cca
commit 40a40fa63b
1 changed files with 6 additions and 7 deletions

View File

@ -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