2022-09-06 18:43:46 +00:00
|
|
|
|
{.used.}
|
|
|
|
|
|
|
|
|
|
import
|
2023-06-19 08:16:05 +00:00
|
|
|
|
std/[sequtils, tempfiles],
|
2022-09-06 18:43:46 +00:00
|
|
|
|
stew/byteutils,
|
2022-11-04 09:52:08 +00:00
|
|
|
|
stew/shims/net as stewNet,
|
2022-09-06 18:43:46 +00:00
|
|
|
|
testutils/unittests,
|
2022-11-04 09:52:08 +00:00
|
|
|
|
chronicles,
|
|
|
|
|
chronos,
|
2022-09-06 18:43:46 +00:00
|
|
|
|
libp2p/switch,
|
2023-09-06 08:18:02 +00:00
|
|
|
|
libp2p/protocols/pubsub/pubsub
|
2022-09-06 18:43:46 +00:00
|
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
|
waku/[waku_core, waku_node, waku_rln_relay],
|
2024-08-02 14:43:22 +00:00
|
|
|
|
../testlib/[wakucore, futures, wakunode],
|
2024-03-12 10:50:30 +00:00
|
|
|
|
./rln/waku_rln_relay_utils
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
from std/times import epochTime
|
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
proc buildWakuRlnConfig(
|
|
|
|
|
credIndex: uint,
|
|
|
|
|
epochSizeSec: uint64,
|
|
|
|
|
treeFilename: string,
|
|
|
|
|
userMessageLimit: uint64 = 1,
|
|
|
|
|
): WakuRlnConfig =
|
|
|
|
|
let treePath = genTempPath("rln_tree", treeFilename)
|
|
|
|
|
# Off-chain
|
|
|
|
|
return WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(credIndex.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: userMessageLimit,
|
|
|
|
|
rlnEpochSizeSec: epochSizeSec,
|
|
|
|
|
rlnRelayTreePath: treePath,
|
|
|
|
|
)
|
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
procSuite "WakuNode - RLN relay":
|
2024-03-12 10:50:30 +00:00
|
|
|
|
# NOTE: we set the rlnRelayUserMessageLimit to 1 to make the tests easier to reason about
|
2022-09-06 18:43:46 +00:00
|
|
|
|
asyncTest "testing rln-relay with valid proof":
|
|
|
|
|
let
|
|
|
|
|
# publisher node
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# Relay node
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# Subscriber
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey3 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node3 = newTestWakuNode(nodeKey3, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
|
|
|
|
|
|
# set up three nodes
|
|
|
|
|
# node1
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node1.mountRelay(@[DefaultPubsubTopic])
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig1 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node1.mountRlnRelay(wakuRlnConfig1)
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node1.start()
|
|
|
|
|
|
|
|
|
|
# node 2
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node2.mountRelay(@[DefaultPubsubTopic])
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig2 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(2.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_2"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node2.mountRlnRelay(wakuRlnConfig2)
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node2.start()
|
|
|
|
|
|
|
|
|
|
# node 3
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node3.mountRelay(@[DefaultPubsubTopic])
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig3 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(3.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_3"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node3.mountRlnRelay(wakuRlnConfig3)
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node3.start()
|
|
|
|
|
|
|
|
|
|
# connect them together
|
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
await node3.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
|
|
|
|
var completionFut = newFuture[bool]()
|
2024-03-15 23:08:47 +00:00
|
|
|
|
proc relayHandler(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
2023-06-06 17:28:47 +00:00
|
|
|
|
debug "The received topic:", topic
|
2023-08-21 06:55:34 +00:00
|
|
|
|
if topic == DefaultPubsubTopic:
|
2023-06-06 17:28:47 +00:00
|
|
|
|
completionFut.complete(true)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
# mount the relay handler
|
2023-09-26 11:33:52 +00:00
|
|
|
|
node3.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
# prepare the message payload
|
|
|
|
|
let payload = "Hello".toBytes()
|
|
|
|
|
|
|
|
|
|
# prepare the epoch
|
|
|
|
|
var message = WakuMessage(payload: @payload, contentTopic: contentTopic)
|
2024-03-12 10:50:30 +00:00
|
|
|
|
doAssert(node1.wakuRlnRelay.unsafeAppendRLNProof(message, epochTime()).isOk())
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
## node1 publishes a message with a rate limit proof, the message is then relayed to node2 which in turn
|
|
|
|
|
## verifies the rate limit proof of the message and relays the message to node3
|
|
|
|
|
## verification at node2 occurs inside a topic validator which is installed as part of the waku-rln-relay mount proc
|
2024-01-18 12:49:13 +00:00
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), message)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
(await completionFut.withTimeout(10.seconds)) == true
|
|
|
|
|
|
|
|
|
|
await node1.stop()
|
|
|
|
|
await node2.stop()
|
|
|
|
|
await node3.stop()
|
2023-02-13 10:43:49 +00:00
|
|
|
|
|
2023-08-21 06:55:34 +00:00
|
|
|
|
asyncTest "testing rln-relay is applied in all rln pubsub/content topics":
|
|
|
|
|
# create 3 nodes
|
2024-03-15 23:08:47 +00:00
|
|
|
|
let nodes = toSeq(0 ..< 3).mapIt(
|
|
|
|
|
newTestWakuNode(generateSecp256k1Key(), parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
|
)
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await allFutures(nodes.mapIt(it.start()))
|
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
|
let pubsubTopics =
|
|
|
|
|
@[
|
2023-08-21 06:55:34 +00:00
|
|
|
|
PubsubTopic("/waku/2/pubsubtopic-a/proto"),
|
2024-03-15 23:08:47 +00:00
|
|
|
|
PubsubTopic("/waku/2/pubsubtopic-b/proto"),
|
|
|
|
|
]
|
|
|
|
|
let contentTopics =
|
|
|
|
|
@[
|
2023-08-21 06:55:34 +00:00
|
|
|
|
ContentTopic("/waku/2/content-topic-a/proto"),
|
2024-03-15 23:08:47 +00:00
|
|
|
|
ContentTopic("/waku/2/content-topic-b/proto"),
|
|
|
|
|
]
|
2023-08-21 06:55:34 +00:00
|
|
|
|
|
|
|
|
|
# set up three nodes
|
|
|
|
|
await allFutures(nodes.mapIt(it.mountRelay(pubsubTopics)))
|
|
|
|
|
|
|
|
|
|
# mount rlnrelay in off-chain mode
|
|
|
|
|
for index, node in nodes:
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(index.uint + 1),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_" & $(index + 1)),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node.mountRlnRelay(wakuRlnConfig)
|
2023-08-21 06:55:34 +00:00
|
|
|
|
|
|
|
|
|
# start them
|
|
|
|
|
await allFutures(nodes.mapIt(it.start()))
|
|
|
|
|
|
|
|
|
|
# connect them together
|
|
|
|
|
await nodes[0].connectToNodes(@[nodes[1].switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
await nodes[2].connectToNodes(@[nodes[1].switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
|
|
|
|
var rxMessagesTopic1 = 0
|
|
|
|
|
var rxMessagesTopic2 = 0
|
2024-03-15 23:08:47 +00:00
|
|
|
|
proc relayHandler(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
2023-08-21 06:55:34 +00:00
|
|
|
|
info "relayHandler. The received topic:", topic
|
|
|
|
|
if topic == pubsubTopics[0]:
|
|
|
|
|
rxMessagesTopic1 = rxMessagesTopic1 + 1
|
|
|
|
|
elif topic == pubsubTopics[1]:
|
|
|
|
|
rxMessagesTopic2 = rxMessagesTopic2 + 1
|
|
|
|
|
|
|
|
|
|
# mount the relay handlers
|
2023-09-26 11:33:52 +00:00
|
|
|
|
nodes[2].subscribe((kind: PubsubSub, topic: pubsubTopics[0]), some(relayHandler))
|
|
|
|
|
nodes[2].subscribe((kind: PubsubSub, topic: pubsubTopics[1]), some(relayHandler))
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await sleepAsync(1000.millis)
|
|
|
|
|
|
2023-08-31 10:24:41 +00:00
|
|
|
|
# generate some messages with rln proofs first. generating
|
|
|
|
|
# the proof takes some time, so this is done before publishing
|
|
|
|
|
# to avoid blocking the test
|
|
|
|
|
var messages1: seq[WakuMessage] = @[]
|
|
|
|
|
var messages2: seq[WakuMessage] = @[]
|
|
|
|
|
|
|
|
|
|
let epochTime = epochTime()
|
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
|
for i in 0 ..< 3:
|
|
|
|
|
var message = WakuMessage(
|
|
|
|
|
payload: ("Payload_" & $i).toBytes(), contentTopic: contentTopics[0]
|
|
|
|
|
)
|
2024-03-12 10:50:30 +00:00
|
|
|
|
nodes[0].wakuRlnRelay.unsafeAppendRLNProof(message, epochTime).isOkOr:
|
|
|
|
|
raiseAssert $error
|
2023-08-31 10:24:41 +00:00
|
|
|
|
messages1.add(message)
|
2023-08-21 06:55:34 +00:00
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
|
for i in 0 ..< 3:
|
|
|
|
|
var message = WakuMessage(
|
|
|
|
|
payload: ("Payload_" & $i).toBytes(), contentTopic: contentTopics[1]
|
|
|
|
|
)
|
2024-03-12 10:50:30 +00:00
|
|
|
|
nodes[1].wakuRlnRelay.unsafeAppendRLNProof(message, epochTime).isOkOr:
|
|
|
|
|
raiseAssert $error
|
2023-08-31 10:24:41 +00:00
|
|
|
|
messages2.add(message)
|
|
|
|
|
|
|
|
|
|
# publish 3 messages from node[0] (last 2 are spam, window is 10 secs)
|
|
|
|
|
# publish 3 messages from node[1] (last 2 are spam, window is 10 secs)
|
2024-03-15 23:08:47 +00:00
|
|
|
|
for msg in messages1:
|
|
|
|
|
discard await nodes[0].publish(some(pubsubTopics[0]), msg)
|
|
|
|
|
for msg in messages2:
|
|
|
|
|
discard await nodes[1].publish(some(pubsubTopics[1]), msg)
|
2023-08-21 06:55:34 +00:00
|
|
|
|
|
|
|
|
|
# wait for gossip to propagate
|
2023-08-22 08:10:54 +00:00
|
|
|
|
await sleepAsync(5000.millis)
|
2023-08-21 06:55:34 +00:00
|
|
|
|
|
|
|
|
|
# check that node[2] got messages from both topics
|
2023-08-22 08:10:54 +00:00
|
|
|
|
# and that rln was applied (just 1 msg is rx, rest are spam)
|
2023-08-21 06:55:34 +00:00
|
|
|
|
check:
|
|
|
|
|
rxMessagesTopic1 == 1
|
|
|
|
|
rxMessagesTopic2 == 1
|
|
|
|
|
|
|
|
|
|
await allFutures(nodes.mapIt(it.stop()))
|
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
asyncTest "testing rln-relay with invalid proof":
|
|
|
|
|
let
|
|
|
|
|
# publisher node
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# Relay node
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# Subscriber
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey3 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node3 = newTestWakuNode(nodeKey3, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
|
|
|
|
|
|
# set up three nodes
|
|
|
|
|
# node1
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node1.mountRelay(@[DefaultPubsubTopic])
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig1 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_4"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node1.mountRlnRelay(wakuRlnConfig1)
|
2022-12-13 09:26:24 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node1.start()
|
|
|
|
|
|
|
|
|
|
# node 2
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node2.mountRelay(@[DefaultPubsubTopic])
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig2 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(2.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_5"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node2.mountRlnRelay(wakuRlnConfig2)
|
2022-12-13 09:26:24 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node2.start()
|
|
|
|
|
|
|
|
|
|
# node 3
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node3.mountRelay(@[DefaultPubsubTopic])
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig3 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(3.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_6"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node3.mountRlnRelay(wakuRlnConfig3)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node3.start()
|
|
|
|
|
|
|
|
|
|
# connect them together
|
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
await node3.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
|
|
|
|
# define a custom relay handler
|
|
|
|
|
var completionFut = newFuture[bool]()
|
2024-03-15 23:08:47 +00:00
|
|
|
|
proc relayHandler(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
2023-06-06 17:28:47 +00:00
|
|
|
|
debug "The received topic:", topic
|
2023-08-21 06:55:34 +00:00
|
|
|
|
if topic == DefaultPubsubTopic:
|
2023-06-06 17:28:47 +00:00
|
|
|
|
completionFut.complete(true)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
# mount the relay handler
|
2023-09-26 11:33:52 +00:00
|
|
|
|
node3.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
# prepare the message payload
|
|
|
|
|
let payload = "Hello".toBytes()
|
|
|
|
|
|
|
|
|
|
# prepare the epoch
|
2024-02-28 16:19:20 +00:00
|
|
|
|
let epoch = node1.wakuRlnRelay.getCurrentEpoch()
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
# prepare the proof
|
|
|
|
|
let
|
|
|
|
|
contentTopicBytes = contentTopic.toBytes
|
|
|
|
|
input = concat(payload, contentTopicBytes)
|
2024-03-15 23:08:47 +00:00
|
|
|
|
extraBytes: seq[byte] = @[byte(1), 2, 3]
|
2024-03-01 08:45:40 +00:00
|
|
|
|
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let nonceManager = node1.wakuRlnRelay.nonceManager
|
|
|
|
|
let rateLimitProofRes = node1.wakuRlnRelay.groupManager.generateProof(
|
|
|
|
|
concat(input, extraBytes), epoch, MessageId(0)
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
|
assert rateLimitProofRes.isOk(), $rateLimitProofRes.error
|
|
|
|
|
# check the proof is generated correctly outside when block to avoid duplication
|
2022-11-22 17:29:43 +00:00
|
|
|
|
let rateLimitProof = rateLimitProofRes.get().encode().buffer
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
|
let message =
|
|
|
|
|
WakuMessage(payload: @payload, contentTopic: contentTopic, proof: rateLimitProof)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
## node1 publishes a message with an invalid rln proof, the message is then relayed to node2 which in turn
|
|
|
|
|
## attempts to verify the rate limit proof and fails hence does not relay the message to node3, thus the relayHandler of node3
|
|
|
|
|
## never gets called
|
|
|
|
|
## verification at node2 occurs inside a topic validator which is installed as part of the waku-rln-relay mount proc
|
2024-01-18 12:49:13 +00:00
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), message)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
# the relayHandler of node3 never gets called
|
|
|
|
|
(await completionFut.withTimeout(10.seconds)) == false
|
|
|
|
|
|
|
|
|
|
await node1.stop()
|
|
|
|
|
await node2.stop()
|
|
|
|
|
await node3.stop()
|
|
|
|
|
|
|
|
|
|
asyncTest "testing rln-relay double-signaling detection":
|
|
|
|
|
let
|
|
|
|
|
# publisher node
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# Relay node
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# Subscriber
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey3 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node3 = newTestWakuNode(nodeKey3, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
|
|
|
|
|
|
# set up three nodes
|
|
|
|
|
# node1
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node1.mountRelay(@[DefaultPubsubTopic])
|
2022-12-13 09:26:24 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig1 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_7"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node1.mountRlnRelay(wakuRlnConfig1)
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node1.start()
|
|
|
|
|
|
|
|
|
|
# node 2
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node2.mountRelay(@[DefaultPubsubTopic])
|
2022-12-13 09:26:24 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig2 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(2.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_8"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node2.mountRlnRelay(wakuRlnConfig2)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node2.start()
|
|
|
|
|
|
|
|
|
|
# node 3
|
2023-08-21 06:55:34 +00:00
|
|
|
|
await node3.mountRelay(@[DefaultPubsubTopic])
|
2022-12-13 09:26:24 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
# mount rlnrelay in off-chain mode
|
2024-06-20 09:35:21 +00:00
|
|
|
|
let wakuRlnConfig3 = WakuRlnConfig(
|
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
|
rlnRelayCredIndex: some(3.uint),
|
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_9"),
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node3.mountRlnRelay(wakuRlnConfig3)
|
2022-11-04 03:00:42 +00:00
|
|
|
|
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await node3.start()
|
|
|
|
|
|
|
|
|
|
# connect the nodes together node1 <-> node2 <-> node3
|
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
await node3.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
|
|
|
|
# get the current epoch time
|
|
|
|
|
let time = epochTime()
|
|
|
|
|
# create some messages with rate limit proofs
|
|
|
|
|
var
|
|
|
|
|
wm1 = WakuMessage(payload: "message 1".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
# another message in the same epoch as wm1, it will break the messaging rate limit
|
|
|
|
|
wm2 = WakuMessage(payload: "message 2".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
# wm3 points to the next epoch
|
|
|
|
|
wm3 = WakuMessage(payload: "message 3".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
wm4 = WakuMessage(payload: "message 4".toBytes(), contentTopic: contentTopic)
|
2024-03-15 23:08:47 +00:00
|
|
|
|
|
2024-03-12 10:50:30 +00:00
|
|
|
|
node3.wakuRlnRelay.unsafeAppendRLNProof(wm1, time).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
node3.wakuRlnRelay.unsafeAppendRLNProof(wm2, time).isOkOr:
|
|
|
|
|
raiseAssert $error
|
2024-07-05 22:03:38 +00:00
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
|
node3.wakuRlnRelay.unsafeAppendRLNProof(
|
|
|
|
|
wm3, time + float64(node3.wakuRlnRelay.rlnEpochSizeSec)
|
|
|
|
|
).isOkOr:
|
2024-03-12 10:50:30 +00:00
|
|
|
|
raiseAssert $error
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
# relay handler for node3
|
|
|
|
|
var completionFut1 = newFuture[bool]()
|
|
|
|
|
var completionFut2 = newFuture[bool]()
|
|
|
|
|
var completionFut3 = newFuture[bool]()
|
|
|
|
|
var completionFut4 = newFuture[bool]()
|
2024-03-15 23:08:47 +00:00
|
|
|
|
proc relayHandler(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
2023-06-06 17:28:47 +00:00
|
|
|
|
debug "The received topic:", topic
|
2023-08-21 06:55:34 +00:00
|
|
|
|
if topic == DefaultPubsubTopic:
|
2023-06-06 17:28:47 +00:00
|
|
|
|
if msg == wm1:
|
|
|
|
|
completionFut1.complete(true)
|
|
|
|
|
if msg == wm2:
|
|
|
|
|
completionFut2.complete(true)
|
|
|
|
|
if msg == wm3:
|
|
|
|
|
completionFut3.complete(true)
|
|
|
|
|
if msg == wm4:
|
|
|
|
|
completionFut4.complete(true)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
|
|
|
|
|
# mount the relay handler for node3
|
2023-09-26 11:33:52 +00:00
|
|
|
|
node3.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
## node1 publishes and relays 4 messages to node2
|
|
|
|
|
## verification at node2 occurs inside a topic validator which is installed as part of the waku-rln-relay mount proc
|
|
|
|
|
## node2 relays either of wm1 or wm2 to node3, depending on which message arrives at node2 first
|
|
|
|
|
## node2 should detect either of wm1 or wm2 as spam and not relay it
|
|
|
|
|
## node2 should relay wm3 to node3
|
|
|
|
|
## node2 should not relay wm4 because it has no valid rln proof
|
2024-01-18 12:49:13 +00:00
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm1)
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm2)
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm3)
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm4)
|
2022-09-06 18:43:46 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
res1 = await completionFut1.withTimeout(10.seconds)
|
|
|
|
|
res2 = await completionFut2.withTimeout(10.seconds)
|
|
|
|
|
|
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
|
(res1 and res2) == false
|
|
|
|
|
# either of the wm1 and wm2 is found as spam hence not relayed
|
2022-09-06 18:43:46 +00:00
|
|
|
|
(await completionFut3.withTimeout(10.seconds)) == true
|
|
|
|
|
(await completionFut4.withTimeout(10.seconds)) == false
|
|
|
|
|
|
|
|
|
|
await node1.stop()
|
|
|
|
|
await node2.stop()
|
2023-02-10 16:55:47 +00:00
|
|
|
|
await node3.stop()
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
|
|
|
|
asyncTest "clearNullifierLog: should clear epochs > MaxEpochGap":
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Given two nodes
|
2023-09-06 08:18:02 +00:00
|
|
|
|
let
|
2024-08-02 14:43:22 +00:00
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
|
pubsubTopicSeq = @[DefaultPubsubTopic]
|
2023-09-06 08:18:02 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(0))
|
2023-09-06 08:18:02 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(0))
|
2024-08-02 14:43:22 +00:00
|
|
|
|
epochSizeSec: uint64 = 5 # This means rlnMaxEpochGap = 4
|
2024-06-20 09:35:21 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Given both nodes mount relay and rlnrelay
|
|
|
|
|
await node1.mountRelay(pubsubTopicSeq)
|
|
|
|
|
let wakuRlnConfig1 = buildWakuRlnConfig(1, epochSizeSec, "wakunode_10")
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node1.mountRlnRelay(wakuRlnConfig1)
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Mount rlnrelay in node2 in off-chain mode
|
2023-09-06 08:18:02 +00:00
|
|
|
|
await node2.mountRelay(@[DefaultPubsubTopic])
|
2024-08-02 14:43:22 +00:00
|
|
|
|
let wakuRlnConfig2 = buildWakuRlnConfig(2, epochSizeSec, "wakunode_11")
|
2024-03-12 10:50:30 +00:00
|
|
|
|
await node2.mountRlnRelay(wakuRlnConfig2)
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Given the two nodes are started and connected
|
|
|
|
|
waitFor allFutures(node1.start(), node2.start())
|
2023-09-06 08:18:02 +00:00
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Given some messages
|
2023-09-06 08:18:02 +00:00
|
|
|
|
var
|
|
|
|
|
wm1 = WakuMessage(payload: "message 1".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
wm2 = WakuMessage(payload: "message 2".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
wm3 = WakuMessage(payload: "message 3".toBytes(), contentTopic: contentTopic)
|
2024-08-02 14:43:22 +00:00
|
|
|
|
wm4 = WakuMessage(payload: "message 4".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
wm5 = WakuMessage(payload: "message 5".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
wm6 = WakuMessage(payload: "message 6".toBytes(), contentTopic: contentTopic)
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# And node2 mounts a relay handler that completes the respective future when a message is received
|
|
|
|
|
var
|
|
|
|
|
completionFut1 = newFuture[bool]()
|
|
|
|
|
completionFut2 = newFuture[bool]()
|
|
|
|
|
completionFut3 = newFuture[bool]()
|
|
|
|
|
completionFut4 = newFuture[bool]()
|
|
|
|
|
completionFut5 = newFuture[bool]()
|
|
|
|
|
completionFut6 = newFuture[bool]()
|
2024-03-15 23:08:47 +00:00
|
|
|
|
proc relayHandler(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
2023-09-06 08:18:02 +00:00
|
|
|
|
debug "The received topic:", topic
|
|
|
|
|
if topic == DefaultPubsubTopic:
|
|
|
|
|
if msg == wm1:
|
|
|
|
|
completionFut1.complete(true)
|
|
|
|
|
if msg == wm2:
|
|
|
|
|
completionFut2.complete(true)
|
|
|
|
|
if msg == wm3:
|
|
|
|
|
completionFut3.complete(true)
|
2024-08-02 14:43:22 +00:00
|
|
|
|
if msg == wm4:
|
|
|
|
|
completionFut4.complete(true)
|
|
|
|
|
if msg == wm5:
|
|
|
|
|
completionFut5.complete(true)
|
|
|
|
|
if msg == wm6:
|
|
|
|
|
completionFut6.complete(true)
|
2023-12-15 09:26:17 +00:00
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
|
node2.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(relayHandler))
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Given all messages have an rln proof and are published by the node 1
|
|
|
|
|
let publishSleepDuration: Duration = 5000.millis
|
|
|
|
|
let time = epochTime()
|
|
|
|
|
|
|
|
|
|
# Epoch 1
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(wm1, time).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
# Message wm2 is published in the same epoch as wm1, so it'll be considered spam
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(wm2, time).isOkOr:
|
|
|
|
|
raiseAssert $error
|
2024-01-18 12:49:13 +00:00
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm1)
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm2)
|
2024-08-02 14:43:22 +00:00
|
|
|
|
await sleepAsync(publishSleepDuration)
|
|
|
|
|
check:
|
|
|
|
|
node1.wakuRlnRelay.nullifierLog.len() == 0
|
|
|
|
|
node2.wakuRlnRelay.nullifierLog.len() == 1
|
|
|
|
|
|
|
|
|
|
# Epoch 2
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(wm3, epochTime()).isOkOr:
|
|
|
|
|
raiseAssert $error
|
2024-01-18 12:49:13 +00:00
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm3)
|
2024-08-02 14:43:22 +00:00
|
|
|
|
await sleepAsync(publishSleepDuration)
|
|
|
|
|
check:
|
|
|
|
|
node1.wakuRlnRelay.nullifierLog.len() == 0
|
|
|
|
|
node2.wakuRlnRelay.nullifierLog.len() == 2
|
2023-12-15 09:26:17 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Epoch 3
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(wm4, epochTime()).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm4)
|
|
|
|
|
await sleepAsync(publishSleepDuration)
|
|
|
|
|
check:
|
|
|
|
|
node1.wakuRlnRelay.nullifierLog.len() == 0
|
|
|
|
|
node2.wakuRlnRelay.nullifierLog.len() == 3
|
|
|
|
|
|
|
|
|
|
# Epoch 4
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(wm5, epochTime()).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm5)
|
|
|
|
|
await sleepAsync(publishSleepDuration)
|
|
|
|
|
check:
|
|
|
|
|
node1.wakuRlnRelay.nullifierLog.len() == 0
|
|
|
|
|
node2.wakuRlnRelay.nullifierLog.len() == 4
|
|
|
|
|
|
|
|
|
|
# Epoch 5
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(wm6, epochTime()).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), wm6)
|
|
|
|
|
await sleepAsync(publishSleepDuration)
|
|
|
|
|
check:
|
|
|
|
|
node1.wakuRlnRelay.nullifierLog.len() == 0
|
|
|
|
|
node2.wakuRlnRelay.nullifierLog.len() == 4
|
|
|
|
|
|
|
|
|
|
# Then the node 2 should have cleared the nullifier log for epochs > MaxEpochGap
|
|
|
|
|
# Therefore, with 4 max epochs, the first 4 messages will be published (except wm2, which shares epoch with wm1)
|
|
|
|
|
check:
|
|
|
|
|
(await completionFut1.waitForResult()).value() == true
|
|
|
|
|
(await completionFut2.waitForResult()).isErr()
|
|
|
|
|
(await completionFut3.waitForResult()).value() == true
|
|
|
|
|
(await completionFut4.waitForResult()).value() == true
|
|
|
|
|
(await completionFut5.waitForResult()).value() == true
|
|
|
|
|
(await completionFut6.waitForResult()).value() == true
|
|
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
|
waitFor allFutures(node1.stop(), node2.stop())
|
|
|
|
|
|
|
|
|
|
asyncTest "Spam Detection and Slashing (currently gossipsub score decrease)":
|
|
|
|
|
# Given two nodes
|
2023-09-06 08:18:02 +00:00
|
|
|
|
let
|
2024-08-02 14:43:22 +00:00
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
|
pubsubTopicSeq = @[DefaultPubsubTopic]
|
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
|
epochSizeSec: uint64 = 5 # This means rlnMaxEpochGap = 4
|
|
|
|
|
|
|
|
|
|
# Given both nodes mount relay and rlnrelay
|
|
|
|
|
# Mount rlnrelay in node1 in off-chain mode
|
|
|
|
|
await node1.mountRelay(pubsubTopicSeq)
|
|
|
|
|
let wakuRlnConfig1 = buildWakuRlnConfig(1, epochSizeSec, "wakunode_10")
|
|
|
|
|
await node1.mountRlnRelay(wakuRlnConfig1)
|
|
|
|
|
|
|
|
|
|
# Mount rlnrelay in node2 in off-chain mode
|
|
|
|
|
await node2.mountRelay(@[DefaultPubsubTopic])
|
|
|
|
|
let wakuRlnConfig2 = buildWakuRlnConfig(2, epochSizeSec, "wakunode_11")
|
|
|
|
|
await node2.mountRlnRelay(wakuRlnConfig2)
|
|
|
|
|
|
|
|
|
|
# Given the two nodes are started and connected
|
|
|
|
|
waitFor allFutures(node1.start(), node2.start())
|
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# Given some messages with rln proofs
|
|
|
|
|
let time = epochTime()
|
|
|
|
|
var
|
|
|
|
|
msg1 = WakuMessage(payload: "message 1".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
msg2 = WakuMessage(payload: "message 2".toBytes(), contentTopic: contentTopic)
|
|
|
|
|
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(msg1, time).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
# Message wm2 is published in the same epoch as wm1, so it'll be considered spam
|
|
|
|
|
node1.wakuRlnRelay.unsafeAppendRLNProof(msg2, time).isOkOr:
|
|
|
|
|
raiseAssert $error
|
|
|
|
|
|
|
|
|
|
# When publishing the first message (valid)
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), msg1)
|
|
|
|
|
await sleepAsync(FUTURE_TIMEOUT_SCORING) # Wait for scoring
|
|
|
|
|
|
|
|
|
|
# Then the score of node2 should increase
|
2023-09-06 08:18:02 +00:00
|
|
|
|
check:
|
2024-08-02 14:43:22 +00:00
|
|
|
|
node1.wakuRelay.peerStats[node2.switch.peerInfo.peerId].score == 0.1
|
|
|
|
|
node2.wakuRelay.peerStats[node1.switch.peerInfo.peerId].score == 1.1
|
2023-09-06 08:18:02 +00:00
|
|
|
|
|
2024-08-02 14:43:22 +00:00
|
|
|
|
# When publishing the second message (spam)
|
|
|
|
|
discard await node1.publish(some(DefaultPubsubTopic), msg2)
|
|
|
|
|
await sleepAsync(FUTURE_TIMEOUT_SCORING)
|
|
|
|
|
|
|
|
|
|
# Then the score of node2 should decrease
|
|
|
|
|
check:
|
|
|
|
|
node1.wakuRelay.peerStats[node2.switch.peerInfo.peerId].score == 0.1
|
|
|
|
|
node2.wakuRelay.peerStats[node1.switch.peerInfo.peerId].score == -99.4
|