Skip to content

Commit

Permalink
fix: make rln rate limit spec compliant (#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Dec 15, 2023
1 parent 0fc617f commit 5847f49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions tests/waku_rln_relay/test_wakunode_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ procSuite "WakuNode - RLN relay":
await node3.stop()

asyncTest "clearNullifierLog: should clear epochs > MaxEpochGap":

let
# publisher node
nodeKey1 = generateSecp256k1Key()
Expand Down Expand Up @@ -445,7 +445,7 @@ procSuite "WakuNode - RLN relay":
proofAdded1 = node1.wakuRlnRelay.appendRLNProof(wm1, time)
# another message in the same epoch as wm1, it will break the messaging rate limit
wm2 = WakuMessage(payload: "message 2".toBytes(), contentTopic: contentTopic)
proofAdded2 = node1.wakuRlnRelay.appendRLNProof(wm2, time + EpochUnitSeconds)
proofAdded2 = node1.wakuRlnRelay.appendRLNProof(wm2, time)
# wm3 points to the next epoch
wm3 = WakuMessage(payload: "message 3".toBytes(), contentTopic: contentTopic)
proofAdded3 = node1.wakuRlnRelay.appendRLNProof(wm3, time + EpochUnitSeconds * 2)
Expand All @@ -455,7 +455,7 @@ procSuite "WakuNode - RLN relay":
proofAdded1
proofAdded2
proofAdded3

# relay handler for node2
var completionFut1 = newFuture[bool]()
var completionFut2 = newFuture[bool]()
Expand All @@ -469,25 +469,25 @@ procSuite "WakuNode - RLN relay":
completionFut2.complete(true)
if msg == wm3:
completionFut3.complete(true)

# mount the relay handler for node2
node2.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
await sleepAsync(2000.millis)

await node1.publish(some(DefaultPubsubTopic), wm1)
await sleepAsync(10.seconds)
await node1.publish(some(DefaultPubsubTopic), wm2)
await sleepAsync(10.seconds)
await node1.publish(some(DefaultPubsubTopic), wm3)

let
res1 = await completionFut1.withTimeout(10.seconds)
res2 = await completionFut2.withTimeout(10.seconds)
res3 = await completionFut3.withTimeout(10.seconds)

check:
(res1 and res2 and res3) == true # all 3 are valid
node2.wakuRlnRelay.nullifierLog.len() == 1 # after clearing, only 1 is stored
res1 == true
res2 == false
res3 == true
node2.wakuRlnRelay.nullifierLog.len() == 2

await node1.stop()
await node2.stop()
2 changes: 1 addition & 1 deletion waku/waku_rln_relay/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const
# the root is created locally, using createMembershipList proc from waku_rln_relay_utils module, and the result is hardcoded in here
StaticGroupMerkleRoot* = "1e534adab58f7d300aaeecae57a25e0a0b18c368a09f720280da92b288950901"

const EpochUnitSeconds* = float64(10) # the rln-relay epoch length in seconds
const EpochUnitSeconds* = float64(1) # 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
Expand Down

0 comments on commit 5847f49

Please sign in to comment.