Skip to content

Indexes: Harden the flush-error notification invariant - #35731

Open
arejula27 wants to merge 2 commits into
bitcoin:masterfrom
arejula27:flush-notify-invariant
Open

arejula27 wants to merge 2 commits into
bitcoin:masterfrom
arejula27:flush-notify-invariant

Conversation

@arejula27

@arejula27 arejula27 commented Jul 15, 2026 •

Copy link
Copy Markdown
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 (review) (pruned-file deletion after a failed flush is handled in #36735).

@DrahtBot

DrahtBot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

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
Concept ACK ryanofsky

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:

  • #36971 (blockstorage: fix partial-mask assertions and genesis availability checks by l0rinc)
  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #36858 (refactor: break the blockstorage/validation circular dependency by pzafonte)
  • #36548 (net: serve MSG_BLOCK by stripping witnesses in place by l0rinc)
  • #36326 (kernel: Use typed errors for fatal and flush error notifications by arejula27)
  • #36000 (validation: prefetch blocks while connecting by l0rinc)
  • #35003 (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.

@DrahtBot

Copy link
Copy Markdown
Contributor

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

Hints

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.

@arejula27
arejula27 force-pushed the flush-notify-invariant branch from a4c7bf0 to 2d7830b Compare November 2, 2026 16:53
@arejula27

Copy link
Copy Markdown
Contributor Author

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.

@arejula27
arejula27 marked this pull request as ready for review November 2, 2026 16:54

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

For the follow-ups in #35714 (review), 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

@arejula27

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants