Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding rln validator as default #2367

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i understand this.
imho if rln is enabled, it should be enabled in all topics. same applies for all validators.

so not sure i understand the difference between validators and default validators. Having addValidator and addDefaultValidator creates some cognitive load for a use case that IMHO we don't have?


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
Loading