#34371 wallet: allow importprunedfunds for spending transactions

full analysis

https://github.com/bitcoin/bitcoin/pull/34371 · 8144225309 · +36/-20 in 3 files, 1 commits · labels: Wallet

Goal

  • Allow pruned wallet users to re-import transactions that spend from the wallet
  • Prevents inaccurate wallet balances after using removeprunedfunds

Updates `importprunedfunds` to accept transactions that spend from the wallet in addition to transactions that fund it. This is done by routing the import check through `AddToWalletIfInvolvingMe()`, which inspects both `IsMine` and `IsFromMe`, rather than duplicating `IsMine` checks in the RPC. A functional test is added to verify importing a spending transaction that has no outputs returning to the wallet.

Problem: Users of pruned wallets who use `removeprunedfunds` and attempt to re-import transactions spending from the wallet are rejected with an error ('No addresses in wallet correspond to included transaction'), leaving the wallet reporting an incorrect balance.

Category: Wallet (#33 of 84)

P3 · bug fix

  • P3 because it fixes an accounting bug that leads to incorrect balances in pruned wallets
  • Restores correct balances for users re-importing spending transactions
  • Impact is localized to a specialized RPC command

Fixes a wallet accounting bug where spending transactions cannot be re-imported into pruned wallets (#21647), leading to inaccurate balances. The fix has clear value and correctness benefits for wallet users on pruned nodes, but is reasonably deferrable as `importprunedfunds` is a specialized RPC.

Membership: Modifies src/wallet/rpc/backup.cpp, src/wallet/wallet.h, and wallet functional tests to change transaction import behavior.

Factors: security/stability 0, bug 2, performance 0, user value 2, leverage 0

Reviewability: Ready

  • Ready for review: branch is up to date, passes CI, and only an optional test comment remains

The branch applies cleanly to master, passes CI, and all blocking review suggestions have been implemented. The only open review comment is an explicitly optional test enhancement.

Author status: active; rebased on master after conflict resolution in wallet.h

Open concerns:

  • Optional test suggestion from Bicaru20 to assert balance equality before and after remove/import

Resolved concerns:

  • achow101 requested avoiding `subtractfeefromamount` and explicitly specifying UTXOs in the functional test
  • davidgumberg suggested calling `AddToWalletIfInvolvingMe()` directly from wallet logic instead of duplicating checks in the RPC handler

Agreement: Strong

  • Strong agreement on the fix and implementation
  • Confirmed it accomplishes the goal and fixes UTXO tracking (Bicaru20)
  • Approval of the updated approach and test coverage (achow101)
  • Advised moving wallet logic into core wallet code rather than RPC (davidgumberg)

Strong: ACKs from achow101 and Bicaru20; architectural suggestion from davidgumberg incorporated.

Both achow101 and Bicaru20 have ACKed the approach and implementation. The change from an RPC-side check to using AddToWalletIfInvolvingMe addressed davidgumberg's review.

  • achow101 ACKed commit 72186b7697
  • Bicaru20 re-ACKed c2da52d366 noting the PR accomplishes its goal and fixes UTXO tracking
  • davidgumberg pointed out business logic should live in CWallet rather than RPC, which the author adopted

Review verdicts (DrahtBot): 1 (+1)

Files

File list not available for this run.

Card

This PR fixes a bug in `importprunedfunds` where spending transactions without wallet outputs are rejected, causing pruned wallets to show incorrect balances (issue #21647). It replaces the RPC's manual `IsMine` check with a call to `AddToWalletIfInvolvingMe`, which handles both incoming and outgoing wallet transactions. The change is supported by maintainers and reviewers (achow101, Bicaru20) with no unresolved objections. It is ready for final review and merge.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:50, confidence high, input hash db1735d68b12739f