Indexes: Harden the flush-error notification invariant #35731

pull arejula27 wants to merge 2 commits into bitcoin:master from arejula27:flush-notify-invariant changing 3 files +97 −7
  1. arejula27 commented at 5:35 PM on July 15, 2026: contributor

    FlushStateToDisk() returns state.Error(...) when FlushChainstateBlockFile() fails, relying on the invariant that the flush-error notification has already been emitted (so the node is aborted). Today that invariant holds only because every success = false branch in FlushBlockFile/FlushUndoFile happens to call flushError() itself. A future flush source, or a new error branch, that fails without notifying would make FlushStateToDisk() report an error without AbortNode() being triggered.

    This PR makes that invariant hold by construction: whenever a flush reports failure, the flush-error notification has been emitted.

    • test: cover FlushBlockFile flush-error notifications: BlockManager unit tests that inject a failure on the block file and on the undo file separately, and assert that each failure emits flushError.
    • blockstorage: encapsulate flush+notify in FlushFile: a single FlushFile() helper performs the flush and emits the notification on failure; FlushBlockFile and FlushUndoFile delegate to it. No behaviour change.

    Follow-up to #35714. Possible further work on flush error handling is listed in #35714#pullrequestreview-5697890316 (pruned-file deletion after a failed flush is handled in #36735).

  2. DrahtBot added the label UTXO Db and Indexes on Jul 15, 2026
  3. DrahtBot commented at 5:35 PM on July 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    Concept ACK ryanofsky

    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:

    • #36858 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36858.svg"></sub> (refactor: break the blockstorage/validation circular dependency by pzafonte)
    • #36843 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36843.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
    • #36548 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36548.svg"></sub> (net: serve MSG_BLOCK by stripping witnesses in place by l0rinc)
    • #36326 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36326.svg"></sub> (kernel: Use typed errors for fatal and flush error notifications by arejula27)
    • #36000 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36000.svg"></sub> (validation: prefetch blocks while connecting by l0rinc)
    • #35003 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35003.svg"></sub> (validation: improve block data I/O error handling in P2P paths by furszy)

    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-->

  4. DrahtBot added the label CI failed on Jul 20, 2026
  5. DrahtBot commented at 11:17 AM on July 20, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/29437114552/job/88325958979</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU reported required header/include fixes (it modified src/node/blockstorage.h and exited non-zero).</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  6. DrahtBot added the label Needs rebase on Oct 28, 2026
  7. test: cover FlushBlockFile flush-error notifications 5cdf2cc4e1
  8. blockstorage: encapsulate flush+notify in FlushFile 2d7830b092
  9. arejula27 force-pushed on Nov 2, 2026
  10. arejula27 commented at 4:54 PM on November 2, 2026: contributor

    Rebased onto current master and converting from draft to open. @ryanofsky's follow-up list on #35714 also flagged more to do here, I'll do that in the next few days.

  11. arejula27 marked this as ready for review on Nov 2, 2026
  12. DrahtBot removed the label CI failed on Nov 2, 2026
  13. DrahtBot removed the label Needs rebase on Nov 2, 2026
  14. ryanofsky approved
  15. ryanofsky commented at 7:05 PM on November 3, 2026: contributor

    Concept ACK 2d7830b0928cf7e57c8e795f03b0b7d33e7cecfd on new test coverage and bundling Flush/flushError together.

    For the follow-ups in #35714#pullrequestreview-5697890316, note that #36735 is taking item 7 (deleting pruned files after a failed flush), so it might make sense to coordinate there. For items changing how errors are reported (like turning warnings into failures), I could be best to start with item 4, documenting how callers should use the FlushStateToDisk() return value, so later changes can follow a consistent rule instead of being made one at a time.

    Would also be good to update description now that PR #35714 is merged, and maybe simplify a little so this can be understood without needing to understand the #35714 history

  16. arejula27 commented at 6:18 PM on November 19, 2026: contributor

    Thanks for the review @ryanofsky . I've updated the PR description so it no longer depends on #35714's history. I'll start with documenting how callers should use the FlushStateToDisk() return value (item 4) and leave item 7 to #36735.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-20 15:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me