mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-15 09:26:38 +00:00
fix: make rln rate limit spec compliant (#2294)
This commit is contained in:
parent
0fc617ff69
commit
5847f49d3d
@ -398,7 +398,7 @@ procSuite "WakuNode - RLN relay":
|
|||||||
await node3.stop()
|
await node3.stop()
|
||||||
|
|
||||||
asyncTest "clearNullifierLog: should clear epochs > MaxEpochGap":
|
asyncTest "clearNullifierLog: should clear epochs > MaxEpochGap":
|
||||||
|
|
||||||
let
|
let
|
||||||
# publisher node
|
# publisher node
|
||||||
nodeKey1 = generateSecp256k1Key()
|
nodeKey1 = generateSecp256k1Key()
|
||||||
@ -445,7 +445,7 @@ procSuite "WakuNode - RLN relay":
|
|||||||
proofAdded1 = node1.wakuRlnRelay.appendRLNProof(wm1, time)
|
proofAdded1 = node1.wakuRlnRelay.appendRLNProof(wm1, time)
|
||||||
# another message in the same epoch as wm1, it will break the messaging rate limit
|
# another message in the same epoch as wm1, it will break the messaging rate limit
|
||||||
wm2 = WakuMessage(payload: "message 2".toBytes(), contentTopic: contentTopic)
|
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 points to the next epoch
|
||||||
wm3 = WakuMessage(payload: "message 3".toBytes(), contentTopic: contentTopic)
|
wm3 = WakuMessage(payload: "message 3".toBytes(), contentTopic: contentTopic)
|
||||||
proofAdded3 = node1.wakuRlnRelay.appendRLNProof(wm3, time + EpochUnitSeconds * 2)
|
proofAdded3 = node1.wakuRlnRelay.appendRLNProof(wm3, time + EpochUnitSeconds * 2)
|
||||||
@ -455,7 +455,7 @@ procSuite "WakuNode - RLN relay":
|
|||||||
proofAdded1
|
proofAdded1
|
||||||
proofAdded2
|
proofAdded2
|
||||||
proofAdded3
|
proofAdded3
|
||||||
|
|
||||||
# relay handler for node2
|
# relay handler for node2
|
||||||
var completionFut1 = newFuture[bool]()
|
var completionFut1 = newFuture[bool]()
|
||||||
var completionFut2 = newFuture[bool]()
|
var completionFut2 = newFuture[bool]()
|
||||||
@ -469,25 +469,25 @@ procSuite "WakuNode - RLN relay":
|
|||||||
completionFut2.complete(true)
|
completionFut2.complete(true)
|
||||||
if msg == wm3:
|
if msg == wm3:
|
||||||
completionFut3.complete(true)
|
completionFut3.complete(true)
|
||||||
|
|
||||||
# mount the relay handler for node2
|
# mount the relay handler for node2
|
||||||
node2.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
|
node2.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
|
||||||
await sleepAsync(2000.millis)
|
await sleepAsync(2000.millis)
|
||||||
|
|
||||||
await node1.publish(some(DefaultPubsubTopic), wm1)
|
await node1.publish(some(DefaultPubsubTopic), wm1)
|
||||||
await sleepAsync(10.seconds)
|
|
||||||
await node1.publish(some(DefaultPubsubTopic), wm2)
|
await node1.publish(some(DefaultPubsubTopic), wm2)
|
||||||
await sleepAsync(10.seconds)
|
|
||||||
await node1.publish(some(DefaultPubsubTopic), wm3)
|
await node1.publish(some(DefaultPubsubTopic), wm3)
|
||||||
|
|
||||||
let
|
let
|
||||||
res1 = await completionFut1.withTimeout(10.seconds)
|
res1 = await completionFut1.withTimeout(10.seconds)
|
||||||
res2 = await completionFut2.withTimeout(10.seconds)
|
res2 = await completionFut2.withTimeout(10.seconds)
|
||||||
res3 = await completionFut3.withTimeout(10.seconds)
|
res3 = await completionFut3.withTimeout(10.seconds)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
(res1 and res2 and res3) == true # all 3 are valid
|
res1 == true
|
||||||
node2.wakuRlnRelay.nullifierLog.len() == 1 # after clearing, only 1 is stored
|
res2 == false
|
||||||
|
res3 == true
|
||||||
|
node2.wakuRlnRelay.nullifierLog.len() == 2
|
||||||
|
|
||||||
await node1.stop()
|
await node1.stop()
|
||||||
await node2.stop()
|
await node2.stop()
|
||||||
|
@ -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
|
# the root is created locally, using createMembershipList proc from waku_rln_relay_utils module, and the result is hardcoded in here
|
||||||
StaticGroupMerkleRoot* = "1e534adab58f7d300aaeecae57a25e0a0b18c368a09f720280da92b288950901"
|
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
|
const MaxClockGapSeconds* = 20.0 # the maximum clock difference between peers in seconds
|
||||||
|
|
||||||
# maximum allowed gap between the epochs of messages' RateLimitProofs
|
# maximum allowed gap between the epochs of messages' RateLimitProofs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user