Repository navigation
fix(spv): notify wallet after broadcast to update balance immediately - #674
Conversation
After broadcasting a transaction in SPV mode, the upstream dash-spv client does not call process_mempool_transaction() on the local wallet manager. This means spent UTXOs stay unmarked and the wallet balance remains stale until the transaction appears in a mined block (~2.5 min). Add a workaround that calls process_mempool_transaction() and triggers a reconcile signal right after a successful broadcast, so the UI reflects the updated balance immediately. Upstream issue: dashpay/rust-dashcore#487 Co-Authored-By: Claude Opus 4.6 <[email protected]>
📝 WalkthroughWalkthroughThe changes introduce a workaround in the SPV request handler that notifies the wallet after a successful broadcast by calling a new helper function, updating wallet mempool state and optionally signaling reconciliation when the upstream behavior does not invoke the necessary wallet updates. Changes
Sequence DiagramsequenceDiagram
participant Client
participant SPV Handler
participant Wallet
participant Reconcile
Client->>SPV Handler: Request broadcast
SPV Handler->>SPV Handler: Broadcast transaction
SPV Handler->>Wallet: notify_wallet_after_broadcast()
Wallet->>Wallet: process_mempool_transaction(tx)
alt reconcile_tx provided
Wallet->>Reconcile: Signal reconciliation
end
Wallet-->>SPV Handler: Notification complete
SPV Handler-->>Client: Broadcast result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/spv/manager.rs`:
- Around line 1456-1469: Add inline async unit tests in this file covering
notify_wallet_after_broadcast: create an
Arc<AsyncRwLock<WalletManager<ManagedWalletInfo>>> test fixture and a sample
Transaction, then (1) a test that calls notify_wallet_after_broadcast and
verifies the wallet's state changed as expected after
process_mempool_transaction (use WalletManager/ManagedWalletInfo helpers or
mocks), (2) a test that passes Some(mpsc::Sender) as reconcile_tx and asserts
the channel receives the reconcile signal (verify try_send produced a message),
and (3) a test that calls notify_wallet_after_broadcast with reconcile_tx = None
to ensure no panic/regression; mark tests with #[tokio::test] or the appropriate
async test attribute and keep them inline in this .rs file.
Summary
process_mempool_transaction()on the local wallet manager so spent UTXOs are marked immediately and balance updates in the UI without waiting for a block (~2.5 min)TODO(workaround)for easy removal once fixed upstreamDetails
When broadcasting a transaction in SPV mode, the upstream
dash-spvclient sends the tx to P2P peers but does not notify its ownWalletManager. The sending peer won't receive its own tx back via relay, so the wallet only discovers the transaction when it appears in a mined block.This adds a self-contained workaround:
notify_wallet_after_broadcast()free function — callswallet.process_mempool_transaction(&tx)and fires a reconcile signalspawn_request_handlerafter successful broadcastTest plan
🤖 Generated with Claude Code
🤖 Co-authored by Claudius the Magnificent AI Agent
Summary by CodeRabbit