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

feat: HTTP REST API: Filter support v2 #1890

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

NagyZoltanPeter
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter commented Aug 7, 2023

Description

WIP PR to allow pre-check.

  • Add support for Waku Filter v2 specification on Rest API interface.
  • Integrate use of v2 filter into node.

Changes

  • Updated openapi.yaml doc for v1 and v2 support
  • Separation of legacy filter rest api
  • Add client interface for v2 filter rest api
  • Add handler for processing v2 rest requests
  • Integrate v2 filter into node
  • Add tests for v2
  • Extend tests with failure cases
  • Rebased to latest master with applied autoshard feat on FilterV2 subscribe/unsubscribe

Tracks

#1872

@NagyZoltanPeter NagyZoltanPeter self-assigned this Aug 7, 2023
@NagyZoltanPeter NagyZoltanPeter linked an issue Aug 7, 2023 that may be closed by this pull request
3 tasks
@NagyZoltanPeter
Copy link
Contributor Author

NagyZoltanPeter commented Aug 7, 2023

@jm-clius : Please check if the interface is ok.

Also a remark to https://rfc.vac.dev/spec/12/
RequestId is mandatory part of the communication, but can't really see the use of it.
Rather I would add a subscription key that is generated by the peer and can identify it when sending subsequent updates or deletes to its subscription. So to avoid unintended modification (and discovery) to peers subscription data by knowing only the peer_id. Such a key could be stored on service side. What do you think?

@NagyZoltanPeter NagyZoltanPeter changed the title HTTP REST API: Filter support v2 - WIP feat: HTTP REST API: Filter support v2 - WIP Aug 7, 2023
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

Added some comments :)

waku/v2/node/rest/filter/openapi.yaml Outdated Show resolved Hide resolved
waku/v2/node/rest/filter/openapi.yaml Outdated Show resolved Hide resolved
waku/v2/node/rest/filter/openapi.yaml Outdated Show resolved Hide resolved
waku/v2/node/rest/filter/openapi.yaml Outdated Show resolved Hide resolved
waku/v2/node/rest/filter/openapi.yaml Outdated Show resolved Hide resolved
@NagyZoltanPeter NagyZoltanPeter force-pushed the feat-1851-http-rest-api-filter-v2 branch from ede943b to 80158ee Compare August 23, 2023 13:52
@NagyZoltanPeter NagyZoltanPeter changed the title feat: HTTP REST API: Filter support v2 - WIP feat: HTTP REST API: Filter support v2 Aug 25, 2023
@NagyZoltanPeter NagyZoltanPeter force-pushed the feat-1851-http-rest-api-filter-v2 branch 2 times, most recently from 652cf8f to 18c2953 Compare August 29, 2023 09:06
@NagyZoltanPeter
Copy link
Contributor Author

Hi, @jm-clius, @Ivansete-status, @SionoiS

Please review this PR, I intend to be the finalized Filter V2 - Rest API interface.
Although there are number of changes in the protocol level, but mainly about conversion of types.

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

@github-actions
Copy link

github-actions bot commented Aug 29, 2023

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:1890

Built from dbdc197

@NagyZoltanPeter NagyZoltanPeter marked this pull request as ready for review August 29, 2023 09:33
Copy link
Collaborator

@Ivansete-status Ivansete-status left a 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

Makefile Outdated Show resolved Hide resolved
apps/wakunode2/app.nim Outdated Show resolved Hide resolved
apps/wakunode2/app.nim Outdated Show resolved Hide resolved
apps/wakunode2/app.nim Outdated Show resolved Hide resolved
waku/node/rest/filter/handlers.nim Outdated Show resolved Hide resolved
waku/node/rest/filter/handlers.nim Show resolved Hide resolved
waku/node/rest/filter/handlers.nim Outdated Show resolved Hide resolved
waku/node/rest/filter/handlers.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
Copy link
Contributor

@SionoiS SionoiS left a 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.

tests/wakunode_rest/test_rest_filter.nim Show resolved Hide resolved
tests/wakunode_rest/test_rest_filter.nim Show resolved Hide resolved
tests/wakunode_rest/test_rest_filter.nim Show resolved Hide resolved
tests/wakunode_rest/test_rest_filter.nim Show resolved Hide resolved
tests/wakunode_rest/test_rest_filter.nim Show resolved Hide resolved
waku/node/rest/filter/openapi.yaml Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
@NagyZoltanPeter
Copy link
Contributor Author

Sorry, it was my bad to screw up zerokit submodule commit while doing the rebase. Not it is fixed and align with master.
Thanks for pointing out @Ivansete-status

Copy link
Contributor

@jm-clius jm-clius left a 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).

Makefile Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
@jm-clius
Copy link
Contributor

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
Copy link
Collaborator

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 ?


let req: FilterUnsubscribeRequest = decodedBody.value()

let peerOpt = node.peerManager.selectPeer(WakuFilterCodec)
Copy link
Contributor

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?

@NagyZoltanPeter
Copy link
Contributor Author

@jm-clius , @Ivansete-status , @SionoiS
Hereby I would like to come to conclusion on approach mounting
Filter V2 client vs. legacy one.

All of you found this part questionable. I expected about it but would like to come up with some sort of solution.
Mostly because it derives from the same question the led to SP's cache handling proposal.

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.
Maybe a bit better abstraction could be more handy / happy to discuss /.

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?

@jm-clius
Copy link
Contributor

FilterV2 changes it to one global handler to be provided by its user at creation.

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 filterClient. This indeed points out a flaw in the architecture. My suggestion here would be to change the filter client to have a list of global push handlers rather than just one set at creation and to expose an addPushHandler()-like method. This way applications can add handlers to an already-mounted filter client. The API should then add a push handler that populates a cache and expose a read function that returns the cached messages to REST clients (and clears the cache). This is to provide a polling mechanism via REST, similar to what we have for JSON-RPC API. WDYT?

@SionoiS
Copy link
Contributor

SionoiS commented Aug 31, 2023

Seams like the simplest thing to do for now would be what @jm-clius wrote.

Allow registering handlers in filterClient. Rest API register handlers for caches. APPs can also register handlers.

@NagyZoltanPeter
Copy link
Contributor Author

@Ivansete-status @jm-clius
I've done with fixing the findings (do hope).
Please re-check it as the filter push handling involved quite number of change also in interfaces.

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.

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

You can find the experimental image built from this PR at

quay.io/wakuorg/nwaku-pr:1890-experimental

Copy link
Contributor

@jm-clius jm-clius left a 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.

@NagyZoltanPeter NagyZoltanPeter marked this pull request as draft September 6, 2023 12:35
@NagyZoltanPeter
Copy link
Contributor Author

@Ivansete-status @jm-clius
Although I'm now finished with all fixes and catch ups where tests / examples / chat app were broken I have put back to draft while I will make agreed changes with Hanno.
We discussed to shoot for a simpler less restrictive interface on FilterPushHandling, while keep the possibility of poll messages through REST API if.
It means, it will be not necessary to add handler per subscription but apart from that.
I will notice you when ready. But /health endpoint has now higher prio first.

@NagyZoltanPeter NagyZoltanPeter marked this pull request as ready for review September 12, 2023 08:21
Copy link
Collaborator

@Ivansete-status Ivansete-status left a 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.

examples/filter_subscriber.nim Outdated Show resolved Hide resolved
tests/wakunode_rest/test_rest_filter.nim Outdated Show resolved Hide resolved
waku/node/rest/filter/client.nim Show resolved Hide resolved
waku/node/rest/filter/handlers.nim Outdated Show resolved Hide resolved
waku/node/rest/filter/handlers.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Show resolved Hide resolved
waku/node/waku_node.nim Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/node/waku_node.nim Outdated Show resolved Hide resolved
waku/waku_core/subscription.nim Outdated Show resolved Hide resolved
Copy link
Contributor

@jm-clius jm-clius left a 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 Show resolved Hide resolved
return
proc filterUnsubscribe*(node: WakuNode,
pubsubTopic: Option[PubsubTopic],
contentTopics: Option[seq[ContentTopic]],
Copy link
Contributor

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.

waku/node/waku_node.nim Outdated Show resolved Hide resolved
@NagyZoltanPeter
Copy link
Contributor Author

I needed to rebase to latest master to kick in ci checks, hence I did a squash (that would be done anyway by GH).

@NagyZoltanPeter
Copy link
Contributor Author

@jm-clius, @Ivansete-status :
Please look at the final stage of this long long running PR.
Last changes:

  • Addressed interface change on waku_node, introduced filterUnsubscribeAll.
  • It involves changes on Rest interface, new endpoint added: /filter/v2/subscriptions/all with HTTP DELETE.

Copy link
Contributor

@jm-clius jm-clius left a 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.

@NagyZoltanPeter NagyZoltanPeter dismissed Ivansete-status’s stale review September 14, 2023 09:03

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.

Copy link
Collaborator

@Ivansete-status Ivansete-status left a 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! 💯

NagyZoltanPeter and others added 3 commits September 14, 2023 20:32
…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
@NagyZoltanPeter NagyZoltanPeter merged commit dac072f into master Sep 14, 2023
16 checks passed
@NagyZoltanPeter NagyZoltanPeter deleted the feat-1851-http-rest-api-filter-v2 branch September 14, 2023 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: HTTP REST API: Filter support v2
4 participants