-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat(relay): ordered validator execution #1966
Conversation
65876ac
to
4972ac7
Compare
You can find the image built from this PR at
|
hmm looks like the tests fail where it shouldn't - valid rln messages are not hitting the relayHandlers - nwaku/tests/waku_rln_relay/test_wakunode_rln_relay.nim Lines 230 to 234 in 0ac8a7f
|
4972ac7
to
c733752
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.
left some comments, perhaps one is related to your problem?
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! I've added a few comments/questions :)
Btw, I believe we should move the "validator" logic to a more appropriate place.
Given that the validation is part of the Relay
protocol, I think we need to make the next refactoring:
-
- Create a
validators
folder in "nwaku/waku/waku_relay/"
- Create a
-
- Move the logic of
apps/wakunode2/wakunode2_validator_signed.nim
intonwaku/waku/waku_relay/validators/signed_topic_validator.nim
- Move the logic of
-
- Move the RLN validation logic to
nwaku/waku/waku_relay/validators/rln_validator.nim
- Move the RLN validation logic to
WDYT @jm-clius , @alrevuelta , @rymnc ?
@@ -749,7 +749,7 @@ when defined(rln): | |||
# register rln validator for all subscribed relay pubsub topics | |||
for pubsubTopic in node.wakuRelay.subscribedTopics: | |||
debug "Registering RLN validator for topic", pubsubTopic=pubsubTopic | |||
procCall GossipSub(node.wakuRelay).addValidator(pubsubTopic, validator) | |||
node.wakuRelay.addValidator(pubsubTopic, validator) |
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.
Is this change directly related to the purpose of reordering the validators?
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.
yep, before we were calling gossipsubs addValidator
. with this now we call wakuRelay addValidator
.
In other words, we override addValidator
with a new implementation.
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, this is. as @jm-clius described below, we will create a new waku_validators
directory where we initialize them in the order we wish for them to execute
# add the ordered validator to the topic | ||
if not w.validatorInserted.hasKey(pubSubTopic): | ||
procCall GossipSub(w).addValidator(pubSubTopic, w.generateOrderedValidator()) | ||
w.validatorInserted[pubSubTopic] = true |
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.
Should we update this Table
upon an unsubscribe
event?
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.
this seems important right?
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.
Thanks, addressed in 893ddf5
proc isSubscribed*(w: WakuRelay, topic: PubsubTopic): bool = | ||
GossipSub(w).topics.hasKey(topic) | ||
|
||
iterator subscribedTopics*(w: WakuRelay): lent PubsubTopic = | ||
for topic in GossipSub(w).topics.keys(): | ||
yield topic | ||
|
||
proc generateOrderedValidator*(w: WakuRelay): auto {.gcsafe.} = |
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.
The 'Ordered' in this case refers to first validating the basic Waku Message encoding, and then, the rest?
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.
Sort of, we describe here 1 single validator that gossipsub calls back to - and we control the order of
@@ -122,7 +121,10 @@ const GossipsubParameters = GossipSubParams( | |||
type | |||
WakuRelayResult*[T] = Result[T, string] | |||
WakuRelayHandler* = proc(pubsubTopic: PubsubTopic, message: WakuMessage): Future[void] {.gcsafe, raises: [Defect].} | |||
WakuValidatorHandler* = proc(pubsubTopic: PubsubTopic, message: WakuMessage): Future[ValidationResult] {.gcsafe, raises: [Defect].} |
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.
WakuValidatorHandler* = proc(pubsubTopic: PubsubTopic, message: WakuMessage): Future[ValidationResult] {.gcsafe, raises: [Defect].} | |
WakuValidatorHandler = proc(pubsubTopic: PubsubTopic, message: WakuMessage): Future[ValidationResult] {.gcsafe, raises: [Defect].} |
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 believe this should be public so other protocols may use this to better describe the handlers
@@ -710,61 +710,6 @@ suite "Waku rln relay": | |||
msgValidate3 == MessageValidationResult.Valid | |||
msgValidate4 == MessageValidationResult.Invalid | |||
|
|||
asyncTest "should validate invalid proofs if bandwidth is available": |
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.
Ooh what a pitty. Why we are removing that? I am happy with it although not fully understanding the test logic ;P
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.
yep, any reason why removing it? having some coverage for validateMessage
is good.
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.
this pr also removes the bandwidth constraint validator, which should be a separate validator!
Kind of agree but its a bit more complex than that. While rln is very coupled with relay, they are still kind of separate things. I would be happy to "merge" both since I don't conceive relay without rln, but not sure everyone agrees. Until we agree on this, 1. would be blocked. Same applies to 3.
|
Thanks for the answers @alrevuelta ! |
trying to upstream this vacp2p/nim-libp2p#945 so perhaps we can simplify this PR. Our case would be the |
Even without the upstream change, I quite like explicitly decoupling "Waku Validators" from the internal relay validators. This is exactly because validators rely so much on application-specific configuration, decisions and ordering.
Don't quite agree. The validation internals is not part of relay protocol. It exists exactly because the application (in this case the Waku Node) has knowledge about message validity that is not available (and should not be available) to the relay protocol. In other words, validators are a mechanism for the application to pass down validation knowledge (which belongs to them) to the relay protocol. See for example this discussion on message processing in the gossipsub spec:
|
I like this idea - this way the application (wakunode2) defines the validators for waku relay, in the order it wants. reduces dependency issues too. so I guess we have to define the "minimum validation" for waku_relay, which could be the waku message decoding. |
Indeed, but even that could in theory be on the "node" layer - relay shouldn't necessarily have to know it's passing around |
Lets try to wrap this up this PR. Not sure if we can upstream the feature of sequential validators see so don't want to block this PR :) |
Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com>
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.
minor comment, looking almost ready.
@rymnc As far as I understand we must ensure that addValidator
is called always before subscribe.
Otherwise the wrapped validator created with generateOrderedValidator
won't contain the ones added later.
This behaviour is ok, but can we ensure that addValidator
is not called after subscribe()
is called? So that we can avoid people adding a validator that is not really applied.
# add the ordered validator to the topic | ||
if not w.validatorInserted.hasKey(pubSubTopic): | ||
procCall GossipSub(w).addValidator(pubSubTopic, w.generateOrderedValidator()) | ||
w.validatorInserted[pubSubTopic] = true |
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.
this seems important right?
not sure I understand "ensure that nwaku/waku/waku_relay/protocol.nim Lines 217 to 241 in 893ddf5
it is called before subscribe 🤔 |
00c36ee
to
e97a38a
Compare
You can find the experimental image built from this PR at
|
@rymnc mm the
That validator wont be executed right? So its added but it never "reaches" gossipsub |
I think it will still be executed since the seq of validators is not copied, and it will always access them from WakuNode.wakuValidators |
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!
Description
Important
This PR modifies waku_relay code and must be reviewed strictly :)
Maybe we should run it in waku-simulator?
nim-libp2p does not order the execution of validators
https://github.com/status-im/nim-libp2p/blob/66f9dc9167f5ba8e5b6867be54f3e63052b93797/libp2p/protocols/pubsub/pubsub.nim#L520-L526
but for our validators (signedTopicValidator, Rln), we need to guarantee order of execution. This PR sets the foundation
for ordering the validators (they should all be appended sequentially)
Changes
--rln-relay-bandwidth-threshold
)WakuMessage
's instead of nim-libp2pMessage
's (thereby saving the extra decoding)Issue
closes #1967