Skip to content

Wallet: add consistency check on wallet transactions stored on wallet database when loading the wallet. - #35163

Closed
Luquitasjeffrey wants to merge 2 commits into
bitcoin:masterfrom
Luquitasjeffrey:issue34599
Closed

Luquitasjeffrey wants to merge 2 commits into
bitcoin:masterfrom
Luquitasjeffrey:issue34599

Conversation

@Luquitasjeffrey

Copy link
Copy Markdown

Fixes: #34599
When loading a corrupted wallet database there exists the chance where the transaction state is inconsistent. For example, in the wallet database a parent transaction could appear to be inactive while the child transaction was confirmed (of course that makes no sense, in the blockchain both transactions are confirmed). As a result, when the wallet attempts to abandon inactive transactions, it raises an assertion error.
To fix the problem, if when loading the wallet it encounters an inconsistent transaction state, it will return NEED_RESCAN as db errors, because, it is not usable a wallet that has inconsistent transaction state.

  • Adds a new test case in wallet_tests.cpp: test_crash_corrupt_wallet_abandon

@DrahtBot

DrahtBot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35115 (wallet: fix abandon crash on inconsistent state by tony-ku)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • [TxStateConfirmed{m_node.chainman->ActiveChain()[1]->GetBlockHash(), 1, 0}] in src/wallet/test/wallet_tests.cpp
  • [TxStateConfirmed{block_child.GetHash(), 101, 1}] in src/wallet/test/wallet_tests.cpp

2026-04-27 04:17:21

Comment thread src/wallet/walletdb.cpp
if (it != pwallet->mapWallet.end()) {
const CWalletTx& ptx = it->second;
if (wtx.isConfirmed() && !ptx.isConfirmed()) {
result = DBErrors::NEED_RESCAN;

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.

Question: Should these assignments preserve any more severe load error already stored in result?

Since DBErrors is severity-ordered, and this function already tracks the worst result via std::max, a plain assignment to DBErrors::NEED_RESCAN could silently overwrite a more severe error already stored in result. Would result = std::max(result, DBErrors::NEED_RESCAN) be safer here?

@dergoegge

Copy link
Copy Markdown
Member

This PR looks LLM generated, without real understanding from the author.

LLM generated unit tests are not great for proving the existence of bugs, as LLMs can abuse the access to internal state to produce the wanted results.

Please write a functional test that demonstrates the bug, as that would at least increase the confidence in the LLMs analysis.

@achow101

Copy link
Copy Markdown
Member

I'm closing this PR as it is clearly LLM generated and there is no evidence that the author understands the mechanism of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wallet: Assertion !wtx.isConfirmed() failed

5 participants