validation: avoid partial override of non-valid validation state

bitcoin/bitcoin: PR #36792

Review failed during source verification.

Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Error-state propagation and fatal reporting were deliberately separate operations. The 2015 refactor removed CValidationState::Abort() and introduced an AbortNode(state, ...) helper that first logged, displayed an error and requested shutdown, then called state.Error(). FlushStateToDisk database-write failures and its runtime-error handler used that helper.

This establishes a historical basis for flush failures returning Error after reporting a fatal condition. It does not make Error itself proof of notification: the reporting guarantee comes from the failure path and helper, not from the validation-state type.

Source 1

The historical motivation for propagating fatal flush failures was persistence consistency, not merely diagnostic presentation. #27866 explained that continuing to write the block index after block or undo flushing failed could leave database references to data not safely on disk. Its original proposal relied on FlushStateToDisk already producing abort errors, but later discussion explicitly deferred the new early return there.

This explains why flush failure reporting and error-conveying returns belong together, while also limiting the historical claim: #27866 documents the intended direction, not the introduction of every current FlushStateToDisk failure path.

Source 1 · Source 2 · Source 3

Ralph's inferences

For an initially valid state, the pinned DisconnectTip implementation supports a local 'already reported' invariant: its block-read and DisconnectBlock failures return false without setting Error; the state-bearing failure path is FlushStateToDisk. That function reports low-disk-space and runtime failures through FatalError(), and its block/undo flush failure explicitly says the specific error was already reported through flushError() before setting Error.

This is the strongest supported answer to the assignment: an Error from this path identifies an already-reported unrecoverable flush failure, but does not necessarily mean that the callback named fatalError() was emitted. The proposed suppression relies on this call-path invariant rather than a universal property of Error states.

The caller's independent fatal-reporting responsibility is to cover disconnect failures that have not already reported an error. The pinned base explains that inability to disconnect during normal operation is a local-system failure and that the node should abort rather than remain on a lower-work chain.

This explains why the valid-state failure path still needs fatal handling. Failure to undo the current chain must not silently prevent following the most-work chain; avoiding a repeated notification on the Error path does not remove that separate responsibility.