feat(ethereum): reuse provider on query methods #3164
Merged
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.
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 anasyncconstructor.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
sync_and_listenwhich for simplicity and isolation I decided to leave alone.Arc<RwLock<Option<WsProvider>>>for all the query methods.