AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 23 Bitcoin

Merge bitcoin/bitcoin#32414: validation: periodically flush dbcache during reindex-chainstate

Public commit record

What the developer wrote

Authored by Ava Chow

91/100 · Strong
Merge bitcoin/bitcoin#32414: validation: periodically flush dbcache during reindex-chainstate

c1e554d3e5834a140f2a53854018499a3bfe6822 refactor: consolidate 3 separate locks into one block (Andrew Toth)
41479ed1d23ea752d0ce14c2cf5627f43bceb722 test: add test for periodic flush inside ActivateBestChain (Andrew Toth)
84820561dcb2d156d1a1151a480fc1be6649cae4 validation: periodically flush dbcache during reindex-chainstate (Andrew Toth)

Pull request description:

After #30611 we periodically do a non-erasing flush of the dbcache to disk roughly every hour during IBD.
The intention was to also do this periodic flush during reindex-chainstate, so we would not risk losing progress during a system failure when reindexing with a high dbcache value.

It was discovered that reindex-chainstate does not perform a PERIODIC flush until it has already reached the tip. Since reindexing to tip usually happens within 24 hours, this behaviour was unnoticed with the previous periodic flush interval. Note that reindex-chainstate still does IF_NEEDED flushes during `ConnectBlock`, so this also would not be noticed when running with a lower dbcache value.

This patch moves the PERIODIC flush from after the outer loop in `ActivateBestChain` to inside the outer loop after we release `cs_main`. This will periodically flush during IBD, reindex-chainstate, and steady state.

ACKs for top commit:
l0rinc:
ACK c1e554d3e5834a140f2a53854018499a3bfe6822
achow101:
ACK c1e554d3e5834a140f2a53854018499a3bfe6822
sipa:
utACK c1e554d3e5834a140f2a53854018499a3bfe6822

Tree-SHA512: c447ad03e16c9978b8ed2c285b38e1b4c56e7778ab93b6f64435116f47b8931017f5f56ab53eb61656693146aaced776f666af573a41ab28e8f2b6d8657fa756
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a Bitcoin Core bug where the database cache (dbcache) was not being periodically saved to disk during the 'reindex-chainstate' operation. The intended behavior was to flush the cache roughly every hour to avoid losing progress if the system crashed. Because the flush only happened after reaching the tip, users running reindex-chainstate with a large dbcache could lose many hours of work on a crash. The patch moves the periodic flush inside the main loop so it actually occurs during reindexing, initial block download, and normal operation. It is a reliability/durability fix, not a remote-exploitable security vulnerability.

Recommended action

No urgent security action required. Node operators who use reindex-chainstate with large dbcache values should upgrade to benefit from improved crash durability. Reviewers should verify the flush is correctly placed outside cs_main and that the new test covers the intended periodic behavior.

Security signals we found

01

reliability/durability fix for local node operation

02

no remote attack surface introduced

03

no consensus, cryptography, or network protocol changes

04

no input parsing or memory safety changes

05

fix prevents potential data loss on crash during reindex-chainstate with high dbcache

Risk score

Why this scored 23/100

Our methodology →
Potential impact 8/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 5/15
Confidence 7/10
Evidence quality 3/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.