2 suggestions
Optional improvements
[suggestion] · Flush-only failures lose their sole fatalError() notification
A block-file flush failure during disconnection now sends only flush_error; bitcoind still shuts down, but the kernel callback category changes rather than merely losing a duplicate notification.
Location: src/validation.cpp:3302 (head).
Details and suggested fix
FlushChainstateBlockFile() reports failure through flushError(), then FlushStateToDisk() returns state.Error(...) without calling FatalError(). The base's unconditional call here supplied the only fatalError() notification on that path. The new early return suppresses it. The kernel interface distinguishes flush errors from unrecoverable fatal errors, and the C API forwards them to separate callbacks. At this point, DisconnectTip() has already applied the disconnected view to CoinsTip() but returns before m_chain.SetTip().
InvalidateBlock() and periodic flushing already propagate flush-only failures, so retaining this behavior is defensible. If that is intended, update the message for becd5c27a77ad5fa4bda2de3ebed4a906d007857 and the PR description to acknowledge that this path loses its only fatal notification. Explain at the branch that the failure was already reported through either fatalError() or flushError(), rather than describing every case as duplicate fatal reporting.
[suggestion] · DisconnectTip()'s already-error return lacks targeted coverage
The 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).
Details and suggested fix
feature_abortnode.py removes rev00000.dat, so DisconnectBlock() fails while state remains valid and exercises the unchanged FatalError() fallback. chainstate_flush_failure_boundary replaces a block file with a directory, but calls FlushStateToDisk(FORCE_FLUSH) directly. The new mutated-block test calls only ConnectBlock(). Add a reorg test through ActivateBestChain() that checks failed activation, the preserved flush error, and notification counts: one flushError() and no fatalError() for the block-file failure. The existing directory substitution is a starting point, not a confirmed complete fixture. Reaching the IF_NEEDED write requires a critical coins cache or a prune flush, and the disconnected block and undo data must remain readable, so the injected failure needs to target a different block file.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Earlier refactoring work explicitly recognized that reusing a validation state preserves an existing failure reason rather than replacing it. Its stated motivation included eliminating ambiguity about input/output state and unintuitive interactions between successive calls—not asserting that each Error() call produces fresh error metadata.
This establishes the preservation behavior as an existing API contract callers must account for. It explains why the affected conversions cannot be understood as ordinary replacement of the entire validation outcome, although it does not establish why preservation was originally chosen.
Historical discussion distinguishes an already-reported flush failure from a fatalError notification. In #35646, the author explained that a FlushChainstateBlockFile() failure propagated through FlushStateToDisk() had already fired flushError(); reporting it through the fatal-error wrapper would call AbortNode() again and change the notification category, whose shutdown behavior depends on m_shutdown_on_fatal_error.
The important contract is propagation of an already-handled local failure, not necessarily prior delivery of the specific fatalError notification. This bears directly on the DisconnectTip() path: avoiding repeated reporting and preserving the original notification category are distinct from interpreting IsError() as proof that fatalError was called.
Ralph's inferences
The precise preservation contract is mode escalation without metadata replacement: Error() always sets M_ERROR, sets the supplied reject reason only when previously valid, and leaves the result and debug message untouched. Thus Invalid-to-Error and Error-to-Error preserve the earlier metadata. This is not a universal first-failure-wins rule, because Invalid() itself writes new metadata.
This is the contract underlying the mutated-block conversion. Replacing the state with a fresh instance changes the metadata contract explicitly; merely calling Error() on the existing Invalid state does not replace its invalidity details.
An Error state is not intrinsically evidence of notification or shutdown. Error() only changes state data, whereas FatalError() separately invokes notifications.fatalError() before calling Error(). In the inspected base DisconnectTip(), assuming a valid incoming state, the only explicit failure path receiving that state is FlushStateToDisk(); block-read and DisconnectBlock failures return false without setting it. Any already-notified guarantee therefore belongs to the flush path and notification implementation, not to IsError() itself.
The narrow answer is not an unconditional guarantee: an Error propagated from DisconnectTip() must be interpreted using its producer's contract. The historical flush discussion supports prior handling, including a path that had already called AbortNode(), but specifically warns that this need not have been a fatalError notification. The uninspected pinned flush and notification implementations prevent a complete shutdown guarantee.