indexes: Don’t commit ahead of the flushed chainstate #34897

pull mzumsande wants to merge 3 commits into bitcoin:master from mzumsande:202603_index_sync_dont_commit_ahead changing 8 files +108 −0
  1. mzumsande commented at 5:54 am on March 23, 2026: contributor

    If indexes commit their data ahead of the flushed chainstate, and there is an unclean shutdown, the index will be corrupted. This is especially the case for the coinstatsindex, which has state (the muhash) which can’t easily be rolled back without access to the blocks. This was only partly fixed in #33212 (for reorg scenarios) but could still happen during initial sync.

    Fix this more thoroughly by having the node keep track of the last flushed block, and skipping index commits if the current block of the index is not an ancestor of the node’s last flushed block (similar to the suggestion by stickies-v in #33212#pullrequestreview-31408570890.

    I tried to follow the spirit of #24230 by adding the call to the chain interface (which involved adding an oddly specific method there) in order to avoid directly reaching into the node from the index code.

    Fixes #33208 Fixes #34261

  2. validation: track last flushed block
    This will be used to prevent the indexes to flush their state ahead of
    the chainstate.
    489bb4a5d8
  3. index: Don't commit ahead of the flushed chainstate
    Otherwise, if the node has an unclean restart,
    indexes with state (coinstatsindex) couldn't reorg to the
    last flushed tip and would be corrupted.
    7933e270ee
  4. test: add test to ensure indexes dont commit too early 5af4d6e2a6
  5. DrahtBot added the label UTXO Db and Indexes on Mar 23, 2026
  6. DrahtBot commented at 5:54 am on March 23, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK fjahr, l0rinc

    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:

    • #34917 (wallet: mark bip125-replaceable deprecated, remove walletrbf argument by rkrux)

    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.

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • //! Uses the fully validated chainstate, which is the one indexes follow. -> //! Uses the fully validated chainstate, which is the one the indexes follow. [Missing “the” makes the sentence grammatically incorrect and slightly harder to read.]

    2026-03-23 05:54:23

  7. fjahr commented at 8:23 am on March 23, 2026: contributor
    Concept ACK
  8. l0rinc commented at 1:12 pm on March 25, 2026: contributor
    I have reported something similar in #34489 (review) and #34489 (review) - will this PR fix those? Concept ACK regardless, thanks for fixing them!

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-03-29 03:13 UTC

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