feat: add AsyncEthereumClient mirroring EthereumClient#2523
Open
Uxio0 wants to merge 3 commits into
Open
Conversation
Add an asyncio-based AsyncEthereumClient that mirrors EthereumClient using AsyncWeb3/AsyncHTTPProvider + aiohttp, subclassing the sync client and managers and overriding only I/O so no business logic is duplicated. AsyncMulticall keeps batch_call at full parity with the sync Multicall path (raw revert bytes included). Refactor EthereumClient to extract I/O-free helpers shared by both clients (payload builders, batch-response processing, eth_call decode, tx error mapping, trace selectors, manager builders/formatters). Reuse the sync test suites against the async client via a sync-facade proxy. Fix bugs found during the refactor: - get_total_transfer_history double-counted transfers matching both from/to filters - send_unsigned_transaction returned an empty hash on exhausted retries (now raises) - functools.cache on instance methods leaked instances (per-instance cache + clear_cache)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d0f7c2c57
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an asyncio-based
AsyncEthereumClientthat mirrorsEthereumClient's feature set usingAsyncWeb3/AsyncHTTPProvider+aiohttp, while refactoringEthereumClientso the two share all I/O-free logic instead of duplicating it. Also fixes three bugs found during the refactor.Closes PLA-1596.
Async client
AsyncEthereumClient(EthereumClient)and async managers subclass the sync ones, overriding only the I/O withasync_-prefixed coroutines; every pure helper (payload building, response decoding, tx error mapping, trace selectors, manager builders/formatters) is reused, so no business logic is duplicated.AsyncMulticall(Multicall)overrides only the on-chaineth_call, soasync_batch_call/async_batch_call_same_functionkeep full parity with the sync client: Multicall when available, JSON-RPC batch fallback,force_batch_callhonored, and identical results — including raw revert bytes for failed calls.aiohttpsession withaclose()/async withlifecycle; POA middleware mirrored. Async tracing uses raw JSON-RPC (AsyncWeb3has no.tracing).safe_eth.ethalongsideget_auto_async_ethereum_client.Refactor (EthereumClient / Multicall)
Extracted shared, I/O-free helpers used by both sync and async clients: JSON-RPC payload builders, batch-response processing/validation,
eth_calldecoding, tx error mapping, trace selectors, ERC20/721 builders & formatters, and Multicall result decoding.Bug fixes
get_total_transfer_historydouble-counted a transfer matching both thefromandtofilters — now deduplicated on(transactionHash, logIndex).send_unsigned_transactionreturned an emptyHexBytes("")(looked like success) when retries were exhausted — now raises.functools.cacheon instance methods (get_chain_id,get_client_version,is_eip1559_supported,get_singleton_factory_address) pinned every client instance for the process lifetime — replaced with a per-instance cache +clear_cache().Tests
TestERC20Module,TestTracingManager,TestEthereumClient) are reused against the async client via a smallSyncCallProxy, so the async I/O paths are exercised by the same assertions; only the handful of tests that mock synchronous internals are overridden to target the async equivalent.batch_callparity test (including the revert case).ethereum_client(sync),async_ethereum_client,multicall, and the Safe test base setUp — 114 passed.Notes
requests.Sessionthread-safety,get_balancesnative-balance N+1, and an asyncget_transfer_historyare tracked as follow-ups (PLA-1598, PLA-1599, PLA-1600).