-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Subscription management implementation #3554
base: main
Are you sure you want to change the base?
Conversation
3d06c95
to
828b8b2
Compare
This is ready for a review :) |
23d7f11
to
8644827
Compare
3f355ec
to
21f396d
Compare
I moved to a context-based args management for subscription handlers in order to facilitate custom args to be used within handlers. This is back on a freeze for reviews. |
21f396d
to
3918d63
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 a few ideas for consideration but didn't see anything that sticks out as a showstopper. Nice work!
- ``sx`` -> ``sub``. - Some clarifying changes on type hints and arg names in tests. - Docs update to clarify handlers. This whole area of the docs will get a lot of attention and refactoring in a future PR. But at least the current docs are more descriptive.
4d390dd
to
e10f028
Compare
@kclowes, always good to ask 😅. The relevant API changes only introduce more customization. This shouldn't break the API. And if no handlers are passed in (new feature), you can still listen to free-flowing messages directly from the socket. The typing in the socket stream was already Thoughts on that? |
- ``sx`` -> ``sub``. - Some clarifying changes on type hints and arg names in tests. - Docs update to clarify handlers. This whole area of the docs will get a lot of attention and refactoring in a future PR. But at least the current docs are more descriptive.
e10f028
to
2d4958a
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.
I like this! I didn't have time to go through with a fine tooth comb, but if you feel good about it and the tests, don't let me block your merge 👍
c33d49c
to
39f7b9f
Compare
It has been pretty battle tested but it's causing some irrelevant flaky replace transaction tests to fail pretty consistently, just on CI. I checked against My suspicion is it's not directly related to this PR. Ultimately those tests need to be properly fixed, so that might be what I end up doing in a separate PR. Either way I'll be sure to preserve the current state of the new code (no force pushing on top of the previous commits) so that nothing that you all have reviewed changes. |
7772a9b
to
d23e800
Compare
d23e800
to
461dbd2
Compare
04ab8f4
to
6707be0
Compare
- Make use of a ``TaskReliant`` queue that is specific for handler subscriptions. Put a ``SubscriptionProcessingFinished`` exceptions in the queue to signal when all handler subscriptions have been unsubscribed from. - Add testing around running the ``handler_subscriptions`` method while listening for un-handled subscriptions via the socket. - Create a container to manage all subscriptions, since we store subs in more than one way: by ``id``, by ``label``, etc... - The ``SubscriptionContainer`` class has an object reference, so we changes share this with the provider's ``RequestProcessor`` class. The request_processor can use the container to make decisions about which queue to store the subscription in, based on the presence or absence of a ``handler``.
- Properly cancel and close all tasks for persistent connection provider tests - Clear caches as a cleanup for all persistent connection provider tests
db7049c
to
6b820cb
Compare
- Instead of guessing what the request `id` will be and having to bump this cache key for internal requests, assign a unique cache key to each request. Save these cache keys as a list that can house all cache keys for a request and its internal requests. - Swap this cache key for a cache key generated with the request `id` only after the request `id` is already known. This will prevent any guesswork. This prevents calls being nmade from other tasks from interfering with the request `id` assignment and accidentally bumping the cache key for a request while it is still being processed.
6b820cb
to
9a2c699
Compare
What was wrong?
Related to Issue #3397
Working with many subscriptions is not ideal at the moment. In web3.py v7, we added significant support for
eth_subscribe
via the newPersistentConnectionProvider
implementation. Though we've added support with parity to howwebsockets
works, this still only left us with a raw API to handle messages as they come through the socket. We have JSON-RPC specifications of how subscriptions should be formed and the client returns a uniqueid
per subscription. SincePersistentConenctionProvider
classes are fully asynchronous, as they should be, we should implement an API that can leverage all of this in order to handle subscriptions asynchronously as they come in.How was it fixed?
EthSubscription
class can, and should be encouraged to, have ahandler
function passed to it so that it can properly handle the subscription as it comes in, rather than having the burden of listening and parsing based on messageid
be on the user.w3.eth.subscribe
can now also accept ahandler
kwarg since all subscriptions are managed by the manager under-the-hood. It can also accept anevent
for "logs" subscriptions so that it may be easily parsed by the handler.id
to parse logs.In a separate PR we should add a significant docs overhaul for clearer communication on
PersistentConnectionProvider
usage as well as subscription management usageTodo:
Cute Animal Picture