indexes: Save progress on early flushes #36948

pull LakshyaBagani wants to merge 2 commits into bitcoin:master from LakshyaBagani:issue-36939 changing 2 files +48 −14
  1. LakshyaBagani commented at 8:19 PM on November 22, 2026: none

    Since #34897, a flush in ConnectTip() can report a block before the index receives BlockConnected for it. The locator check in ChainStateFlushed() then skips saving the index tip. On a pruned assumeutxo node, repeated skips can leave the saved tip so far behind that the index needs blocks that were pruned by the time it restarts after background validation.

    This PR uses Fabian Jahr’s two commits. The first adds a unit test that reproduces the skipped write. The second removes the locator check and updates the test to verify the saved tip after reopening the index. Commit() allows the write only if the index tip is at or is an ancestor of the chainstate’s last flushed block.

    Fixes #36939

  2. DrahtBot added the label UTXO Db and Indexes on Nov 22, 2026
  3. DrahtBot commented at 8:19 PM on November 22, 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
    ACK fjahr

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. LakshyaBagani commented at 8:22 PM on November 22, 2026: none

    Hi @mzumsande, @fjahr, and @l0rinc, could you take a look ?

    Since the locator change in #34897, a flush can report a block before the index receives BlockConnected for it. Would you prefer letting the index save its current tip when the flushed block is ahead on the same chain, or changing the callback order in validation?

  5. fjahr commented at 8:51 PM on November 22, 2026: contributor

    @LakshyaBagani I already developed a fix, just didn't get around to open the PR yet. You can see the branch here: https://github.com/fjahr/bitcoin/commits/2026-11-index-flush-commit/ I think that approach is better because Commit() already refuses to write unless the index's best block is an ancestor of the chainstate's last flushed block, so the locator check that you keep and even widen here can only block commits that are safe, and removing it leaves one rule in one place. If you want you maintain it you can pull my commits in here, otherwise I can open a separate PR.

  6. LakshyaBagani commented at 9:00 PM on November 22, 2026: none

    Thanks for sharing your fix. I will bring both of your commits into this PR, credit you in the description, and follow up on reviews.

  7. test: characterize skipped index commit when the flush notification is ahead ae70abbea8
  8. index: commit when the flush notification is ahead of the index ea1b6cba29
  9. LakshyaBagani force-pushed on Nov 22, 2026
  10. fjahr commented at 1:47 PM on November 24, 2026: contributor

    ACK ea1b6cba295b3e23afda2643ab7460ef09cb3620

    (Obviously not worth that much under the circumstances)

    The CI currently doesn't run because you are a first time contributor @LakshyaBagani , I hope a maintainer can approve it soon.


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-27 03:51 UTC

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