simplify MutWallet - #4689
Conversation
|
Claude finished @MartinquaXD's task in 1m 11s —— View job PR Review: simplify
|
| // note that [`Arc::make_mut()`] will never perform a deep clone because | ||
| // we never give out clones of the inner `Arc` and we take a | ||
| // write lock in this function which gives us exclusive access. |
There was a problem hiding this comment.
The claim "we never give out clones of the inner Arc" isn't strictly accurate anymore: sign_transaction_from does Arc::clone(self.0.read().unwrap().deref()) (line 89). So if a sign_transaction_from future is in flight while register_signer runs, the strong count is >1 and Arc::make_mut will deep-clone here.
That's harmless for correctness (make_mut deep-clones precisely so the mutation stays isolated), but the comment's absolute wording is misleading. Per the PR description all signers are registered up-front before any signing, so this doesn't happen in practice — worth softening the comment to say the deep clone only happens if a sign is concurrently in flight, which shouldn't occur given the registration-at-startup usage.
There was a problem hiding this comment.
Hmm, true. Because you can't extract the inner wallet from the returned future the worst that could happen is a deep clone in register_signers but we can't run into the scenario where we have multiple MutWallet instances flying around that have different sets of signers. That would be a real headache to debug.
There was a problem hiding this comment.
@claude check that the updated comment is fully accurate.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Description
alloy's
EthereumWallethas some&mut selfmethods which make it a bit awkward to work with when multiple parties should have access to the same wallet.This presented some challenges in terms of making it work in the current_thread runtime which is the default for tokio tests. The implementation chosen at the time spawns a new runtime and blocks on that. However, the
block_in_placecall shows up very prominently in flamegraphs which suggests it has a ton of overhead.Changes
Replace the
tokio::sync::RwLockwithstd::sync::RwLockwhich makes all the tokio runtime shenanigans unnecessary.RwLockshould in practice never block because once we set up all the signing keys at the start all methods only need to take a read lock so starving the tokio runtime is not an issue.How to test
existing tests should still pass