-
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
feat: HTTP REST API: Filter support v2 #1890
Conversation
@jm-clius : Please check if the interface is ok. Also a remark to https://rfc.vac.dev/spec/12/ |
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.
Added some comments :)
ede943b
to
80158ee
Compare
652cf8f
to
18c2953
Compare
Hi, @jm-clius, @Ivansete-status, @SionoiS Please review this PR, I intend to be the finalized Filter V2 - Rest API interface. @SionoiS I would like to ask your special attention on Autoshard part of legacy filter and filter v2 adaptation. I hope I can apply it carefully while rebasing/merging. Also I would like to discuss to apply some more test cases on sub/unsub using sharding. WDYT? |
You can find the image built from this PR at
Built from dbdc197 |
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 for the PR!
I'm adding a bunch of reviews so that you can start checking it. Tomorrow morning I will study this PR again, and potentially add more comments
Cheers
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
See comments but nothing major.
Sorry, it was my bad to screw up zerokit submodule commit while doing the rebase. Not it is fixed and align with master. |
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.
Not approving yet because of comment:
- blocking: question below re need for internal and external caches or message handlers. I think we can simplify this PR and the node logic if we remove this for now.
Another non-blocking comment, as this really relates to autosharding:
have commented on the autosharding PRs, but I think we need to simplify what we require of the node's API here. For example, I see loads of replication in the logic between the subscribe and unsubscribe - such as mapping contentTopics to pubsubTopic, contentTopic pairs using the parseSharding
method, which I imagine can be handled as helper methods within the sharding modules. I think we need to follow this up with PRs that simplify waku_node.nim
(perhaps the async queue work that @SionoiS has opened does exactly this - will still review).
Btw, especially if a PR remains open for quite some time, it's helpful to "resolve" older comments that are no longer relevant or that you've addressed. This way when a reviewer comes back to the PR it's easy to navigate through the history and see what has been resolved and what is still to be addressed. :) |
|
||
let remotePeerRes = parsePeerInfo(peer) | ||
if remotePeerRes.isErr(): | ||
error "Couldn't parse the peer info properly", error = remotePeerRes.error |
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 that we should enhance in the future is to make the waku_node
trace the minimum possible (or nothing ideally)
From my point of view, we should always deal with Result[T]
types and leave the traces for the upper layers. There shouldn't be any trace/log in waku_node
. wdyt about this statement @jm-clius ?
waku/node/rest/filter/handlers.nim
Outdated
|
||
let req: FilterUnsubscribeRequest = decodedBody.value() | ||
|
||
let peerOpt = node.peerManager.selectPeer(WakuFilterCodec) |
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.
Doesn't this select a random peer?
When unsubscribing we should use the same peer than for subscribing no?
@jm-clius , @Ivansete-status , @SionoiS All of you found this part questionable. I expected about it but would like to come up with some sort of solution. Unlike realy's and legacy filte's approach where we add message callback per subscription, FilterV2 changes it to one global handler to be provided by its user at creation. So it makes it a bit more difficult to provide it at the stage of creation. Maybe less flexible. So for easy use, I gave an option to handle it internally for the app level and give a generic caching of received messages from the push by the filter service peer. I feel both option a bit limiting the app level possibilities and not that consistent. But for shorthand solution we may think it is enough that app level provides a handler for the messages pushed and do what it wants about it. Noticing here the discussion just recently popped out on discord that it may needs a bit wider thinking where - what layer - to provide any guaranties over messages delivered to the light client. I agree it is clumsy as now it is, so some fix is necessary. Wdyt? |
Right, I see your point. I still wouldn't add an intermediate handler and cache though, as it provides functionality which is only really needed by the API. In this case the API has some application-like requirements of how the pushed messages should be handled, but cannot effect this as it is not responsible for creating the |
Seams like the simplest thing to do for now would be what @jm-clius wrote. Allow registering handlers in |
@Ivansete-status @jm-clius Note: I tried different approaches, but was not happy with them. So I went back the approach used with Filter v1, and providing callback at subscribe. So does rest interface is extended as well with get message for V2. Note2.: I will see if ci goes ok and check if needs any further action. Note3.: I did not rebased again for ease your review now for better compare against previous. |
You can find the experimental image built from this PR at
|
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.
Right, I would really like to approve and thanks for your patience with this, but I don't quite see the benefit of introducing complex subscription management logic into the filter protocol. What particular benefit does this provide above the far simpler approach of adding handlers to the client object itself? Perhaps I'm missing part of the picture here, so happy to set a call to clear this up.
@Ivansete-status @jm-clius |
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.
It looks really great in general! Good job!
However, I've added a few nitpicks and a comment where I suggest to submit a separate PR to refactor the waku/waku_filter/client.nim
file.
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've requested some changes. After they are implemented I'll be ready to approve the rest of this PR. :) I think it will be too much overhead to change this now, but there could have been a great many individual PRs here. For complex PRs, even basic refactoring (such as changing line lengths) should be split into separate PRs. The API handlers and types could be a PR separate from the actual integration with the node, etc. I know this has been mentioned before, but since then the PR has still grown quite a bit.
waku/node/waku_node.nim
Outdated
return | ||
proc filterUnsubscribe*(node: WakuNode, | ||
pubsubTopic: Option[PubsubTopic], | ||
contentTopics: Option[seq[ContentTopic]], |
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 don't think this should be an Option
. seq[ContentTopic]
can be empty, but that would result in an err
returned by the underlying client protocol. We don't want to build much logic into waku_node
belonging to underlying protocols - it simply exists to mount, integrate and expose a common API for underlying protocols. The exception here is that we do provide autosharding "middleware" in the waku_node
- in other words, logic to populate the pubsubTopic
if absent from API calls. But even this should probably be extracted to another module. The waku_node
should in theory just provide a filterSubscribe
, filterUnsubscribe
and filterUnsubscribeAll
- not interpret certain API calls as one or the other based on added logic.
77f88f8
to
1734cf0
Compare
I needed to rebase to latest master to kick in ci checks, hence I did a squash (that would be done anyway by GH). |
@jm-clius, @Ivansete-status :
|
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.
Happy with the changes now. Good job. :) Let's get this merged! Thanks for your patience.
I do think all relevant observations are answered or fixed. I'm not pretty sure which one is signed by GH as change requested though.
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 and for the patience! 💯
…eeded Filter rest api documentation updated with v1 and v2 interface support. Separated legacy filter rest interface Fix code and tests of v2 Filter rest api Filter v2 message push test added Small enhancment on Makefile. 'make list' will list all targets defined Applied autoshard to Filter V2 Fix of PR review comments - removed unnecessary defaults, long lines, added rest filter tests to all tests Fix PR findings: Redesigned FilterPushHandling, code style, catch up apps and tests with filter v2 interface changes Fixed broken interface effect in exemples, warning elimination Rename of FilterSubscriptionsRequest (Filter Rest API schema type) to FilterSubscribeRequest Rename of FilterV1SubscriptionsRequest to FilterLegacySubscribeRequest, fix broken chat2 app, fix tests Changed Filter v2 push handler subscription to simple register Fix PR styling foundings
8791875
to
880d018
Compare
Description
WIP PR to allow pre-check.
Changes
Tracks
#1872