Skip to content

Conversation

@t00ts
Copy link
Contributor

@t00ts t00ts commented Jan 5, 2026

Every query method (get_chain, get_starknet_state, etc.) currently creates a new WebSocket connection, uses it once, and discards it. This was OK when we were using http, but for ws it seems quite wasteful.

On my first attempt to solve this, I tried establishing the connection in the EthereumClient::new() method, which meant having an async constructor.

This worked, but it cascaded heavily through the entire codebase. A bunch of test helpers had to bcome async, context builders, etc.

I have this in a separate branch if anyone wants to check it out. But I just felt it was too much of a change for something that was supposed to be an internal optimization.

So, yanked it all, started again, this time going for lazy initialization of the connection, keeping new() sync and failing later if the connection couldn't be established.

We now have

  1. sync_and_listen which for simplicity and isolation I decided to leave alone.
  2. A shared connection/provider stored in Arc<RwLock<Option<WsProvider>>> for all the query methods.

@t00ts t00ts marked this pull request as ready for review January 5, 2026 09:00
@t00ts t00ts requested a review from a team as a code owner January 5, 2026 09:00
@t00ts t00ts force-pushed the t00ts/ethereum-provider branch from 5651df1 to 0328d08 Compare January 5, 2026 11:38
@t00ts t00ts force-pushed the t00ts/ethereum-provider branch from 0328d08 to df18313 Compare January 5, 2026 11:39
@t00ts t00ts merged commit 5392641 into main Jan 6, 2026
8 checks passed
@t00ts t00ts deleted the t00ts/ethereum-provider branch January 6, 2026 05:38
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.

4 participants