indexes: Save progress on early flushes

bitcoin/bitcoin: PR #36948

1 suggestion

Optional improvements

Link

[suggestion] · The flush-ahead test misses cross-branch commit rejection

The same-chain commit tests would still pass with a height-only Commit() guard, so they do not verify the cross-branch rejection now relied on after removing the callback guard.

Location: src/test/baseindex_tests.cpp:115 (head).

Details and suggested fix

Commit() checks ancestry against GetLastFlushedBlock(), not merely the notification locator. During a reorg, the index can remain on the old branch until BlockConnected() rewinds it, while a ConnectTip() flush can arrive first. index_reorg_crash does not check persisted progress, so it does not cover this case either.

Add a negative case using the new test's unregister/flush/register pattern: commit common ancestor C, index unflushed A1 at C+1, then unregister while building a taller competing branch from C with BuildChain() and processing its blocks. Force a flush and drain notifications before re-registering and delivering ChainStateFlushed(). After Stop() and Init(), assert that the saved height remains C, before any Sync(). A height-only guard would incorrectly save A1 here, violating the ancestry invariant used for stateful-index crash recovery.


Coverage details