mirror of https://github.com/waku-org/nwaku.git
Revert epochs to float64
This commit is contained in:
parent
a3a0a09cca
commit
40a40fa63b
|
@ -406,11 +406,10 @@ proc fromEpoch*(epoch: Epoch): uint64 =
|
||||||
let t = fromBytesLE(uint64, array[32,byte](epoch))
|
let t = fromBytesLE(uint64, array[32,byte](epoch))
|
||||||
return t
|
return t
|
||||||
|
|
||||||
proc calcEpoch*(t: int64): Epoch =
|
proc calcEpoch*(t: float64): Epoch =
|
||||||
## gets time `t` as `int64` with milliseconds resolution
|
## gets time `t` as `flaot64` with subseconds resolution in the fractional part
|
||||||
## and returns its corresponding rln `Epoch` value
|
## and returns its corresponding rln `Epoch` value
|
||||||
## TODO: check the uint64 cast doesn't induce overflows
|
let e = uint64(t/EPOCH_UNIT_SECONDS)
|
||||||
let e = uint64(t/(EPOCH_UNIT_SECONDS*1000))
|
|
||||||
return toEpoch(e)
|
return toEpoch(e)
|
||||||
|
|
||||||
proc getCurrentEpoch*(): Epoch =
|
proc getCurrentEpoch*(): Epoch =
|
||||||
|
@ -428,7 +427,7 @@ proc compare*(e1, e2: Epoch): int64 =
|
||||||
return int64(epoch1) - int64(epoch2)
|
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.,
|
## 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`'s epoch is within MAX_EPOCH_GAP of the current epoch
|
||||||
## the `msg` has valid rate limit proof
|
## the `msg` has valid rate limit proof
|
||||||
|
@ -474,10 +473,10 @@ proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption: Optio
|
||||||
return MessageValidationResult.Valid
|
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 true if it can create and append a `RateLimitProof` to the supplied `msg`
|
||||||
## returns false otherwise
|
## 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()`)
|
## The `epoch` field of `RateLimitProof` is derived from the provided `senderEpochTime` (using `calcEpoch()`)
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
Loading…
Reference in New Issue