-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
WebsocketProviderV2 #3048
WebsocketProviderV2 #3048
Conversation
- Allow for establishing a ws connection, leaving it open, and asynchronously sending and receiving messages - Allow for a message stream to endlessly receive messages and pass the responses through result formatters - Added a simple version for ``eth_subscribe`` to ``AsyncEth`` TODO: - Still need to pass responses back through the middleware before the formatters are applied - Refactor everything, it's all a huge mess :P - Typing - Docs around new websocket setup - Docs around ``eth_subscribe`` only being used for persistent websocket connection ... add validation to the method to raise an exception if coming from any other provider maybe? - Implement the validation to ``eth_subscribe`` that will raise an exception if a provider cannot handle subscriptions + add clear messaging for the user - Add tests - Refactor + clean up the transient cache and cache logic - Move methods out of RequestManager? Allow for the provider to handle most of these cases?
- curry the response formatting for easier passing of each middleware response handler method - make the cache class for the PersistentConnectionProvider a ``SimpleCache`` - use classes where appropriate rather than dicts for caching
- DRY the duplicate code in the persistent recv() stream and the singular ws.recv() via ws.send() by using just one AsyncGenerator and returning only the __anext__() item in the singular retrieve. - Some cleanup along the way - Hacky support for subscriptions with params just to test against another subscription ("logs") that isn't "newHeads"
- Huge cleanup on logic - Move certain base class properties into the PersistentConnectionProvider class - Wrap up some of the subscription / caching logic into private methods in the PersistentConnectionProvider
- Add a utility method for seeing if either set in a pair of sets is a subset of the other. This is useful for comparing dict keys with formatters where keys may be missing on either side of the comparison but one is always a subset of the other. - Use this utility method to map to different formatters for parsing subscription response types.
- Create Types for eth_subscription request params and update those in the method signature - Refactor some of the logic around formatting middleware: curry ``_apply_response_formatters()`` rather than creating a whole new method that is basically a curried version of that - lint-roll and fix lint issues - Handle some different caching cases, clear WebsocketProviderV2 cache after disconnecting
- Properly set up logic for eth_unsubscribe - Pop subscription info from cache if successful unsubscribe call with the subscription id
- Fixed some things along the way. Looks liek a lot of the async setup was a bit muddied. It was necessary to create async versions of fixtures for these tests. As this is only an async provider, it wasn't able to steal any informationa at all from the sync tests since it doesn't define a ``w3`` in its module scope. I believe that's the only reason the other async tests are working.
d53a9c0
to
d2207b6
Compare
60baabe
to
7e91981
Compare
b5f1d4c
to
aba9105
Compare
This is ready for an initial review... sorry for the PR size here 😔 cc: @DefiDebauchery |
aba9105
to
5dc90b5
Compare
5dc90b5
to
8b46197
Compare
- Add web3.providers.websocket.rst to .gitignore
- Add web3.providers.websocket.rst to .gitignore - Put back formatters for eth_getCode / remove unnecessary ``compose()`` - Add read-friendly comment splitting Web3 from AsyncWeb3 in main.py - Use correct class name in docstring - Friendlier message when exception is raised connecting to websocket endpoint - Friendlier message for websocket restricted_kwargs; use a merge of default + provided websocket_kwargs with the provided values taking precedence - Validate "ws://" / "wss://" in websocket endpoint
064d410
to
b798960
Compare
- Add web3.providers.websocket.rst to .gitignore - Put back formatters for eth_getCode / remove unnecessary ``compose()`` - Add read-friendly comment splitting Web3 from AsyncWeb3 in main.py - Use correct class name in docstring - Friendlier message when exception is raised connecting to websocket endpoint - Friendlier message for websocket restricted_kwargs; use a merge of default + provided websocket_kwargs with the provided values taking precedence - Validate "ws://" / "wss://" in websocket endpoint
b798960
to
054bcf1
Compare
- Add web3.providers.websocket.rst to .gitignore - Put back formatters for eth_getCode / remove unnecessary ``compose()`` - Add read-friendly comment splitting Web3 from AsyncWeb3 in main.py - Use correct class name in docstring - Friendlier message when exception is raised connecting to websocket endpoint - Friendlier message for websocket restricted_kwargs; use a merge of default + provided websocket_kwargs with the provided values taking precedence - Validate "ws://" / "wss://" in websocket endpoint - Use Dict[str, Any] for websocket_kwargs type
054bcf1
to
62366e9
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.
🚢 Nothing stands out in my mind, lgtm! Will be curious to see adoption feedback and see if there are challenges migrating to v2.
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 looks good to me from a code perspective! I'll take some time on Monday to play around with the UI. It'll be awesome to get this in!
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 nit on the docs, but looks great otherwise!
8787e4f
to
871ce94
Compare
- Add web3.providers.websocket.rst to .gitignore - Put back formatters for eth_getCode / remove unnecessary ``compose()`` - Add read-friendly comment splitting Web3 from AsyncWeb3 in main.py - Use correct class name in docstring - Friendlier message when exception is raised connecting to websocket endpoint - Friendlier message for websocket restricted_kwargs; use a merge of default + provided websocket_kwargs with the provided values taking precedence - Validate "ws://" / "wss://" in websocket endpoint - Use Dict[str, Any] for websocket_kwargs type
What was wrong?
Related to Issue #2880
WebsocketProvider
doesn't keep an open connection and doesn't allow for subscription supporteth_subscribe
How was it fixed?
Features:
eth_subscribe
(andeth_unsubscribe
) supportUsage (from the docs added):
Todo:
EthereumTesterProvider
/ eth-tester based core testsCute Animal Picture