Review report

core: PR #35714

1 minor finding · 1 suggestion

Earlier concerns neither republished nor resolved: 2 major findings · 1 minor finding. See the Run archive for their assessments.

Findings

Link

[minor] · Flush failure leaves the coins tip ahead of the active chain

A local block- or undo-file I/O failure can leave chainstate inconsistent and trigger assertions on later processing; no production occurrence has been observed.

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

Details and suggested fix

If the IF_NEEDED flush in ConnectTip() writes because the coins cache is critical or pruning is required, and FlushChainstateBlockFile() fails, ConnectTip() returns an error after view.Flush() has merged the block into CoinsTip(). It returns before removing the block’s conflicting mempool transactions or updating m_chain.

ActivateBestChainStep() treats this as a system error and calls MaybeUpdateMempoolForReorg(disconnectpool, false). If the mempool contains a transaction from the block, or one that conflicts with it, and that transaction spends a mature coinbase output, the filter reads the spent input from CoinsTip() and hits assert(!coin.IsSpent()).

The tips also remain inconsistent for later processing. A subsequent ActivateBestChain() on this chainstate retries the block and hits assert(hashPrevBlock == view.GetBestBlock()) in ConnectBlock(); a reorg can hit the corresponding assertion in DisconnectTip().

This path sends only flushError, which applications may ignore. bitcoin-chainstate logs the notification and continues calling ProcessBlock(). In bitcoind, the notification requests shutdown, but an ActivateBestChain() call can still run before threads are interrupted. At base, this failure was only logged and ConnectTip() completed. The existing CheckDiskSpace() and runtime_error returns can cause the same divergence, but also send fatalError; this change adds a trigger that sends only flushError.

Keep CoinsTip() and m_chain coherent before returning the error, for example by completing the in-memory tip update when only the durability step failed. The trigger requires a local block- or undo-file I/O failure, and no production occurrence has been observed.


Optional improvements

Link

[suggestion] · The flush-failure test does not check recovery on a later flush

The test does not verify that a later flush, including the shutdown flush, persists the pending state after the injected failure.

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

Details and suggested fix

The injector deletes the block file and replaces it with a directory, and the test ends after the failed FORCE_FLUSH call. Recovery depends on the dirty block-index entries, file info, and coins remaining pending after the early return so a later FlushStateToDisk() can write them. A change that drops this pending state would still pass the test.

Rename the block file aside rather than deleting it, then restore it after the failure assertions. Retry FlushStateToDisk(FlushStateMode::FORCE_FLUSH) with a fresh BlockValidationState. Check that the retry succeeds and that GetLastFlushedBlock(), CoinsDB().GetBestBlock(), and persisted nHeightLast all advance to new_tip. Keep the existing failure assertions.


Coverage details

Earlier concerns

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