Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the wallet access patterns to minimize lock contention by reducing the duration that read locks on the Wallets global state are held. The changes introduce helper functions that encapsulate the pattern of acquiring a lock, cloning data, and immediately releasing the lock, rather than holding locks across await points.
- Introduced
find_walletandget_current_wallethelper functions to reduce lock scope - Removed lifetime parameters from
SignMessageandSignMessageBuilderstructs - Changed wallet storage from references to owned values throughout the codebase
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/wallets/src/lib.rs | Added helper functions find_wallet and get_current_wallet that clone wallet data before releasing locks |
| crates/rpc/src/methods/sign_message.rs | Removed lifetime parameters and changed to store owned Wallet instead of reference |
| crates/rpc/src/methods/send_transaction.rs | Refactored to use new helper functions and reduced lock scopes with explicit scoping blocks |
| crates/rpc/src/lib.rs | Updated to use new helper functions for wallet access |
| crates/networks/src/lib.rs | Removed outdated comments about lock avoidance patterns |
Comments suppressed due to low confidence (3)
crates/rpc/src/lib.rs:147
- This code holds the
Walletsread lock across an await point (get_current_address().await), which contradicts the PR's goal of reducing lock duration. Consider usingethui_wallets::get_current_wallet().awaithelper function to release the lock earlier, similar to the pattern ineth_signat line 289.
let wallets = Wallets::read().await;
let address = wallets.get_current_wallet().get_current_address().await;
crates/rpc/src/lib.rs:164
- This code holds the
Walletsread lock across an await point (get_current_address().await), which contradicts the PR's goal of reducing lock duration. Consider usingethui_wallets::get_current_wallet().awaithelper function to release the lock earlier, similar to the pattern ineth_signat line 289.
let wallets = Wallets::read().await;
let network = ctx.network().await;
let address = wallets.get_current_wallet().get_current_address().await;
crates/rpc/src/lib.rs:343
- This code holds the
Walletsread lock across an await point (get_current_address().await), which contradicts the PR's goal of reducing lock duration. Consider usingethui_wallets::get_current_wallet().awaithelper function to release the lock earlier, similar to the pattern ineth_signat line 289.
let wallets = Wallets::read().await;
let network = ctx.network().await;
let address = wallets.get_current_wallet().get_current_address().await;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Follow up to #1504