Skip to content

Comments

wallets: Fix locks held up for too long #1505

Merged
naps62 merged 3 commits intomainfrom
fix-locks-2
Nov 26, 2025
Merged

wallets: Fix locks held up for too long #1505
naps62 merged 3 commits intomainfrom
fix-locks-2

Conversation

@naps62
Copy link
Member

@naps62 naps62 commented Nov 26, 2025

Follow up to #1504

Copilot AI review requested due to automatic review settings November 26, 2025 16:45
@naps62 naps62 added the B-bugfix Something is working again label Nov 26, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_wallet and get_current_wallet helper functions to reduce lock scope
  • Removed lifetime parameters from SignMessage and SignMessageBuilder structs
  • 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 Wallets read lock across an await point (get_current_address().await), which contradicts the PR's goal of reducing lock duration. Consider using ethui_wallets::get_current_wallet().await helper function to release the lock earlier, similar to the pattern in eth_sign at 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 Wallets read lock across an await point (get_current_address().await), which contradicts the PR's goal of reducing lock duration. Consider using ethui_wallets::get_current_wallet().await helper function to release the lock earlier, similar to the pattern in eth_sign at 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 Wallets read lock across an await point (get_current_address().await), which contradicts the PR's goal of reducing lock duration. Consider using ethui_wallets::get_current_wallet().await helper function to release the lock earlier, similar to the pattern in eth_sign at 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.

@naps62 naps62 merged commit c76d4e0 into main Nov 26, 2025
13 of 14 checks passed
@naps62 naps62 deleted the fix-locks-2 branch November 26, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-bugfix Something is working again

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant