Review report

core: PR #35731

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

1 major finding · 2 suggestions

Findings

Link

[major] · A block-file flush error leaves the coins tip ahead of the active chain

A local block or undo file flush failure can leave in-memory chainstate inconsistent and trigger an assertion; production impact on kernel applications is unconfirmed.

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

Details and suggested fix

ConnectTip() flushes its block view into CoinsTip() before calling FlushStateToDisk(IF_NEEDED), and updates m_chain only afterward. If the block or undo file flush fails, the error return leaves CoinsTip() at the new block while m_chain remains at its parent. DisconnectTip() has the same ordering. The resulting inconsistency can trigger an assertion in bitcoind during the same call if the block confirms a mempool transaction spending a coinbase output. It can also trigger an assertion when a later ActivateBestChain() retries the still-candidate block. This second case applies to a libbitcoinkernel application that logs flush_error and continues; no checked-in kernel embedding that does so was identified, so impact on kernel applications is unconfirmed. The failure requires a local block or undo file flush I/O error that peers or RPC clients cannot cause. In the base version, the failure was only logged and ConnectTip() completed with consistent in-memory state. Keep the tip coherent on this path. For example, after a failed IF_NEEDED flush, skip the block-index and coins writes, return success so ConnectTip() or DisconnectTip() completes, and retry the flush later. Switching only to FatalError would not prevent the assertions. Restarting recovers from the last successful flush.


Optional improvements

Link

[suggestion] · The flush-error notification guarantee covers only file-sequence flush failures

A future failure path in FlushBlockFile() that bypasses FlushFile() could return an error without sending the notification that the caller assumes has already been sent.

Location: src/node/blockstorage.cpp:750 (head).

Details and suggested fix

FlushFile() sends flushError() when FlatFileSeq::Flush() fails, and both current file flushes use it. But FlushBlockFile() collects failures in a success boolean, which FlushChainstateBlockFile() passes through. A future failure branch that skips FlushFile() would let FlushStateToDisk() return an error without notifying bitcoind, so it would not call AbortNode(). The new tests cover only the two current failure sources. Should the guarantee cover every failure reaching FlushStateToDisk()? If so, emit the notification at that return site and clarify which layer owns it. FindNextBlockPos() and WriteBlockUndo() ignore the return value, so they still need notification at the leaf; notifying at both levels would report the error twice in bitcoind, where both flushError() and fatalError() call AbortNode(). Otherwise, narrow the stated guarantee to file-sequence flush failures.


Link

[suggestion] · The flush-failure test does not check persisted block-index or coins state

Moving the error return below WriteBlockIndexDB() would leave the test passing even though block-index metadata had been written.

Location: src/test/chainstate_write_tests.cpp:129 (head).

Details and suggested fix

The test checks the return value, exit status, and m_last_flushed_block, but not the persisted block-index or coins state. FlushStateToDisk() writes block-index metadata with WriteBlockIndexDB() before the coins write and marker update. Record persisted state before mineBlocks(1) and verify it remains unchanged after the failed flush. For example, compare chainstate.CoinsDB().GetBestBlock() with old_flushed->GetBlockHash(), and compare the affected file's CBlockFileInfo read through m_blockman.m_block_tree_db->ReadBlockFileInfo(). Keep the existing marker check because indexes depend on it separately.


Coverage details