-
Notifications
You must be signed in to change notification settings - Fork 57
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
chore(api): validate rln message before sending (rest + rpc) #1968
Conversation
raise newException(ValueError, "Failed to publish: error appending RLN proof to message") | ||
|
||
# validate the message before sending it | ||
let result = node.wakuRlnRelay.validateMessage(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsure if its ok to use validateMessage
here, since inside it updates a bunch of metrics and call updateLog
. Any opinion @rymnc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I don't think we should use validateMessage, because if you try publishing the same message it would get stuck since the proofMetadata would exist in the nullifierLog afaik. should probably split the function into the check, and then the state update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this 74d38f5 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!
You can find the image built from this PR at
|
74d38f5
to
f5ba118
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
6b76a8c
to
c130158
Compare
let rootIndex = rlnPeer.groupManager.indexOfRoot(proof.merkleRoot) | ||
waku_rln_valid_messages_total.observe(rootIndex.toFloat()) | ||
return MessageValidationResult.Valid | ||
|
||
proc validateMessageAndUpdateLog*( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rymnc created this function, which is like the old validateMessage
but now we have:
- validateMessage
- validateMessageAndUpdateLog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for it! I just added a question to learn sth :)
proc subscribedTopics*(w: WakuRelay): seq[PubsubTopic] = | ||
return toSeq(GossipSub(w).topics.keys()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Morning! Is this directly related to the purpose of the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, but imho there is no need to use generators for this. the amount of topics is not enough to justify it. also using poorly documented features such as lent lent
is a bad idea, unless strictly needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, minor comment
waku/node/jsonrpc/relay/handlers.nim
Outdated
if result == MessageValidationResult.Invalid: | ||
raise newException(ValueError, "Failed to publish: invalid RLN proof") | ||
elif result == MessageValidationResult.Spam: | ||
raise newException(ValueError, "Failed to publish: limit exceeded, try again later") | ||
elif result == MessageValidationResult.Valid: | ||
debug "Publishing message WITH RLN proof", pubSubTopic=pubSubTopic | ||
let publishFut = node.publish(pubsubTopic, message) | ||
if not await publishFut.withTimeout(futTimeout): | ||
raise newException(ValueError, "Failed to publish: timed out") | ||
else: | ||
raise newException(ValueError, "Failed to publish: unknown RLN proof validation result") | ||
else: | ||
raise newException(ValueError, "Failed to publish: RLN enabled but not mounted") | ||
|
||
# if RLN is not mounted, publish the message as is | ||
else: | ||
debug "Publishing message WITHOUT RLN proof", pubSubTopic=pubSubTopic | ||
let publishFut = node.publish(pubsubTopic, message) | ||
|
||
if not await publishFut.withTimeout(futTimeout): | ||
raise newException(ValueError, "Failed to publish: timed out") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these ValueError
's can be CatchableError
's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, maybe we can operate on the same message
in both cases? i.e rln is enabled, rln is disabled?
then we can save some loc by having just one
let publishFut = node.publish(pubsubTopic, message)
if not await publishFut.withTimeout(futTimeout):
raise newException(ValueError, "Failed to publish: timed out")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ow indeed, that was a bit spageti.
c964916
c130158
to
c964916
Compare
Description:
How to test it:
Rest API
RPC API