diff --git a/tests/v2/test_waku_rln_relay.nim b/tests/v2/test_waku_rln_relay.nim index 3cda5878b..57d4f9c7f 100644 --- a/tests/v2/test_waku_rln_relay.nim +++ b/tests/v2/test_waku_rln_relay.nim @@ -820,7 +820,7 @@ suite "Waku rln relay": debug "encoded and decode time", epoch = epoch, epochBytes = epochBytes, decodedEpoch = decodedEpoch - test "Epoch comparison": + test "Epoch comparison, epoch1 > epoch2": # check edge cases let time1 = uint64.high @@ -828,8 +828,8 @@ suite "Waku rln relay": epoch1 = time1.toEpoch() epoch2 = time2.toEpoch() check: - diff(epoch1, epoch2) == int64(1) - diff(epoch2, epoch1) == int64(-1) + absDiff(epoch1, epoch2) == uint64(1) + absDiff(epoch2, epoch1) == uint64(1) test "updateLog and hasDuplicate tests": let diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index 5ec0c6014..a8c178a37 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # Generated automatically by config.status (libbacktrace) version-unused -# Libtool was configured on host fv-az96-850: +# Libtool was configured on host fv-az290-341: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_constants.nim b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_constants.nim index 3d02b4e94..3f9422b3a 100644 --- a/waku/v2/protocol/waku_rln_relay/waku_rln_relay_constants.nim +++ b/waku/v2/protocol/waku_rln_relay/waku_rln_relay_constants.nim @@ -458,4 +458,4 @@ const EpochUnitSeconds* = float64(10) # the rln-relay epoch length in seconds const MaxClockGapSeconds* = 20.0 # the maximum clock difference between peers in seconds # maximum allowed gap between the epochs of messages' RateLimitProofs -const MaxEpochGap* = int64(MaxClockGapSeconds/EpochUnitSeconds) \ No newline at end of file +const MaxEpochGap* = uint64(MaxClockGapSeconds/EpochUnitSeconds) \ No newline at end of file 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 d07940d60..96dc4a890 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 @@ -1,7 +1,7 @@ {.push raises: [Defect].} import - std/[sequtils, tables, times, streams, os, deques], + std/[sequtils, tables, times, os, deques], chronicles, options, chronos, stint, confutils, web3, json, @@ -785,15 +785,21 @@ proc getCurrentEpoch*(): Epoch = ## gets the current rln Epoch time return calcEpoch(epochTime()) -proc diff*(e1, e2: Epoch): int64 = - ## returns the difference between the two rln `Epoch`s `e1` and `e2` +proc absDiff*(e1, e2: Epoch): uint64 = + ## returns the absolute difference between the two rln `Epoch`s `e1` and `e2` ## i.e., e1 - e2 # convert epochs to their corresponding unsigned numerical values let epoch1 = fromEpoch(e1) epoch2 = fromEpoch(e2) - return int64(epoch1) - int64(epoch2) + + # Manually perform an `abs` calculation + if epoch1 > epoch2: + return epoch1 - epoch2 + else: + return epoch2 - epoch1 + proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption: Option[float64] = none(float64)): MessageValidationResult = @@ -820,12 +826,12 @@ proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, let msgEpoch = msg.proof.epoch # calculate the gaps - gap = diff(epoch, msgEpoch) + gap = absDiff(epoch, msgEpoch) debug "message epoch", msgEpoch = fromEpoch(msgEpoch) # validate the epoch - if abs(gap) > MaxEpochGap: + if gap > MaxEpochGap: # message's epoch is too old or too ahead # accept messages whose epoch is within +-MaxEpochGap from the current epoch debug "invalid message: epoch gap exceeds a threshold", gap = gap,