Skip to content

Wallet: Keep transaction removal indexes consistent - #1927

Draft
reubenyap wants to merge 1 commit into
masterfrom
codex/wallet-tx-deletion-indexes-20260829
Draft

Wallet: Keep transaction removal indexes consistent#1927
reubenyap wants to merge 1 commit into
masterfrom
codex/wallet-tx-deletion-indexes-20260829

Conversation

@reubenyap

Copy link
Copy Markdown
Member

PR intention

Fix direct wallet transaction deletion so mapWallet, wtxOrdered, mapTxSpends, setWalletUTXO, and cached balances remain consistent.

This is a standalone fix from #1896. It does not change AbandonTransaction. Because #1896 has not merged, this PR includes the minimal MarkDirty() calls needed after successful deletion; that is the only intended overlap and may require conflict resolution if #1896 lands first.

Code changes brief

  • Add one shared in-memory removal operation used by EraseFromWallet and ZapSelectTx.
  • Remove only spend-index entries owned by the deleted transaction, preserve surviving child and competing-spender edges, remove deleted outputs, and restore owned parent outputs only when no active wallet spend remains.
  • Commit selected database erasures as one transaction before applying matching memory changes.
  • Add regression coverage for both entry points, ordered pointers, conflicts, competing spenders, parent spendability and balances, surviving child edges, further transaction insertion, reload consistency, and database failure.

Validation:

  • On the unpatched pinned base, the focused suite failed 39 assertions across all 3 cases.
  • cmake --build build-removal --target test_firo -j4
  • test_firo.exe --run_test=wallet_tx_removal_tests --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT
  • test_firo.exe --run_test=wallet_tests --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT
  • test_firo.exe --run_test=spark_wallet_tests --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT
  • cmake --build build-removal --target firod firo-cli -j4
  • python qa/rpc-tests/importprunedfunds.py --nocleanup
  • git diff --check

All patched commands passed on Windows MinGW. The RPC test used --nocleanup only to avoid the framework's Windows open-log cleanup error. Python 3.12 used pinned pyasyncore==1.0.5 because the legacy test framework imports the removed standard-library module.

Limitation: database failure coverage injects transaction-start failure. It does not artificially inject a mid-erase or commit failure.

Clean derived wallet indexes before erasing a CWalletTx, and commit batched database deletions before applying matching memory changes. Add coverage for both removal entry points, competing spends, balances, reloads, ordered pointers, and database failure.
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

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