mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
validation: avoid partial override of non-valid validation state #36792
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36792
Loading…
Reference in a new issue
No description provided.
Delete branch "2611-validationstate-reason-overwrite"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
ValidationState::Error() only sets the reject reason if the state is still valid. When it is called on a state that is already Invalid or Error, the mode changes but the earlier reason, result and debug message are kept. The result is a mix of the old and new error. Code review in #35570 found two places where this happens. This makes the in-and-out use of the state parameter harder to follow and to remove later.
This PR makes both cases explicit:
ConnectBlock()→CheckBlock()with a mutated block (BLOCK_MUTATED, e.g. a merkle root mismatch). This is treated as a sign of corruption and reported throughFatalError(), but the resulting Error state keptBLOCK_MUTATED/bad-txnmrklroot. Now the Invalid state is logged and then replaced, so the Error state carries the corruption message.ActivateBestChainStep()→DisconnectTip()→FlushStateToDisk()failure.FlushStateToDisk()has already reported a fatal error, andActivateBestChainStep()then calledFatalError()a second time with a less specific message. Now the existing error is logged and returned unchanged, and no second fatal error is reported.Behavior changes:
The first commit adds a unit test for case 1 that captures the current behavior, and the second commit updates its expectations. Case 2 has no test, because a flush failure cannot be triggered without fault injection. The path where
DisconnectTip()fails while the state is still valid is covered byfeature_abortnode.pyand is unchanged.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
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.
🔵 Suggestion · Flush-only failures lose their sole
fatalError()notificationA block-file flush failure during disconnection now sends only
flush_error;bitcoindstill shuts down, but the kernel callback category changes rather than merely losing a duplicate notification.Location:
src/validation.cpp:3302(head).🔵 Suggestion ·
DisconnectTip()'s already-error return lacks targeted coverageThe abort-node, direct flush-failure, and new mutated-block tests cannot detect restoration of the unconditional
FatalError()here; adapting the existing flush-failure injection to a reorg remains unconfirmed.Location:
src/validation.cpp:3303(head).Review coverage was incomplete.
Reviewed:
becd5c27a77a· Review report · Previous reportspermalink
tACK
b4b95702bBuilt PR head
b4b95702bon macOS. Allvalidation_block_testspass.Also ran a mutation check by restoring the pre-fix
validation.cpp(89bd6a3a6) while keeping the new test.connectblock_mutated_block_is_fatal_errorfails as expected because the corruption message is missing from the debug log. With the fix restored, it passes.Case 2 (
ActivateBestChainStep) is not covered by a test in this PR. FromDisconnectTip():Valid.DisconnectBlock()failure: state remainsValid.FlushStateToDisk()failure: state becomesError.Thanks for checking, that's true, known. The Valid-state path (DisconnectBlock failure) is exercised by
feature_abortnode.py, and its behavior is unchanged. The Error-state path needsFlushStateToDisk(IF_NEEDED)to both decide to write and then fail (low disk space, a block-file flush error, or an exception from the coins DB), and none of these can be injected in tests today. I prefer not to add fault-injection scaffolding in this PR, but I'm happy to do it as a follow-up if reviewers think it's worth it.The PR description already contains: "Case 2 has no test, because a flush failure cannot be triggered without fault injection."
🐙 This pull request conflicts with the target branch and needs rebase.
Non-contentious rebase (due to #36109), no other changes.
(
git range-diff f12cc4a..b4b9570 3e4c803..becd5c2git range-diff b4b9570...becd5c2)