fix: adding rln validator as default (#2367)

This commit is contained in:
gabrielmer 2024-01-29 16:11:26 +01:00 committed by GitHub
parent 4f06dcffce
commit bb58a63aa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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.} =
@ -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()
@ -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)