Review report

bitcoin/bitcoin: PR #35646

1 minor finding · 3 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Reorg disconnect flush failures no longer raise fatalError

Kernel clients that treat flush_error as non-fatal can miss the unrecoverable-error signal when a required reorg-disconnect flush fails.

Location: src/validation.cpp:3288 (head).

Details and suggested fix

After DisconnectBlock succeeds, DisconnectTip flushes its local view into CoinsTip before the IF_NEEDED disk flush and updates m_chain only afterward. If that flush writes because of critical cache usage or pruning and a block/undo-file flush fails, RaiseFlush calls only flushError. This branch now propagates the token instead of also raising fatalError("Failed to disconnect block."), as before. The C adapter returns the same -1 used for other processing failures, so a kernel client that logs flush_error but relies on fatal_error to stop can continue with mismatched coins and chain tips. Retrying the disconnect would hit the best-block assertion. Record which notification the token represents and escalate a flush-only token once when it aborts a disconnect, without repeating fatalError for Raise-created tokens. Add a reorg failure-injection test checking propagation and callback counts. Bitcoind still shuts down on either callback. No production occurrence was identified.


Optional improvements

Link

[suggestion] · Fatal-error callback comments omit flushError

ProcessNewBlock can return a FatalError after only flushError fires, contrary to comments that direct callers and kernel embedders solely to fatalError.

Location: src/validation.h:1281 (head).

Details and suggested fix

The block and undo flush helpers use FatalError::RaiseFlush, which calls only flushError. FlushStateToDisk and activation propagate that token to ProcessNewBlock without calling fatalError. The C adapter keeps flush_error and fatal_error separate, so an embedder registering only the documented fatal_error callback can miss the diagnostic and receive only the generic -1 result. Describe the already-fired notification as the corresponding fatalError or flushError, and name both channels in the BlockChecked and kernel block_checked comments. Align the retained AcceptBlock flush comment too. FatalError's class comment already documents this distinction; notification behavior itself does not need to change.


Link

[suggestion] · Fatal-submission tests miss submitblock's RPC error branch

The fixture only exercises BlockTemplateManager::SubmitBlock, so it does not protect submitblock's new RPC_VERIFY_ERROR result after a fatal failure, including one following a valid BlockChecked notification.

Location: src/test/validation_block_tests.cpp:116 (head).

Details and suggested fix

The RPC has its own if (!res) branch before consulting the state catcher, but none of these three failure-injection cases invokes it. In AFTER_CHECK, the catcher already holds a valid state when the periodic flush fails. Without the RPC error check, BIP22ValidationResult would return null, as at base; BLOCK_WRITE and UNDO_WRITE would instead fall through to "inconclusive" at head. Parameterize the fixture by submission entry point and invoke submitblock through the RPC table with the fixture's node context. Assert RPC_VERIFY_ERROR and the propagated message for all three failures, keeping AFTER_CHECK under its existing non-Windows guard. Retain the mining-interface assertions for false, "inconclusive", and the debug diagnostic because that contract intentionally differs.


Link

[suggestion] · TestBlockValidity exposes an unreachable FatalError alternative

Keeping Expected for a currently impossible fatal outcome adds four unreachable caller branches and an unnecessary Mining::checkBlock error contract.

Location: src/node/interfaces.cpp:1006 (head).

Details and suggested fix

TestBlockValidity always calls ConnectBlock with fJustCheck=true. That disables the CheckBlock merkle check that can produce BLOCK_MUTATED and returns before WriteBlockUndo, the other FatalError source. Earlier checks return validation states, including witness rejections. The validation.h comment explicitly retains Expected for hypothetical future errors, but today that spreads dead handling across MinerImpl::checkBlock, BlockAssembler::CreateNewBlock, generateblock, and proposal-mode getblocktemplate. Keep TestBlockValidity returning BlockValidationState and unwrap once inside it, using NONFATAL_UNREACHABLE on the error branch to enforce the present invariant. This preserves validation diagnostics and cache behavior while removing the four handlers and the extra checkBlock contract. Revisit the return type if a fatal source becomes reachable.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.