Skip to content

Commit

Permalink
fix: adding rln validator as default (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Jan 29, 2024
1 parent 4f06dcf commit bb58a63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,10 @@ proc mountRlnRelay*(node: WakuNode,
let rlnRelay = rlnRelayRes.get()
let validator = generateRlnValidator(rlnRelay, spamHandler)

# register rln validator for all subscribed relay pubsub topics
for pubsubTopic in node.wakuRelay.subscribedTopics:
debug "Registering RLN validator for topic", pubsubTopic=pubsubTopic
node.wakuRelay.addValidator(pubsubTopic, validator)
# register rln validator as default validator
debug "Registering RLN validator"
node.wakuRelay.addDefaultValidator(validator)

node.wakuRlnRelay = rlnRelay

## Waku peer-exchange
Expand Down
11 changes: 11 additions & 0 deletions waku/waku_relay/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ type
# a map that stores whether the ordered validator has been inserted
# for a given PubsubTopic
validatorInserted: Table[PubsubTopic, bool]
# seq of validators that are called for every pubsub topic
wakuDefaultValidators: seq[WakuValidatorHandler]

proc initProtocolHandler(w: WakuRelay) =
proc handler(conn: Connection, proto: string) {.async.} =
Expand Down Expand Up @@ -183,6 +185,10 @@ proc addValidator*(w: WakuRelay,
for t in topic:
w.wakuValidators.mgetOrPut(t, @[]).add(handler)

proc addDefaultValidator*(w: WakuRelay,
handler: WakuValidatorHandler) {.gcsafe.} =
w.wakuDefaultValidators.add(handler)

method start*(w: WakuRelay) {.async.} =
debug "start"
await procCall GossipSub(w).start()
Expand Down Expand Up @@ -210,6 +216,11 @@ proc generateOrderedValidator*(w: WakuRelay): auto {.gcsafe.} =
let msg = msgRes.get()

# now sequentially validate the message
for validator in w.wakuDefaultValidators:
let validatorRes = await validator(pubsubTopic, msg)
if validatorRes != ValidationResult.Accept:
return validatorRes

if w.wakuValidators.hasKey(pubsubTopic):
for validator in w.wakuValidators[pubsubTopic]:
let validatorRes = await validator(pubsubTopic, msg)
Expand Down

0 comments on commit bb58a63

Please sign in to comment.