validation: return block-file flush errors #35714

Manually merged
l0rinc merged 2 commits from l0rinc/flush-state-failure-boundary into master 2026-10-28 21:22:42 +00:00 AGit
l0rinc commented 2026-07-13 19:37:29 +00:00 (Migrated from github.com)

Problem: When flushing block or undo data fails, FlushStateToDisk() still writes block-index metadata and coins data, then advances m_last_flushed_block.
With a separate -blocksdir, persistent failures there can leave metadata referring to block data that is not durable even when chainstate writes succeed.

Fix: Return the flush error before those writes, leaving the last-flushed marker and on-disk coins tip unchanged in the failing call.
Later flushes can retry and write if they succeed, including during shutdown.
ConnectTip() and DisconnectTip() propagate the error before updating the chain tip, after applying the coins changes in memory.

History:

  • #27866 raised whether saving other state after a flush failure was preferable. This change preserves later retries while skipping writes in the failing call.
  • #34897 introduced m_last_flushed_block to prevent persistent indexes from advancing past flushed chainstate. This fix keeps it at the last successful flush.
**Problem:** When flushing block or undo data fails, `FlushStateToDisk()` still writes block-index metadata and coins data, then advances `m_last_flushed_block`. With a separate `-blocksdir`, persistent failures there can leave metadata referring to block data that is not durable even when chainstate writes succeed. **Fix:** Return the flush error before those writes, leaving the last-flushed marker and on-disk coins tip unchanged in the failing call. Later flushes can retry and write if they succeed, including during shutdown. `ConnectTip()` and `DisconnectTip()` propagate the error before updating the chain tip, after applying the coins changes in memory. **History:** * [#27866](https://github.com/bitcoin/bitcoin/pull/27866#discussion_r1297313148) raised whether saving other state after a flush failure was preferable. This change preserves later retries while skipping writes in the failing call. * [#34897](https://github.com/bitcoin/bitcoin/pull/34897) introduced `m_last_flushed_block` to prevent persistent indexes from advancing past flushed chainstate. This fix keeps it at the last successful flush.
DrahtBot commented 2026-07-13 19:37:37 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK optout21, arejula27, pzafonte, maflcko, ryanofsky
Concept ACK mzumsande

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)
  • #36074 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #35731 (Indexes: Harden the flush-error notification invariant by arejula27)
  • #35307 (blockstorage: keep snapshot base in normal blockfile range by shuv-amp)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35714 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35714.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35714#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [optout21](https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-6032423095), [arejula27](https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-6087324781), [pzafonte](https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-6088698794), [maflcko](https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-6125770424), [ryanofsky](https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5686928219) | | Concept ACK | [mzumsande](https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-4714960377) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc) * [#36074](https://github.com/bitcoin/bitcoin/pull/36074) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36074.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko) * [#35731](https://github.com/bitcoin/bitcoin/pull/35731) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35731.svg"></sub> (Indexes: Harden the flush-error notification invariant by arejula27) * [#35307](https://github.com/bitcoin/bitcoin/pull/35307) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35307.svg"></sub> (blockstorage: keep snapshot base in normal blockfile range by shuv-amp) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
arejula27 commented 2026-07-13 20:13:41 +00:00 (Migrated from github.com)

Concept ACK

I still have to dig into the code and the implications of this change (just did a quick review), but in the meantime: would it be worth adding a test case for the undo-file failure path as well? both the commit message and the error string mention block or undo files, but the test only injects a failure on blk*.dat.

Concept ACK I still have to dig into the code and the implications of this change (just did a quick review), but in the meantime: would it be worth adding a test case for the undo-file failure path as well? both the commit message and the error string mention block or undo files, but the test only injects a failure on blk*.dat.
l0rinc (Migrated from github.com) reviewed 2026-07-14 19:32:43 +00:00
l0rinc (Migrated from github.com) commented 2026-07-14 19:28:18 +00:00

would it be worth adding a test case for the undo-file failure path as well

Good question, thanks - FlushBlockFile() returns false for either block or undo flush failures, see: github.com/bitcoin/bitcoin@e1a337ee96/src/node/blockstorage.cpp (L774-L786)
Since this PR only changes how that shared result is handled, testing both failure sources separately would fit better in a lower-level BlockManager test.

> would it be worth adding a test case for the undo-file failure path as well Good question, thanks - `FlushBlockFile()` returns false for either block or undo flush failures, see: https://github.com/bitcoin/bitcoin/blob/e1a337ee961db4308697de7cddcf4aad9684c7f1/src/node/blockstorage.cpp#L774-L786 Since this PR only changes how that shared result is handled, testing both failure sources separately would fit better in a lower-level `BlockManager` test.
arejula27 commented 2026-07-15 17:19:56 +00:00 (Migrated from github.com)

ACK e1a337ee96
This is a small change, closing a gap discussed at #34897 I built it and tested it locally. I tryied to play around it and I did not find anything wrong.

One small, non-blocking point: the comment // FlushChainstateBlockFile() already emitted the flush-error notification. describes an invariant, but nothing checks it . It is true today only because every false path inside FlushBlockFile()/FlushUndoFile() calls flushError() first. Would be correct adding an assume to verify this behaviour is keep it in the future?:

if (!m_blockman.FlushChainstateBlockFile(m_chain.Height())) {
    // FlushChainstateBlockFile() already emitted the flush-error notification.
    Assume(m_chainman.m_interrupt);
    return state.Error("Failed to flush block or undo file");
}

Also, I want to ask about something I found while testing, not sure if it is related to this PR. FlushStateToDisk() does not check if shutdown was already requested before it starts. I wrote a test where a first flush fails and requests shutdown, then I fix the file and call FlushStateToDisk() again: it succeeds and m_last_flushed_block moves forward, even though shutdown was already requested before this second call. Is this expected? I think it may be needed for the final flush in Shutdown() (init.cpp), but I am not 100% sure, so I wanted to ask before assuming it is fine

ACK e1a337ee961db4308697de7cddcf4aad9684c7f1 This is a small change, closing a gap discussed at #34897 I built it and tested it locally. I tryied to play around it and I did not find anything wrong. One small, non-blocking point: the comment `// FlushChainstateBlockFile() already emitted the flush-error notification.` describes an invariant, but nothing checks it . It is true today only because every `false` path inside `FlushBlockFile()`/`FlushUndoFile()` calls `flushError()` first. Would be correct adding an assume to verify this behaviour is keep it in the future?: ```cpp if (!m_blockman.FlushChainstateBlockFile(m_chain.Height())) { // FlushChainstateBlockFile() already emitted the flush-error notification. Assume(m_chainman.m_interrupt); return state.Error("Failed to flush block or undo file"); } ``` Also, I want to ask about something I found while testing, not sure if it is related to this PR. `FlushStateToDisk()` does not check if shutdown was already requested before it starts. I wrote a test where a first flush fails and requests shutdown, then I fix the file and call `FlushStateToDisk()` again: it succeeds and `m_last_flushed_block` moves forward, even though shutdown was already requested before this second call. Is this expected? I think it may be needed for the final flush in `Shutdown()` (`init.cpp`), but I am not 100% sure, so I wanted to ask before assuming it is fine
arejula27 commented 2026-07-15 17:36:24 +00:00 (Migrated from github.com)

I opened a follow-up PR https://github.com/bitcoin/bitcoin/pull/35731 i did while reviewing the PR with the intention to group this notify + state.Error() behaviour into one helper, (making the invariant of the comment harder) and add more low-level tests like the ones you mentioned above.

I opened a follow-up PR https://github.com/bitcoin/bitcoin/pull/35731 i did while reviewing the PR with the intention to group this notify + `state.Error()` behaviour into one helper, (making the invariant of the comment harder) and add more low-level tests like the ones you mentioned above.
maflcko (Migrated from github.com) reviewed 2026-07-16 11:36:46 +00:00
maflcko (Migrated from github.com) commented 2026-07-16 11:36:46 +00:00
nit in 0f04fbee2f123c37c4b6fbff7dc10f61dd0b5924: The `&&` make this a bit harder to read and violate https://github.com/bitcoin/bitcoin/pull/35729
mzumsande (Migrated from github.com) reviewed 2026-07-16 14:52:54 +00:00
mzumsande (Migrated from github.com) left a comment

It would be good to discuss the real-world consequences of this change a bit more:

As far as I understand one reason for the status quo is that even if an error would occur, and the data is not durable, there is a good chance of the fsync being done by the OS eventually if the failure is temporary - data is not necessarily lost, so we might as well flush the other state to avoid having to re-do the syncing. If the failure was permanent, the other write operations (chainstate etc.) would likely fail as well, so nothing gets out of sync in that scenario either.

However, one point for this change is that block data is often stored separately (-blocksdir option). In this case, it is quite possible that actually corruption occurs if the blocksdir fsync fails permanently, but flushes of the chainstate etc. all succeed, and BLOCK_HAVE_DATA is set in the blocktree db, while the actual block data is missing.

So I am Concept ACK

It would be good to discuss the real-world consequences of this change a bit more: As far as I understand one reason for the status quo is that even if an error would occur, and the data is not durable, there is a good chance of the fsync being done by the OS eventually if the failure is temporary - data is not necessarily lost, so we might as well flush the other state to avoid having to re-do the syncing. If the failure was permanent, the other write operations (chainstate etc.) would likely fail as well, so nothing gets out of sync in that scenario either. However, one point for this change is that block data is often stored separately (`-blocksdir` option). In this case, it is quite possible that actually corruption occurs if the `blocksdir` fsync fails permanently, but flushes of the chainstate etc. all succeed, and `BLOCK_HAVE_DATA` is set in the blocktree db, while the actual block data is missing. So I am Concept ACK
l0rinc (Migrated from github.com) reviewed 2026-07-16 17:01:35 +00:00
l0rinc (Migrated from github.com) commented 2026-07-16 17:01:35 +00:00

flushed is tied to the state being invalid, it makes more sense to test them in groups, see https://github.com/bitcoin/bitcoin/pull/35729#pullrequestreview-4715961548

If you insist I can remove the state validation here.

`flushed` is tied to the `state` being invalid, it makes more sense to test them in groups, see https://github.com/bitcoin/bitcoin/pull/35729#pullrequestreview-4715961548 If you insist I can remove the `state` validation here.
optout21 (Migrated from github.com) reviewed 2026-08-04 11:04:43 +00:00
optout21 (Migrated from github.com) left a comment

Concept ACK (e1a337ee96)

The change is within FlushStateToDisk, and changes how an error from FlushChainstateBlockFile is handled -- ignored previously, returned upwards with the change.

Build & unit tests verfied locally.

The effectiveness of the new test (i.e., it catches the error) is checked by manually reverting the change.

Analyis of call pattern of FlushChainstateBlockFile: directly called in only one place, the one affected in this change.
Indirectly it is used in several usecases:

  • The chain tip advances (connect/disconnect, including during IBD/reorgs),
  • A new block is accepted to disk,
  • The mempool cache is trimmed after accepting transactions/packages,
  • A user manually prunes via RPC,
  • The coins cache is resized,
  • An assumeutxo snapshot finishes background validation,
  • The node shuts down or an RPC/kernel-API caller explicitly forces a flush.

It's hard to conceptually assess the high-level effects in all the use cases.

Reviewing the steps excluded with the early exit, the update of the m_next_write seems uneqivocal, it may have unintended consequences (left comment).

LGTM, left some comments.

Concept ACK (e1a337ee961db4308697de7cddcf4aad9684c7f1) The change is within `FlushStateToDisk`, and changes how an error from `FlushChainstateBlockFile` is handled -- ignored previously, returned upwards with the change. Build & unit tests verfied locally. The effectiveness of the new test (i.e., it catches the error) is checked by manually reverting the change. Analyis of call pattern of `FlushChainstateBlockFile`: directly called in only one place, the one affected in this change. Indirectly it is used in several usecases: - The chain tip advances (connect/disconnect, including during IBD/reorgs), - A new block is accepted to disk, - The mempool cache is trimmed after accepting transactions/packages, - A user manually prunes via RPC, - The coins cache is resized, - An assumeutxo snapshot finishes background validation, - The node shuts down or an RPC/kernel-API caller explicitly forces a flush. It's hard to conceptually assess the high-level effects in all the use cases. Reviewing the steps excluded with the early exit, the update of the `m_next_write` seems uneqivocal, it _may_ have unintended consequences (left comment). LGTM, left some comments.
optout21 (Migrated from github.com) commented 2026-08-04 10:24:01 +00:00

0f04fbe test: characterize writes after flush failure:

Unit test observation: Running all 781 unit tests, they all pass, but a single output line is printed on the output:
Error: A fatal internal error occurred, see debug.log for details: Flushing block file to disk failed. This is likely the result of an I/O error.
This is noted as this is the only stdout printout from the whole unit test suite. It is emitted from the new unit test (chainstate_flush_failure_boundary -> 2ns call to FlushStateToDisk -> FlushChainstateBlockFile -> FlushBlockFile.)
Any chance to suppress this?

> [0f04fbe](https://github.com/bitcoin/bitcoin/pull/35714/changes/0f04fbee2f123c37c4b6fbff7dc10f61dd0b5924) _test: characterize writes after flush failure_: Unit test observation: Running all 781 unit tests, they all pass, but a single output line is printed on the output: `Error: A fatal internal error occurred, see debug.log for details: Flushing block file to disk failed. This is likely the result of an I/O error.` This is noted as this is the only stdout printout from the whole unit test suite. It is emitted from the new unit test (`chainstate_flush_failure_boundary` -> 2ns call to `FlushStateToDisk` -> `FlushChainstateBlockFile` -> `FlushBlockFile`.) Any chance to suppress this?
optout21 (Migrated from github.com) commented 2026-08-04 10:28:19 +00:00

0f04fbe test: characterize writes after flush failure:

Why not simply BOOST_CHECK(flushed); BOOST_CHECK(state.IsValid()); ?

> [0f04fbe](https://github.com/bitcoin/bitcoin/pull/35714/changes/0f04fbee2f123c37c4b6fbff7dc10f61dd0b5924) _test: characterize writes after flush failure_: Why not simply `BOOST_CHECK(flushed); BOOST_CHECK(state.IsValid());` ?
optout21 (Migrated from github.com) commented 2026-08-04 10:55:18 +00:00

e1a337e validation: stop writes after flush failure:

With this early exit, the update of m_next_write below is also skipped. It looks like that may cause some unwanted side-effects, so maybe it should be kept (e.g. by storing the return value, skipping the steps to be skipped, and keeping the if (should_write || m_next_write == ... block).

> [e1a337e](https://github.com/bitcoin/bitcoin/pull/35714/changes/e1a337ee961db4308697de7cddcf4aad9684c7f1) _validation: stop writes after flush failure_: With this early exit, the update of `m_next_write` below is also skipped. It looks like that _may_ cause some unwanted side-effects, so maybe it should be kept (e.g. by storing the return value, skipping the steps to be skipped, and keeping the `if (should_write || m_next_write == ...` block).
optout21 (Migrated from github.com) commented 2026-08-04 10:36:31 +00:00

e1a337e validation: stop writes after flush failure:

Why is the LogWarning removed? I could not convince myself that the fatalError()/state.Error() calls include the same logging. Is it possible to preserve the log line?

At first I though that the added comments refers to the reason of removal of LogWarning, but then I realized it explains the usage of state.Error() instead of FatalError().

Regarding the comment, FlushChainstateBlockFile indeed calls KernelNotifications::flushError whenever it returns false, but this is handled across two levels (FlushUndoFile), which is a bit too brittle.

> [e1a337e](https://github.com/bitcoin/bitcoin/pull/35714/changes/e1a337ee961db4308697de7cddcf4aad9684c7f1) _validation: stop writes after flush failure_: Why is the `LogWarning` removed? I could not convince myself that the `fatalError()`/`state.Error()` calls include the same logging. Is it possible to preserve the log line? At first I though that the added comments refers to the reason of removal of `LogWarning`, but then I realized it explains the usage of `state.Error()` instead of `FatalError()`. Regarding the comment, `FlushChainstateBlockFile` indeed calls `KernelNotifications::flushError` whenever it returns `false`, but this is handled across two levels (`FlushUndoFile`), which is a bit too brittle.
l0rinc (Migrated from github.com) reviewed 2026-08-09 01:14:04 +00:00
l0rinc (Migrated from github.com) left a comment

Thanks for the review, took me a bit longer to react, I'm juggling a few open ones...

Thanks for the review, took me a bit longer to react, I'm juggling a few open ones...
l0rinc (Migrated from github.com) commented 2026-08-07 20:59:59 +00:00

Good point, added ASSERT_DEBUG_LOG, which suppresses the expected output and verifies the lower-level error message. It fixes it for me, can you please check it? Added you as coauthor.

Good point, added `ASSERT_DEBUG_LOG`, which suppresses the expected output and verifies the lower-level error message. It fixes it for me, can you please check it? Added you as coauthor.
l0rinc (Migrated from github.com) commented 2026-08-07 20:59:33 +00:00

Yes, I could also do that, but that would assume that I find it likely that they will fail independently, and since I don't, I consider it just noise.

Yes, I could also do that, but that would assume that I find it likely that they will fail independently, and since I don't, I consider it just noise.
l0rinc (Migrated from github.com) commented 2026-08-08 19:02:52 +00:00

I don't think m_next_write should advance after a failed write: the timer update was deliberately moved after the chainstate write in #30611. The lower layer has already requested shutdown, and the final FORCE_FLUSH during shutdown does not depend on the periodic deadline.

I don't think `m_next_write` should advance after a failed write: the timer update was deliberately moved after the chainstate write in [#30611](https://github.com/bitcoin/bitcoin/pull/30611#discussion_r2069273906). The lower layer has already requested shutdown, and the final `FORCE_FLUSH` during shutdown does not depend on the periodic deadline.
l0rinc (Migrated from github.com) commented 2026-08-08 19:01:41 +00:00

The lower layer already reports the specific failure through flushError() before returning false, so restoring this generic warning would duplicate the error. I clarified the comment to make that explicit, let me know if it helps.

3097:2026-08-09T00:59:53.599616Z (mocktime: 2020-08-31T15:34:13Z) [test] [noui.cpp:66] [noui_ThreadSafeMessageBoxRedirect] A fatal internal error occurred, see debug.log for details: Flushing block file to disk failed. This is likely the result of an I/O error.

The [lower layer](https://github.com/bitcoin/bitcoin/blob/fa615bd163ac74c11a8e15ed8513a5b81ed9ef3b/src/node/blockstorage.cpp#L776) already reports the specific failure through `flushError()` before returning `false`, so restoring this generic warning would duplicate the error. I clarified the comment to make that explicit, let me know if it helps. > 3097:2026-08-09T00:59:53.599616Z (mocktime: 2020-08-31T15:34:13Z) [test] [noui.cpp:66] [noui_ThreadSafeMessageBoxRedirect] A fatal internal error occurred, see debug.log for details: Flushing block file to disk failed. This is likely the result of an I/O error.
maflcko (Migrated from github.com) reviewed 2026-08-18 08:32:24 +00:00
maflcko (Migrated from github.com) commented 2026-08-18 08:32:24 +00:00

not important, but it looks like https://github.com/bitcoin/bitcoin/pull/35729 was merged, so it could make sense to follow the style used in src/test/coinscachepair_tests.cpp. Or, if you really want to group them, wrap them in another pair of (). I just mention it to avoid a silent merge conflict with https://github.com/bitcoin/bitcoin/pull/35713 and avoid having to touch this line again after merge.

not important, but it looks like https://github.com/bitcoin/bitcoin/pull/35729 was merged, so it could make sense to follow the style used in `src/test/coinscachepair_tests.cpp`. Or, if you really want to group them, wrap them in another pair of `()`. I just mention it to avoid a silent merge conflict with https://github.com/bitcoin/bitcoin/pull/35713 and avoid having to touch this line again after merge.
l0rinc (Migrated from github.com) reviewed 2026-08-18 17:19:30 +00:00
l0rinc (Migrated from github.com) commented 2026-08-18 17:19:30 +00:00
I gave this exact line as a concrete example for why we shouldn't just blindly split these conditions https://github.com/bitcoin/bitcoin/pull/35729#pullrequestreview-4715961548 Why not fix https://github.com/bitcoin/bitcoin/pull/35713 instead?
optout21 (Migrated from github.com) reviewed 2026-08-19 04:33:52 +00:00
optout21 (Migrated from github.com) commented 2026-08-19 04:55:21 +00:00

Verified, no more output produced, thanks!

Verified, no more output produced, thanks!
optout21 (Migrated from github.com) commented 2026-08-19 04:43:53 +00:00

I see your argument about how unrolling is sub-optimal, but it's a weak one for me.
If you insist, the proper solution may be to create a new macro with 2 (or N) conditions, BOOST_CHECK_ALL, that evaluates the conditions, and if one fails, prints the values of all. After moving away from BOOST it would be easy to add such a macro.

I see your argument about how unrolling is sub-optimal, but it's a weak one for me. If you insist, the proper solution may be to create a new macro with 2 (or N) conditions, `BOOST_CHECK_ALL`, that evaluates the conditions, and if one fails, prints the values of all. After moving away from BOOST it would be easy to add such a macro.
optout21 (Migrated from github.com) commented 2026-08-19 04:33:52 +00:00

Thanks, it makes sense.

Thanks, it makes sense.
optout21 (Migrated from github.com) commented 2026-08-19 04:46:01 +00:00

Very good, thanks.

Very good, thanks.
optout21 commented 2026-09-14 11:41:55 +00:00 (Migrated from github.com)

ACK c42d7fe1cf

Concluding my previous review. Reviewed, built and unit-tested locally. Also verified that without the behavior change, the new test fails.

ACK c42d7fe1cf2aee821b4f9931ef94f16e09de8459 Concluding my previous review. Reviewed, built and unit-tested locally. Also verified that without the behavior change, the new test fails.
First-time contributor

1 minor finding · 3 previous findings

🟠 Minor

Flush failure leaves the coins tip ahead of the active chain

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

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.

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.

Previous reports

Previous reports of the same concern:

  • src/validation.cpp:2784. First reported at 90fd0f15b63e839f9fd81f53ce4fa6a08164283b. Last checked at 12f691cf286ea9a020583d267b94efca102a4056.
  • src/validation.cpp:2784. First reported at 12f691cf286ea9a020583d267b94efca102a4056. Last checked at 12f691cf286ea9a020583d267b94efca102a4056.

Previous findings (3)
[Suggestion · still present] 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.

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.

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

Previous reports of the same concern:

  • src/test/chainstate_write_tests.cpp:129. First reported at 12f691cf286ea9a020583d267b94efca102a4056. Last checked at 12f691cf286ea9a020583d267b94efca102a4056.
  • src/test/chainstate_write_tests.cpp:126. First reported at 12f691cf286ea9a020583d267b94efca102a4056. Last checked at 12f691cf286ea9a020583d267b94efca102a4056.
[Major · still present] A critical flush failure leaves CoinsTip ahead of the active chain

If the critical flush in ConnectTip fails, view.Flush() has already merged the connected block into CoinsTip, but the error return skips removeForBlock() and m_chain.SetTip(). ActivateBestChainStep() then handles the system error by calling MaybeUpdateMempoolForReorg(disconnectpool, false). If the mempool contains a transaction spending a mature coinbase, that check accesses its now-spent input and hits assert(!coin.IsSpent()). More generally, the failure leaves the in-memory coins and active-chain tips inconsistent. Roll back the in-memory changes before returning, or make the chainstate unusable and guard subsequent processing. This trigger requires a local block or undo I/O failure during a critical flush. The checked-in bitcoin-chainstate input loop continues after ProcessBlock returns false, but no concrete production trigger or affected caller was identified.

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

First reported at 12f691cf286ea9a020583d267b94efca102a4056. Last checked at 12f691cf286ea9a020583d267b94efca102a4056.

[Major · still present] A failed prune flush can persist the pruned-state flag without committing pruning

When a flush also prunes files, the code writes the prunedblockfiles flag before attempting the block/undo flush. If that flush continues to fail through the shutdown retry, the error return skips WriteBlockIndexDB() and UnlinkPrunedFiles(). The flag is then recorded even though the persisted block-index metadata was not pruned. On restart, the flag causes startup to reject -prune=0 unless the database is rebuilt with -reindex, although the failed flush did not commit the pruning operation. Defer writing the flag until the prune metadata is committed, or otherwise preserve a consistent retryable state.

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

First reported at 12f691cf286ea9a020583d267b94efca102a4056. Last checked at 12f691cf286ea9a020583d267b94efca102a4056.

Resolved findings
[Suggestion · resolved] Assert that block-index metadata is not persisted after the failed flush

These assertions protect the flushed marker and coins DB tip, but they would also pass if FlushStateToDisk wrote block-index metadata before returning the flush error. Since mining the new block leaves block-index or block-file metadata pending for WriteBlockIndexDB, capture a relevant persisted metadata value before the injected failure and assert it remains unchanged afterward. That would cover the metadata boundary in addition to the coins and marker checks, without changing the expected failure behavior.

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

Fixed. First reported at 90fd0f15b63e839f9fd81f53ce4fa6a08164283b. Last checked at 12f691cf286ea9a020583d267b94efca102a4056. The current test reads the persisted CBlockFileInfo for new_tip->nFile and asserts that nHeightLast is still at old_flushed's height. Mining the new block raised that value in memory and marked it dirty, so the check would fail if WriteBlockIndexDB ran before the early return. That covers the requested assertion on the metadata boundary.

Review coverage was incomplete.


Reviewed: 12f691cf286e · Full review report · Previous reports

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:87bdde6e11c8200ebab55606962dbcbbed1f25d8bebf674c6c6e659db1fe52cc:8f5adaa231eb1aff4d179f52d5ea908b8cc3066455d0b32a1baa87e2b34c9f86 --> <!-- ralph-base:0f27bed5b2924420d65caeca439e6b036d3c6cb2 --> <!-- ralph-head:12f691cf286ea9a020583d267b94efca102a4056 --> <!-- ralph-case:52e59a85a2490b045cbf29a050b96a0f63e1285f85ecae5476057a3f30849232 --> 1 minor finding · 3 previous findings **🟠 Minor** **Flush failure leaves the coins tip ahead of the active chain** Location: [`src/validation.cpp:2784`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2784>) (head). 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. <details> <summary>Details and suggested fix</summary> 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. </details> <details> <summary>Previous reports</summary> Previous reports of the same concern: - src/validation.cpp:2784. First reported at `90fd0f15b63e839f9fd81f53ce4fa6a08164283b`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. - src/validation.cpp:2784. First reported at `12f691cf286ea9a020583d267b94efca102a4056`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. </details> --- <details> <summary>Previous findings (3)</summary> <details> <summary>[Suggestion · still present] The flush-failure test does not check recovery on a later flush</summary> The test does not verify that a later flush, including the shutdown flush, persists the pending state after the injected failure. 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. Location: [`src/test/chainstate_write_tests.cpp:116`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/12f691cf286ea9a020583d267b94efca102a4056/src/test/chainstate_write_tests.cpp#L116>) (head). Previous reports of the same concern: - src/test/chainstate_write_tests.cpp:129. First reported at `12f691cf286ea9a020583d267b94efca102a4056`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. - src/test/chainstate_write_tests.cpp:126. First reported at `12f691cf286ea9a020583d267b94efca102a4056`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. </details> <details> <summary>[Major · still present] A critical flush failure leaves CoinsTip ahead of the active chain</summary> If the critical flush in `ConnectTip` fails, `view.Flush()` has already merged the connected block into `CoinsTip`, but the error return skips `removeForBlock()` and `m_chain.SetTip()`. `ActivateBestChainStep()` then handles the system error by calling `MaybeUpdateMempoolForReorg(disconnectpool, false)`. If the mempool contains a transaction spending a mature coinbase, that check accesses its now-spent input and hits `assert(!coin.IsSpent())`. More generally, the failure leaves the in-memory coins and active-chain tips inconsistent. Roll back the in-memory changes before returning, or make the chainstate unusable and guard subsequent processing. This trigger requires a local block or undo I/O failure during a critical flush. The checked-in `bitcoin-chainstate` input loop continues after `ProcessBlock` returns false, but no concrete production trigger or affected caller was identified. Location: [`src/validation.cpp:2784`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2784>) (head). First reported at `12f691cf286ea9a020583d267b94efca102a4056`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. </details> <details> <summary>[Major · still present] A failed prune flush can persist the pruned-state flag without committing pruning</summary> When a flush also prunes files, the code writes the `prunedblockfiles` flag before attempting the block/undo flush. If that flush continues to fail through the shutdown retry, the error return skips `WriteBlockIndexDB()` and `UnlinkPrunedFiles()`. The flag is then recorded even though the persisted block-index metadata was not pruned. On restart, the flag causes startup to reject `-prune=0` unless the database is rebuilt with `-reindex`, although the failed flush did not commit the pruning operation. Defer writing the flag until the prune metadata is committed, or otherwise preserve a consistent retryable state. Location: [`src/validation.cpp:2784`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2784>) (head). First reported at `12f691cf286ea9a020583d267b94efca102a4056`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. </details> <details> <summary>Resolved findings</summary> <details> <summary>[Suggestion · resolved] Assert that block-index metadata is not persisted after the failed flush</summary> These assertions protect the flushed marker and coins DB tip, but they would also pass if FlushStateToDisk wrote block-index metadata before returning the flush error. Since mining the new block leaves block-index or block-file metadata pending for WriteBlockIndexDB, capture a relevant persisted metadata value before the injected failure and assert it remains unchanged afterward. That would cover the metadata boundary in addition to the coins and marker checks, without changing the expected failure behavior. Location: [`src/test/chainstate_write_tests.cpp:133`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/12f691cf286ea9a020583d267b94efca102a4056/src/test/chainstate_write_tests.cpp#L133>) (head). Fixed. First reported at `90fd0f15b63e839f9fd81f53ce4fa6a08164283b`. Last checked at `12f691cf286ea9a020583d267b94efca102a4056`. The current test reads the persisted CBlockFileInfo for new_tip->nFile and asserts that nHeightLast is still at old_flushed's height. Mining the new block raised that value in memory and marked it dirty, so the check would fail if WriteBlockIndexDB ran before the early return. That covers the requested assertion on the metadata boundary. </details> </details> </details> Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`12f691cf286e`](<https://git.fish.foo/bitcoin/bitcoin/commit/12f691cf286ea9a020583d267b94efca102a4056>) · [Full review report](<https://review.fish.foo/traces/35714-12f691cf286ea9a020583d267b94efca102a4056-1638-4.html>) · [Previous reports](<https://review.fish.foo/traces/35714/>)
pzafonte commented 2026-10-06 15:06:59 +00:00 (Migrated from github.com)

tACK 90fd0f15b6
I'm looking into pruning for the kernel (#35627), which would go through this flush path.

tACK 90fd0f15b6 I'm looking into pruning for the kernel (#35627), which would go through this flush path.
l0rinc commented 2026-10-07 06:13:06 +00:00 (Migrated from github.com)

Added missed coverage found by AI review.

Added missed coverage found by AI review.
optout21 commented 2026-10-07 06:35:25 +00:00 (Migrated from github.com)

reACK 12f691cf28

reACK 12f691cf286ea9a020583d267b94efca102a4056
arejula27 commented 2026-10-09 18:58:03 +00:00 (Migrated from github.com)

reACK 12f691cf28

reACK 12f691cf286ea9a020583d267b94efca102a4056
pzafonte commented 2026-10-09 20:27:17 +00:00 (Migrated from github.com)

reACK 12f691cf28

reACK 12f691cf286ea9a020583d267b94efca102a4056
maflcko commented 2026-10-12 13:58:05 +00:00 (Migrated from github.com)

review ACK 12f691cf28 👟

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 12f691cf286ea9a020583d267b94efca102a4056 👟
YTqlh+73BaoV9+pW0OUpkW8+H0S83QlTnH6G42LPiPC6RSvUtoVEZHtFnQr9Zx4xrcxLkrTN12hbie4ISakhCg==
review ACK 12f691cf286ea9a020583d267b94efca102a4056 👟 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK 12f691cf286ea9a020583d267b94efca102a4056 👟 YTqlh+73BaoV9+pW0OUpkW8+H0S83QlTnH6G42LPiPC6RSvUtoVEZHtFnQr9Zx4xrcxLkrTN12hbie4ISakhCg== ``` </details>
ryanofsky (Migrated from github.com) approved these changes 2026-10-28 20:59:34 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 12f691cf28. Thanks for putting the test first, it makes the behavior change easy to verify.

This reverses my suggestion from https://github.com/bitcoin/bitcoin/pull/27866#discussion_r1297313148 when that PR was trying to make the same change. But that suggestion was mainly based on not wanting to have an unjustified behavior change in a cleanup PR, and now there is a clear justification.

Left some comments below, but none blocking. I think this should be merged given all the review it's had so far.

Code review ACK 12f691cf286ea9a020583d267b94efca102a4056. Thanks for putting the test first, it makes the behavior change easy to verify. This reverses my suggestion from https://github.com/bitcoin/bitcoin/pull/27866#discussion_r1297313148 when that PR was trying to make the same change. But that suggestion was mainly based on not wanting to have an unjustified behavior change in a cleanup PR, and now there is a clear justification. Left some comments below, but none blocking. I think this should be merged given all the review it's had so far.
ryanofsky (Migrated from github.com) commented 2026-10-28 17:27:45 +00:00

In commit "test: characterize writes after flush failure" (07d23eb755)

Optional, could be a follow-up: it would be nice if the test also checked what happens on the next flush after this one fails.

With this PR, when the block file flush fails, FlushStateToDisk() returns without writing the block index or the coins. That data stays in memory, so if the problem clears up before a later FlushStateToDisk() call (say, the open failed because the node ran out of file descriptors), that call writes it. The last chance is normally the flush in Shutdown(). If the problem doesn't clear up, the node stops at the last successful flush and catches up after a restart. The first case isn't tested right now.

Moving the block file aside instead of deleting it lets the test put it back, flush again, and check that everything catches up to new_tip:

--- a/src/test/chainstate_write_tests.cpp
+++ b/src/test/chainstate_write_tests.cpp
@@ -114,5 +114,4 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup)
 BOOST_FIXTURE_TEST_CASE(chainstate_flush_failure_boundary, TestChain100Setup)
 {
-    auto inject_file_open_failure{[](const fs::path& file) { Assert(fs::remove(file)); Assert(fs::create_directory(file)); }};
     auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()};
     BlockValidationState state{};
@@ -124,5 +123,9 @@ BOOST_FIXTURE_TEST_CASE(chainstate_flush_failure_boundary, TestChain100Setup)
     auto* new_tip{WITH_LOCK(::cs_main, return chainstate.m_chain.Tip())};
     BOOST_REQUIRE_NE(old_flushed, new_tip);
-    inject_file_open_failure(WITH_LOCK(::cs_main, return chainstate.m_blockman.GetBlockPosFilename(new_tip->GetBlockPos())));
+    // Move the block file aside and put a directory in its place so the flush fails to open it.
+    const fs::path blk_file{WITH_LOCK(::cs_main, return chainstate.m_blockman.GetBlockPosFilename(new_tip->GetBlockPos()))};
+    const fs::path blk_backup{blk_file + ".bak"};
+    fs::rename(blk_file, blk_backup);
+    Assert(fs::create_directory(blk_file));

     ASSERT_DEBUG_LOG("Flushing block file to disk failed");
@@ -135,4 +138,14 @@ BOOST_FIXTURE_TEST_CASE(chainstate_flush_failure_boundary, TestChain100Setup)
     BOOST_REQUIRE(WITH_LOCK(::cs_main, return chainstate.m_blockman.m_block_tree_db->ReadBlockFileInfo(new_tip->nFile, file_info)));
     BOOST_CHECK_EQUAL(file_info.nHeightLast, old_flushed->nHeight);
+
+    // Once the block file is back, a later flush succeeds and catches up.
+    Assert(fs::remove(blk_file));
+    fs::rename(blk_backup, blk_file);
+    state = {};
+    BOOST_CHECK(chainstate.FlushStateToDisk(state, FlushStateMode::FORCE_FLUSH));
+    BOOST_CHECK_EQUAL(WITH_LOCK(::cs_main, return chainstate.GetLastFlushedBlock()), new_tip);
+    BOOST_CHECK(WITH_LOCK(::cs_main, return chainstate.CoinsDB().GetBestBlock()) == new_tip->GetBlockHash());
+    BOOST_REQUIRE(WITH_LOCK(::cs_main, return chainstate.m_blockman.m_block_tree_db->ReadBlockFileInfo(new_tip->nFile, file_info)));
+    BOOST_CHECK_EQUAL(file_info.nHeightLast, new_tip->nHeight);
 }

The diff is against the PR head. The retry checks pass with or without the fix (without it, the failing flush already wrote everything), so they could also go in the first commit.

Update: this is item 5 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316

In commit "test: characterize writes after flush failure" (07d23eb75527b8dd6571a33b3bc304815764bc07) Optional, could be a follow-up: it would be nice if the test also checked what happens on the next flush after this one fails. With this PR, when the block file flush fails, `FlushStateToDisk()` returns without writing the block index or the coins. That data stays in memory, so if the problem clears up before a later `FlushStateToDisk()` call (say, the open failed because the node ran out of file descriptors), that call writes it. The last chance is normally the flush in `Shutdown()`. If the problem doesn't clear up, the node stops at the last successful flush and catches up after a restart. The first case isn't tested right now. Moving the block file aside instead of deleting it lets the test put it back, flush again, and check that everything catches up to `new_tip`: ```diff --- a/src/test/chainstate_write_tests.cpp +++ b/src/test/chainstate_write_tests.cpp @@ -114,5 +114,4 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(chainstate_flush_failure_boundary, TestChain100Setup) { - auto inject_file_open_failure{[](const fs::path& file) { Assert(fs::remove(file)); Assert(fs::create_directory(file)); }}; auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()}; BlockValidationState state{}; @@ -124,5 +123,9 @@ BOOST_FIXTURE_TEST_CASE(chainstate_flush_failure_boundary, TestChain100Setup) auto* new_tip{WITH_LOCK(::cs_main, return chainstate.m_chain.Tip())}; BOOST_REQUIRE_NE(old_flushed, new_tip); - inject_file_open_failure(WITH_LOCK(::cs_main, return chainstate.m_blockman.GetBlockPosFilename(new_tip->GetBlockPos()))); + // Move the block file aside and put a directory in its place so the flush fails to open it. + const fs::path blk_file{WITH_LOCK(::cs_main, return chainstate.m_blockman.GetBlockPosFilename(new_tip->GetBlockPos()))}; + const fs::path blk_backup{blk_file + ".bak"}; + fs::rename(blk_file, blk_backup); + Assert(fs::create_directory(blk_file)); ASSERT_DEBUG_LOG("Flushing block file to disk failed"); @@ -135,4 +138,14 @@ BOOST_FIXTURE_TEST_CASE(chainstate_flush_failure_boundary, TestChain100Setup) BOOST_REQUIRE(WITH_LOCK(::cs_main, return chainstate.m_blockman.m_block_tree_db->ReadBlockFileInfo(new_tip->nFile, file_info))); BOOST_CHECK_EQUAL(file_info.nHeightLast, old_flushed->nHeight); + + // Once the block file is back, a later flush succeeds and catches up. + Assert(fs::remove(blk_file)); + fs::rename(blk_backup, blk_file); + state = {}; + BOOST_CHECK(chainstate.FlushStateToDisk(state, FlushStateMode::FORCE_FLUSH)); + BOOST_CHECK_EQUAL(WITH_LOCK(::cs_main, return chainstate.GetLastFlushedBlock()), new_tip); + BOOST_CHECK(WITH_LOCK(::cs_main, return chainstate.CoinsDB().GetBestBlock()) == new_tip->GetBlockHash()); + BOOST_REQUIRE(WITH_LOCK(::cs_main, return chainstate.m_blockman.m_block_tree_db->ReadBlockFileInfo(new_tip->nFile, file_info))); + BOOST_CHECK_EQUAL(file_info.nHeightLast, new_tip->nHeight); } ``` The diff is against the PR head. The retry checks pass with or without the fix (without it, the failing flush already wrote everything), so they could also go in the first commit. Update: this is item 5 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316
ryanofsky (Migrated from github.com) commented 2026-10-28 17:27:46 +00:00

re: https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-4983411974

In commit "validation: return block-file flush errors" (12f691cf28)

I wrote a test where a first flush fails and requests shutdown, then I fix the file and call FlushStateToDisk() again: it succeeds and m_last_flushed_block moves forward, even though shutdown was already requested before this second call. Is this expected?

Yes, this seems expected and good. The node still shuts down, but if the problem has cleared by then, the shutdown flush can save what the failed flush skipped.

When the block file flush fails, FlushStateToDisk() now returns without writing the block index or the coins, but that data stays in memory. flushError() requests shutdown, and Shutdown() in init.cpp then calls ForceFlushStateToDisk() on each chainstate. If the problem has cleared by then (say, file descriptors released as connections close), that flush writes everything. That's what the PR description means by "Later flushes can retry and write if they succeed, including during shutdown."

The flush doesn't check the interrupt before writing; it's checked by code that produces new state, like ActivateBestChain(). And m_last_flushed_block advancing on that flush is right: that flush succeeded, and with this PR the marker only moves on a successful flush.

re: https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-4983411974 In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) > I wrote a test where a first flush fails and requests shutdown, then I fix the file and call `FlushStateToDisk()` again: it succeeds and `m_last_flushed_block` moves forward, even though shutdown was already requested before this second call. Is this expected? Yes, this seems expected and good. The node still shuts down, but if the problem has cleared by then, the shutdown flush can save what the failed flush skipped. When the block file flush fails, `FlushStateToDisk()` now returns without writing the block index or the coins, but that data stays in memory. `flushError()` requests shutdown, and `Shutdown()` in `init.cpp` then calls `ForceFlushStateToDisk()` on each chainstate. If the problem has cleared by then (say, file descriptors released as connections close), that flush writes everything. That's what the PR description means by "Later flushes can retry and write if they succeed, including during shutdown." The flush doesn't check the interrupt before writing; it's checked by code that produces new state, like `ActivateBestChain()`. And `m_last_flushed_block` advancing on that flush is right: that flush succeeded, and with this PR the marker only moves on a successful flush.
ryanofsky (Migrated from github.com) commented 2026-10-28 17:27:47 +00:00

re: https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-4983411974

In commit "validation: return block-file flush errors" (12f691cf28)

Would be correct adding an assume to verify this behaviour is keep it in the future?

I'd leave out the Assume(m_chainman.m_interrupt), because it would fire for kernel API users on an ordinary flush failure.

The comment promises that the notification was sent, not that shutdown was requested. In the node, flushError() does request shutdown, but in the kernel API it's just a user callback, and nothing sets the interrupt unless the application does. The node already keeps the two separate for fatalError() (m_shutdown_on_fatal_error).

A better way to check the invariant is a test that a failed FlushBlockFile() always calls flushError(), which #35731 adds.

Update: this comes up in items 9 and 11 of the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316

re: https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-4983411974 In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) > Would be correct adding an assume to verify this behaviour is keep it in the future? I'd leave out the `Assume(m_chainman.m_interrupt)`, because it would fire for kernel API users on an ordinary flush failure. The comment promises that the notification was sent, not that shutdown was requested. In the node, `flushError()` does request shutdown, but in the kernel API it's just a user callback, and nothing sets the interrupt unless the application does. The node already keeps the two separate for `fatalError()` (`m_shutdown_on_fatal_error`). A better way to check the invariant is a test that a failed `FlushBlockFile()` always calls `flushError()`, which #35731 adds. Update: this comes up in items 9 and 11 of the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316
ryanofsky (Migrated from github.com) commented 2026-10-28 19:55:07 +00:00

In commit "validation: return block-file flush errors" (12f691cf28)

Non-blocking: it would be nice if this comment also said why returning here is recoverable. Nothing in the code explains that the skipped writes are still pending in memory and can be written by a later flush. Maybe:

                    // FlushChainstateBlockFile() already reported the specific error through flushError().
                    // Return before writing the block index or coins. That data stays in memory, so a later
                    // flush can still write it if the problem clears up, for example the one during shutdown.

Update: this is item 6 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316

In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) Non-blocking: it would be nice if this comment also said why returning here is recoverable. Nothing in the code explains that the skipped writes are still pending in memory and can be written by a later flush. Maybe: ```suggestion // FlushChainstateBlockFile() already reported the specific error through flushError(). // Return before writing the block index or coins. That data stays in memory, so a later // flush can still write it if the problem clears up, for example the one during shutdown. ``` Update: this is item 6 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316
ryanofsky (Migrated from github.com) commented 2026-10-28 17:27:43 +00:00

In commit "validation: return block-file flush errors" (12f691cf28)

Note for reviewers: this doesn't add a new kind of failure for callers. To them a false return here looks like the CheckDiskSpace() failure a few lines up, which already returns before these writes.

Since callers were my concern in https://github.com/bitcoin/bitcoin/pull/27866#discussion_r1297313148, here is what each one does:

In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) Note for reviewers: this doesn't add a new kind of failure for callers. To them a `false` return here looks like the [`CheckDiskSpace()` failure](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2774-L2777) a few lines up, which already returns before these writes. Since callers were my concern in https://github.com/bitcoin/bitcoin/pull/27866#discussion_r1297313148, here is what each one does: - [`DisconnectTip()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2975-L2978) and [`ConnectTip()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L3068-L3071) return false before `m_chain.SetTip()` ([connect](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L3085), [disconnect](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2988)), after the block has already been applied to `CoinsTip()` (see [the separate comment about that](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4405681713)). - [`ActivateBestChain()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L3463-L3466) returns false. Its loop also [stops on `m_interrupt`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L3489), which the node's `flushError()` [sets](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/node/kernel_notifications.cpp#L92-L95) by requesting shutdown. - [`AcceptBlock()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L4399-L4405) ignores the result, with a comment saying the notification still fires. - [`AcceptToMemoryPool()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L1796-L1798) and [`ProcessNewPackage()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L1827-L1829) ignore it. - [`ForceFlushStateToDisk()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2847-L2853), [`PruneAndFlush()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2855-L2862) and [`PruneBlockFilesManual()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L4551-L4558) log it. - [`ResizeCoinsCaches()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L5494-L5504) returns it to [`MaybeRebalanceCaches()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L6102-L6130) and [`ActivateSnapshot()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L5676), which ignore it. - RPCs that call `ForceFlushStateToDisk()` and then read `CoinsDB()` (`gettxoutsetinfo`, `scantxoutset`, `dumptxoutset`) ignore it and can read a DB that is behind the tip, same as with the disk-space failure. - [`MaybeValidateSnapshot()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L6037-L6060) ignores it and then hashes the coins DB, which may be stale. It still returns `STATS_FAILED` rather than marking the snapshot invalid, but only because [`SnapshotUTXOHashBreakpoint()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L5766-L5769) throws once shutdown is requested, which `flushError()` normally does. Not a problem for this PR. A follow-up could make it check the flush result and return early, so it doesn't depend on that. That would be a robustness cleanup, not a behavior change for the node. [Update: this is now [item 10](https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316) in the post-merge follow-ups list.]
ryanofsky (Migrated from github.com) commented 2026-10-28 17:27:48 +00:00

re: https://github.com/bitcoin/bitcoin/pull/35714#discussion_r3741378587

Note: agree m_next_write shouldn't advance. But one minor side effect is the error can now be reported more than once.

If the failed flush was triggered by the periodic timer or a large cache, that condition stays true. So later PERIODIC flushes (mostly from mempool acceptance) retry, fail, and call flushError() again, until connman->Interrupt() stops them. Before this PR the first attempt still wrote the state and advanced m_next_write, so the condition didn't stay true and there was only one report.

The window is short and the node is shutting down anyway, so this seems ok.

re: https://github.com/bitcoin/bitcoin/pull/35714#discussion_r3741378587 Note: agree `m_next_write` shouldn't advance. But one minor side effect is the error can now be reported more than once. If the failed flush was triggered by the periodic timer or a large cache, that condition stays true. So later `PERIODIC` flushes (mostly from mempool acceptance) retry, fail, and call `flushError()` again, until `connman->Interrupt()` stops them. Before this PR the first attempt still wrote the state and advanced `m_next_write`, so the condition didn't stay true and there was only one report. The window is short and the node is shutting down anyway, so this seems ok.
ryanofsky (Migrated from github.com) commented 2026-10-28 20:23:39 +00:00

In commit "validation: return block-file flush errors" (12f691cf28)

Note: one consequence of returning here that's easy to miss. When this happens inside ConnectTip() or DisconnectTip(), the block has already been applied to CoinsTip() but m_chain isn't updated, so the coins tip and the chain tip disagree until shutdown.

Neither ActivateBestChain() nor mempool acceptance checks the interrupt first, so a transaction or block arriving before the network threads stop could hit the asserts in PreChecks() or ConnectBlock(), and the node would abort instead of shutting down cleanly. I found this by reading the code and haven't tried to reproduce it.

I don't think it should block this PR. It isn't corruption: the disk is still at the last successful flush, so the node recovers on restart the same way it would after a crash. And the CheckDiskSpace() return above could already get into this state.

For a follow-up, I think a better fix than adding interrupt checks to every path that assumes the coins tip matches the chain tip is to keep the in-memory state consistent. Memory and disk each need to be consistent on their own, but disk normally lags behind memory, and a failed flush only means it lags further. It shouldn't undo a change already made in memory. So I think ConnectTip() and DisconnectTip() should ignore the flush result the way AcceptBlock() does, since the error is already reported and the block really has been applied, and let ActivateBestChain() stop on the interrupt as usual. Returning before SetTip() dates from when every block was written to disk before memory was updated; that stopped being true when flushing became periodic in #5241, but the early return stayed.

Update: this is item 1 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316

In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) Note: one consequence of returning here that's easy to miss. When this happens inside [`ConnectTip()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L3060-L3071) or [`DisconnectTip()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2959-L2978), the block has already been applied to `CoinsTip()` but `m_chain` isn't updated, so the coins tip and the chain tip disagree until shutdown. Neither `ActivateBestChain()` nor mempool acceptance checks the interrupt first, so a transaction or block arriving before the network threads stop could hit the asserts in [`PreChecks()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L876) or [`ConnectBlock()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L2332), and the node would abort instead of shutting down cleanly. I found this by reading the code and haven't tried to reproduce it. I don't think it should block this PR. It isn't corruption: the disk is still at the last successful flush, so the node recovers on restart the same way it would after a crash. And the `CheckDiskSpace()` return above could already get into this state. For a follow-up, I think a better fix than adding interrupt checks to every path that assumes the coins tip matches the chain tip is to keep the in-memory state consistent. Memory and disk each need to be consistent on their own, but disk normally lags behind memory, and a failed flush only means it lags further. It shouldn't undo a change already made in memory. So I think `ConnectTip()` and `DisconnectTip()` should ignore the flush result the way [`AcceptBlock()`](https://github.com/bitcoin/bitcoin/blob/12f691cf286ea9a020583d267b94efca102a4056/src/validation.cpp#L4399-L4405) does, since the error is already reported and the block really has been applied, and let `ActivateBestChain()` stop on the interrupt as usual. Returning before `SetTip()` dates from when every block was written to disk before memory was updated; that stopped being true when flushing became periodic in #5241, but the early return stayed. Update: this is item 1 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316
Lines 2799-2804
ryanofsky (Migrated from github.com) commented 2026-10-28 17:29:58 +00:00

In commit "validation: return block-file flush errors" (12f691cf28)

Non-blocking, fine as a follow-up: if this early return happens during a prune flush and a later flush succeeds, the pruned block files are never deleted. They stay on disk until a reindex.

How it happens:

  • FindFilesToPrune() has already marked the files pruned in memory (PruneOneBlockFile()) before the block-file flush runs, and setFilesToPrune is local to this call.
  • The later flush writes the block index with those files marked pruned, but FindFilesToPrune() skips files with nSize == 0, so nothing finds them again.

Before this PR a block-file flush failure still unlinked them (the disk-space return above already had this gap).

It's only leaked disk space, not corruption. A fix could keep the pending set in a member that the next successful flush drains, or there could at least be a comment here noting the gap.

Update: this is item 7 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316

In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) Non-blocking, fine as a follow-up: if this early return happens during a prune flush and a later flush succeeds, the pruned block files are never deleted. They stay on disk until a reindex. How it happens: - `FindFilesToPrune()` has already marked the files pruned in memory (`PruneOneBlockFile()`) before the block-file flush runs, and `setFilesToPrune` is local to this call. - The later flush writes the block index with those files marked pruned, but `FindFilesToPrune()` skips files with `nSize == 0`, so nothing finds them again. Before this PR a block-file flush failure still unlinked them (the disk-space return above already had this gap). It's only leaked disk space, not corruption. A fix could keep the pending set in a member that the next successful flush drains, or there could at least be a comment here noting the gap. Update: this is item 7 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316
Lines 4403-4407
ryanofsky (Migrated from github.com) commented 2026-10-28 20:36:36 +00:00

In commit "validation: return block-file flush errors" (12f691cf28)

Non-blocking: this comment says "the fatal error notification inside FlushStateToDisk still fires", but with this PR a block file flush failure is reported through flushError() instead. It would also be worth saying why ignoring the result is right. It's the same reasoning as the ConnectTip() comment: don't confuse disk state with memory state.

-    // Flush errors (e.g. low disk space during pruning) are ignored, so that
-    // callers can't mistreat a flush failure as a block validation failure.
-    // The fatal error notification inside FlushStateToDisk still fires,
-    // so the node will shut down on unrecoverable flush errors regardless.
-    // For state a dummy value is used, and the return value is ignored.
+    // Flush errors are ignored. Failing to save state doesn't make the block
+    // invalid or mean accepting it should be undone, so callers shouldn't see
+    // it as a validation failure. FlushStateToDisk() already reported the error
+    // through flushError() or fatalError(), which normally shuts the node down.

Update: this is item 6 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316

In commit "validation: return block-file flush errors" (12f691cf286ea9a020583d267b94efca102a4056) Non-blocking: this comment says "the fatal error notification inside FlushStateToDisk still fires", but with this PR a block file flush failure is reported through `flushError()` instead. It would also be worth saying why ignoring the result is right. It's the same reasoning as [the `ConnectTip()` comment](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4405681713): don't confuse disk state with memory state. ```diff - // Flush errors (e.g. low disk space during pruning) are ignored, so that - // callers can't mistreat a flush failure as a block validation failure. - // The fatal error notification inside FlushStateToDisk still fires, - // so the node will shut down on unrecoverable flush errors regardless. - // For state a dummy value is used, and the return value is ignored. + // Flush errors are ignored. Failing to save state doesn't make the block + // invalid or mean accepting it should be undone, so callers shouldn't see + // it as a validation failure. FlushStateToDisk() already reported the error + // through flushError() or fatalError(), which normally shuts the node down. ``` Update: this is item 6 in the post-merge follow-ups list: https://github.com/bitcoin/bitcoin/pull/35714#pullrequestreview-5697890316
ryanofsky (Migrated from github.com) reviewed 2026-10-29 15:12:10 +00:00
ryanofsky (Migrated from github.com) left a comment

Post-merge, here is a list of possible follow-ups, roughly in order of importance. It collects suggestions from the review comments above, mine and other reviewers', and from follow-up PRs. Items 1-3 can crash the node or leave a corrupt database on disk; I reproduced each with a unit test. The rest are smaller bugs, documentation and tests. Happy to review any of these.

  1. ConnectTip() and DisconnectTip() should not return early on a flush failure after updating CoinsTip(). Both apply the block to CoinsTip(), then return false on a flush error before m_chain.SetTip() (disconnect, connect), so a disk error leaves the coins tip and the chain tip pointing at different blocks until shutdown.

    I checked this with a unit test: after a block file flush failure inside ConnectTip(), submitting a transaction aborts on the PreChecks() assert, and creating a block template aborts on the ConnectBlock() assert through TestBlockValidity(). So a transaction or getblocktemplate call arriving before shutdown finishes can crash the node instead of letting it shut down cleanly.

    Returning false here treats a disk failure as if it were a memory failure. Memory and disk each need to be consistent on their own, and disk normally lags behind memory; a failed flush only means it lags further. These functions should ignore the flush result the way AcceptBlock() does (the error is already reported through flushError()), and let ActivateBestChain() stop on the interrupt as usual. This predates the PR: the CheckDiskSpace() failure already returned from the same place. (original suggestion)

  2. A failed coins DB write can drop changes from memory, which can then leave a corrupt UTXO set on disk or crash the node. CCoinsViewCache::Sync(), used for periodic and prune flushes, writes the cache to the database in several batches through CCoinsViewDB::BatchWrite(). As each entry is added to a batch, the cache stops tracking it as needing a write (spent coins are erased, other entries marked clean), before the batch is committed.

    If a commit throws on a LevelDB write error, the changes in that batch are neither in the cache nor on disk, so the cache serves those spent coins from the database as unspent. FlushStateToDisk() catches the error and requests shutdown, but the node keeps running until then. If a later flush at the same block succeeds, like the shutdown flush, it writes the remaining entries and records the database as consistent at that block without the lost batch. If a block is connected first, the flush aborts on an assert instead.

    I checked this with a unit test against a real on-disk CCoinsViewDB, making one write fail partway through the flush. After the failed Sync(), 29 of 200 coins spent in the new block were visible as unspent through the cache. The successful retry then recorded the database as consistent at the new block, with those 29 spent coins still in it. A restart would load that as a valid UTXO set.

    This predates the PR and is a different code path, but it breaks the same rule as item 1: a disk failure shouldn't change memory. Keeping entries dirty until their batch commits would fix it.

  3. A failed block index write drops pending block index updates, which can leave a node that won't start without a reindex. As in item 2, WriteBlockIndexDB() erases m_dirty_fileinfo and m_dirty_blockindex before WriteBatchSync() writes them. If that write throws, the block index and file info updates are no longer marked dirty, so a later flush skips them. The shutdown flush retry can succeed, and it then writes the coins on top of a block index on disk that is missing the updates.

    I checked this with a unit test: after a failed block index write and a successful retry, the coins DB's best block was the new tip but the new tip wasn't in the block index on disk. After a simulated restart, the node failed to start with "Error initializing block database" and needed a reindex.

    Clearing the dirty sets only after the write succeeds would fix it.

  4. Document how callers should use the FlushStateToDisk() return value. The header comment only says "@returns true unless a system error occurred", which doesn't tell callers what a false return means for the state they hold. Items 1 and 8 are callers that misread it. Maybe something like:

    * @returns false if state could not be written to disk. The error has
    *     already been reported through the kernel notifications (in the node
    *     this requests shutdown).
    *
    * @warning The return value only says whether state was written to disk;
    *     in-memory state is valid either way. A caller whose own return value
    *     says whether it updated in-memory state should not return false just
    *     because this did.
    
  5. Tests that inject a failure at each write and check memory and disk afterwards. These would have caught items 1-3. Fail each write point in turn (block file, undo file, block index batch, each coins batch, including partial batches), then check that memory is still consistent (CoinsTip() best block matches m_chain.Tip(), the coins view matches the expected UTXO set) and that a restart, or a retry where that's allowed, ends up with the same state on disk as a run with no failure. A test-only option to fail the Nth database write, next to the existing simulate_crash_ratio, would make the database cases easy.

    This also covers checking that a flush after a failed one succeeds and writes the skipped state, which isn't tested yet (original suggestion). @arejula27 mentioned writing a test like this locally, so it might fit in #35731.

  6. Comments that say why the flush handling is right. The AcceptBlock() comment still refers to "the fatal error notification", and describes ignoring the result as keeping callers from mistreating a flush failure. Ignoring the result is more than defensive: callers rely on the return value to know whether the block was stored and the block index updated. If a flush error could make it return false after those updates, the return value would stop meaning anything, which would be bad for composability even though no current caller would break. Maybe something like this (original suggestion):

    // Ignore flush errors. By this point the block is stored and the block
    // index updated, and callers rely on the return value to know that.
    // Failing to write state to disk doesn't undo that, and FlushStateToDisk()
    // has already reported the error through flushError() or fatalError().
    

    Separately, the new early return in FlushStateToDisk() could say why returning is recoverable: the skipped writes stay in memory and a later flush, like the one at shutdown, can write them (original suggestion).

  7. Pruned block files aren't deleted if a prune flush fails and a later flush succeeds. FindFilesToPrune() updates the in-memory file info before the flush, but setFilesToPrune is a local, so the retry writes the index and never unlinks the files. The disk-space failure already had this gap; this PR adds the block-file failure as a second trigger. Keeping the pending set as a member that UnlinkPrunedFiles() drains after the next successful WriteBlockIndexDB() would fix it (original suggestion).

    I checked this with a unit test using -prune=1 -fastprune: after a manual prune whose flush failed and a successful retry, blk00000.dat was still there, while the same prune with no failure deletes it.

  8. ActivateBestChain() returns false after its own periodic flush fails, even though the blocks it connected are fully applied in memory. The periodic flush returns false on failure, while stopping on the interrupt returns true, so callers report a failure for blocks that were connected: the generate* RPCs say "block not accepted", and the kernel API's btck_chainstate_manager_process_block() returns an error.

    This matches the documentation ("@returns true unless a system error occurred"), but it makes false ambiguous: callers can't tell a failed disk write from a block that couldn't be connected. The disk failure is already reported through flushError(), so returning it again doesn't tell callers anything new. It should ignore the flush result like AcceptBlock() and let the interrupt check end the loop, so that false only means a block couldn't be connected or disconnected. The documentation could then say that disk write failures are reported through the notifications instead.

  9. Document that kernel API users should stop validation after a flush or fatal error. Some validation code is only safe because the node's flushError() and fatalError() handlers request shutdown, which sets the interrupt that validation checks. Kernel API users provide their own handlers, which may not request shutdown (earlier comment). The btck_NotifyFlushError and fatal error callbacks could document that the embedder should call btck_context_interrupt() and stop submitting blocks and transactions after one fires, as the node does. That is simpler than making validation correct without it, which would add code the node doesn't need.

  10. MaybeValidateSnapshot() should check its flush result before hashing the coins DB. It calls ForceFlushStateToDisk(), which only logs a failure, then hashes CoinsDB() (original comment). After a failed flush the DB is behind the tip, so the hash doesn't match and the snapshot chainstate is discarded as invalid. In the node this doesn't happen, because the shutdown request stops the hashing first, but that depends on the interrupt being set, not on anything this function checks.

    It should return early with a new SnapshotCompletionResult when the flush fails, without discarding anything. LoadChainstate() calls MaybeValidateSnapshot() again at the next startup, so the check is retried.

  11. #35731 (@arejula27): BlockManager-level tests and a notify-and-error helper. This covers the undo-file failure path @arejula27 asked about in this comment, which @l0rinc deferred to a lower-level test. It needs a rebase now that this is merged.

  12. RPCs that label a possibly stale coins DB with the in-memory tip. scantxoutset (code) and CreateRolledBackUTXOSnapshot() (code) ignore the ForceFlushStateToDisk() result, then read CoinsDB() and report it as m_chain.Tip(). After a failed flush the DB is at the previous flush. Minor, since the node is shutting down. If this isn't changed, the RPC help could warn that the result may lag the tip.

  13. Test style (@maflcko, @optout21). @maflcko suggested splitting the && in the test's BOOST_CHECK to follow the style from #35729 and avoid a silent conflict with the Boost removal in #35713. @optout21 suggested a BOOST_CHECK_ALL-style macro that prints every value when one condition fails. Neither change was made; this only matters when #35713 is rebased.

Post-merge, here is a list of possible follow-ups, roughly in order of importance. It collects suggestions from the review comments above, mine and other reviewers', and from follow-up PRs. Items 1-3 can crash the node or leave a corrupt database on disk; I reproduced each with a unit test. The rest are smaller bugs, documentation and tests. Happy to review any of these. 1. **`ConnectTip()` and `DisconnectTip()` should not return early on a flush failure after updating `CoinsTip()`.** Both apply the block to `CoinsTip()`, then return false on a flush error before `m_chain.SetTip()` ([disconnect](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L2975-L2978), [connect](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L3068-L3071)), so a disk error leaves the coins tip and the chain tip pointing at different blocks until shutdown. I checked this with a unit test: after a block file flush failure inside `ConnectTip()`, submitting a transaction aborts on the [`PreChecks()` assert](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L876), and creating a block template aborts on the [`ConnectBlock()` assert](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L2330-L2332) through `TestBlockValidity()`. So a transaction or `getblocktemplate` call arriving before shutdown finishes can crash the node instead of letting it shut down cleanly. Returning false here treats a disk failure as if it were a memory failure. Memory and disk each need to be consistent on their own, and disk normally lags behind memory; a failed flush only means it lags further. These functions should ignore the flush result the way `AcceptBlock()` does (the error is already reported through `flushError()`), and let `ActivateBestChain()` stop on the interrupt as usual. This predates the PR: the `CheckDiskSpace()` failure already returned from the same place. ([original suggestion](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4405681713)) 2. **A failed coins DB write can drop changes from memory, which can then leave a corrupt UTXO set on disk or crash the node.** [`CCoinsViewCache::Sync()`](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/coins.cpp#L284-L293), used for periodic and prune flushes, writes the cache to the database in several batches through [`CCoinsViewDB::BatchWrite()`](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/txdb.cpp#L135-L198). As each entry is added to a batch, the cache stops tracking it as needing a write (spent coins are erased, other entries marked clean), before the batch is committed. If a commit [throws](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/dbwrapper.cpp#L319-L320) on a LevelDB write error, the changes in that batch are neither in the cache nor on disk, so the cache serves those spent coins from the database as unspent. `FlushStateToDisk()` [catches the error](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L2841-L2843) and requests shutdown, but the node keeps running until then. If a later flush at the same block succeeds, like the shutdown flush, it writes the remaining entries and records the database as consistent at that block without the lost batch. If a block is connected first, the flush aborts on an [assert](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/txdb.cpp#L150) instead. I checked this with a unit test against a real on-disk `CCoinsViewDB`, making one write fail partway through the flush. After the failed `Sync()`, 29 of 200 coins spent in the new block were visible as unspent through the cache. The successful retry then recorded the database as consistent at the new block, with those 29 spent coins still in it. A restart would load that as a valid UTXO set. This predates the PR and is a different code path, but it breaks the same rule as item 1: a disk failure shouldn't change memory. Keeping entries dirty until their batch commits would fix it. 3. **A failed block index write drops pending block index updates, which can leave a node that won't start without a reindex.** As in item 2, [`WriteBlockIndexDB()`](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/node/blockstorage.cpp#L529-L546) erases `m_dirty_fileinfo` and `m_dirty_blockindex` before `WriteBatchSync()` writes them. If that write throws, the block index and file info updates are no longer marked dirty, so a later flush skips them. The shutdown flush retry can succeed, and it then writes the coins on top of a block index on disk that is missing the updates. I checked this with a unit test: after a failed block index write and a successful retry, the coins DB's best block was the new tip but the new tip wasn't in the block index on disk. After a simulated restart, the node failed to start with "Error initializing block database" and needed a reindex. Clearing the dirty sets only after the write succeeds would fix it. 4. **Document how callers should use the `FlushStateToDisk()` return value.** The [header comment](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.h#L736-L750) only says "@returns true unless a system error occurred", which doesn't tell callers what a false return means for the state they hold. Items 1 and 8 are callers that misread it. Maybe something like: ``` * @returns false if state could not be written to disk. The error has * already been reported through the kernel notifications (in the node * this requests shutdown). * * @warning The return value only says whether state was written to disk; * in-memory state is valid either way. A caller whose own return value * says whether it updated in-memory state should not return false just * because this did. ``` 5. **Tests that inject a failure at each write and check memory and disk afterwards.** These would have caught items 1-3. Fail each write point in turn (block file, undo file, block index batch, each coins batch, including partial batches), then check that memory is still consistent (`CoinsTip()` best block matches `m_chain.Tip()`, the coins view matches the expected UTXO set) and that a restart, or a retry where that's allowed, ends up with the same state on disk as a run with no failure. A test-only option to fail the Nth database write, next to the existing `simulate_crash_ratio`, would make the database cases easy. This also covers checking that a flush after a failed one succeeds and writes the skipped state, which isn't tested yet ([original suggestion](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4403889247)). @arejula27 mentioned writing a test like this locally, so it might fit in [#35731](https://github.com/bitcoin/bitcoin/pull/35731). 6. **Comments that say why the flush handling is right.** The [`AcceptBlock()` comment](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L4399-L4405) still refers to "the fatal error notification", and describes ignoring the result as keeping callers from mistreating a flush failure. Ignoring the result is more than defensive: callers rely on the return value to know whether the block was stored and the block index updated. If a flush error could make it return false after those updates, the return value would stop meaning anything, which would be bad for composability even though no current caller would break. Maybe something like this ([original suggestion](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4405809581)): ``` // Ignore flush errors. By this point the block is stored and the block // index updated, and callers rely on the return value to know that. // Failing to write state to disk doesn't undo that, and FlushStateToDisk() // has already reported the error through flushError() or fatalError(). ``` Separately, the new early return in `FlushStateToDisk()` could say why returning is recoverable: the skipped writes stay in memory and a later flush, like the one at shutdown, can write them ([original suggestion](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4405409912)). 7. **Pruned block files aren't deleted if a prune flush fails and a later flush succeeds.** `FindFilesToPrune()` updates the in-memory file info before the flush, but `setFilesToPrune` is a local, so the retry writes the index and never [unlinks the files](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L2795-L2799). The disk-space failure already had this gap; this PR adds the block-file failure as a second trigger. Keeping the pending set as a member that `UnlinkPrunedFiles()` drains after the next successful `WriteBlockIndexDB()` would fix it ([original suggestion](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4403913190)). I checked this with a unit test using `-prune=1 -fastprune`: after a manual prune whose flush failed and a successful retry, `blk00000.dat` was still there, while the same prune with no failure deletes it. 8. **`ActivateBestChain()` returns false after its own periodic flush fails, even though the blocks it connected are fully applied in memory.** The [periodic flush](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L3463-L3465) returns false on failure, while stopping on the [interrupt](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L3489-L3494) returns true, so callers report a failure for blocks that were connected: the `generate*` RPCs say "block not accepted", and the kernel API's `btck_chainstate_manager_process_block()` returns an error. This matches the documentation ("@returns true unless a system error occurred"), but it makes false ambiguous: callers can't tell a failed disk write from a block that couldn't be connected. The disk failure is already reported through `flushError()`, so returning it again doesn't tell callers anything new. It should ignore the flush result like `AcceptBlock()` and let the interrupt check end the loop, so that false only means a block couldn't be connected or disconnected. The documentation could then say that disk write failures are reported through the notifications instead. 9. **Document that kernel API users should stop validation after a flush or fatal error.** Some validation code is [only](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L3215-L3219) [safe](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L3254-L3258) because the node's [`flushError()` and `fatalError()` handlers](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/node/kernel_notifications.cpp#L92-L101) request shutdown, which sets the interrupt that validation checks. Kernel API users provide their own handlers, which may not request shutdown ([earlier comment](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4403889605)). The [`btck_NotifyFlushError`](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/kernel/bitcoinkernel.h#L558-L559) and fatal error callbacks could document that the embedder should call `btck_context_interrupt()` and stop submitting blocks and transactions after one fires, as the node does. That is simpler than making validation correct without it, which would add code the node doesn't need. 10. **`MaybeValidateSnapshot()` should check its flush result before hashing the coins DB.** It calls [`ForceFlushStateToDisk()`](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L6038), which only logs a failure, then hashes `CoinsDB()` ([original comment](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r4403889053)). After a failed flush the DB is behind the tip, so the hash doesn't match and the snapshot chainstate is discarded as invalid. In the node this doesn't happen, because the shutdown request [stops the hashing](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/validation.cpp#L6053-L6061) first, but that depends on the interrupt being set, not on anything this function checks. It should return early with a new `SnapshotCompletionResult` when the flush fails, without discarding anything. `LoadChainstate()` [calls `MaybeValidateSnapshot()` again](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/node/chainstate.cpp#L204-L206) at the next startup, so the check is retried. 11. **[#35731](https://github.com/bitcoin/bitcoin/pull/35731) (@arejula27): `BlockManager`-level tests and a notify-and-error helper.** This covers the undo-file failure path @arejula27 asked about in [this comment](https://github.com/bitcoin/bitcoin/pull/35714#issuecomment-4962258493), which @l0rinc deferred to a lower-level test. It needs a rebase now that this is merged. 12. **RPCs that label a possibly stale coins DB with the in-memory tip.** `scantxoutset` ([code](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/rpc/blockchain.cpp#L2476-L2478)) and `CreateRolledBackUTXOSnapshot()` ([code](https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/rpc/blockchain.cpp#L3286)) ignore the `ForceFlushStateToDisk()` result, then read `CoinsDB()` and report it as `m_chain.Tip()`. After a failed flush the DB is at the previous flush. Minor, since the node is shutting down. If this isn't changed, the RPC help could warn that the result may lag the tip. 13. **Test style (@maflcko, @optout21).** @maflcko [suggested](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r3802387955) splitting the `&&` in the test's `BOOST_CHECK` to follow the style from [#35729](https://github.com/bitcoin/bitcoin/pull/35729) and avoid a silent conflict with the Boost removal in [#35713](https://github.com/bitcoin/bitcoin/pull/35713). @optout21 [suggested](https://github.com/bitcoin/bitcoin/pull/35714#discussion_r3810102050) a `BOOST_CHECK_ALL`-style macro that prints every value when one condition fails. Neither change was made; this only matters when [#35713](https://github.com/bitcoin/bitcoin/pull/35713) is rebased.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35714
No description provided.