Skip to content

fix(spv): notify wallet after broadcast to update balance immediately - #674

Merged
lklimek merged 1 commit into
v1.0-devfrom
fix/spv-broadcast-wallet-notify
Mar 3, 2026
Merged

lklimek merged 1 commit into
v1.0-devfrom
fix/spv-broadcast-wallet-notify

Conversation

@lklimek

@lklimek lklimek commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • After SPV broadcast, call 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)
  • Workaround for upstream bug dashpay/rust-dashcore#487 — clearly marked with TODO(workaround) for easy removal once fixed upstream

Details

When broadcasting a transaction in SPV mode, the upstream dash-spv client sends the tx to P2P peers but does not notify its own WalletManager. 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 — calls wallet.process_mempool_transaction(&tx) and fires a reconcile signal
  • Called from spawn_request_handler after successful broadcast
  • 3 TODO comments reference the upstream issue for tracking

Test plan

  • Send core-to-core transaction in SPV mode
  • Verify wallet balance updates immediately after broadcast (not after block)
  • Verify receiving wallet shows incoming tx after block confirmation
  • Verify no duplicate balance updates when the tx later appears in a block

🤖 Generated with Claude Code

🤖 Co-authored by Claudius the Magnificent AI Agent

Summary by CodeRabbit

  • Bug Fixes
    • Improved wallet state synchronization following successful transaction broadcasts. The wallet now properly updates mempool information and reconciliation data, ensuring accurate account balances and transaction history.

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]>
@coderabbitai

coderabbitai Bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
SPV Wallet Broadcast Notification
src/spv/manager.rs
Introduces new async helper function notify_wallet_after_broadcast() that updates wallet mempool state via process_mempool_transaction() and optionally signals reconciliation after successful SPV broadcast. Integrates this helper into the SPV request handler path.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 A broadcast sent through the SPV sky,
Now wallet whispers, "Mempool, don't be shy!"
With reconcile's gentle nudge complete,
State synchronization is oh-so-sweet! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding wallet notification after SPV broadcast to update balance. It matches the primary objective of immediately notifying the wallet after broadcast.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/spv-broadcast-wallet-notify

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75d05c8 and cd61c0a.

📒 Files selected for processing (1)
  • src/spv/manager.rs

Comment thread src/spv/manager.rs Resolved
@lklimek
lklimek merged commit 7451ae2 into v1.0-dev Mar 3, 2026
5 checks passed
@lklimek
lklimek deleted the fix/spv-broadcast-wallet-notify branch March 3, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant