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

Websockets v2 iterator #3067

Merged
merged 8 commits into from Aug 1, 2023
Merged

Websockets v2 iterator #3067

merged 8 commits into from Aug 1, 2023

Conversation

fselmo
Copy link
Collaborator

@fselmo fselmo commented Jul 28, 2023

PR Summary:

  • Add asynchronous iterator functionality to the AsyncWeb3 with WebsocketProviderV2 via persistent_connection()
  • (bugfix) Fix typing for the optional "full_transactions" boolean param when subscribing to "newPendingTransactions"
  • Split WebsocketProviderV2 tests into asynchronous generator / context manager (async with) and asynchronous iterator (async for) tests
  • Add docs for async iterator setup

Peripheral changes:

  • Add a bit more connection debugging with exponential backoff when connecting via WebsocketProviderV2. Keep re-connection attempts reasonable at 5 for now.
  • Use a better system for the heartbeat / is_connected() method for wsV2, as recommended by the websockets library, use the unsolicited pong call.

Todo:

Cute Animal Picture

Screenshot 2023-07-28 at 16 29 51

- AsyncIterator support: Add ``__aiter__()`` method to ``_PersistentConnectionWeb3`` in order to support infinite websocket connections.
- If we don't care about latency, we should just use an unsolicited pong for the heartbeat:
https://websockets.readthedocs.io/en/stable/reference/asyncio/client.html#websockets.client.WebSocketClientProtocol.pong

- Add a max for connection retries, set a default, and add an exponential backoff rate when attempting to connect.
- Separate the goethereum_ws_v2 tests into a directory with ``AsyncGenerator`` / "async with w3..." style tests and ``AsyncIterator`` / "async for w3..." style tests
@fselmo fselmo marked this pull request as ready for review July 28, 2023 22:30
- Due to the exponential backoff, it is already pretty reasonable to have this number at 5 but more than this might add long wait times. If there is demand, we can open this up to an init arg in the future.
Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

@fselmo fselmo merged commit 65fdaa5 into ethereum:main Aug 1, 2023
84 checks passed
fselmo added a commit that referenced this pull request Aug 1, 2023
@fselmo fselmo deleted the websockets-v2-iterator branch April 3, 2024 20:52
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.

None yet

2 participants