Skip to content

assumeutxo: add init and completion logic

This is part of the assumeutxo project (parent PR: #15606)


This changeset adds logic for detecting and activating snapshot chainstates on start, and for completing the snapshot validation process once the background chainstate reaches the base block of the assumed-valid chain. It also handles removing the snapshot chainstate data on-disk in the event that the snapshot fails to validate.

As detailed in assumeutxo.md:

Once the tip of the background chainstate hits the base block of the snapshot chainstate, we stop use of the background chainstate by setting m_stop_use, in CompleteSnapshotValidation(), which is checked in ActivateBestChain()). We hash the background chainstate's UTXO set contents and ensure it matches the compiled value in CMainParams::m_assumeutxo_data.

The background chainstate data lingers on disk until shutdown, when in ChainstateManager::Reset(), the background chainstate is cleaned up with ValidatedSnapshotShutdownCleanup(), which renames the chainstate_[hash] datadir as chainstate.

Failure consideration: if bitcoind unexpectedly halts after m_stop_use is set on the background chainstate but before CompleteSnapshotValidation() can finish, the need to complete snapshot validation will be detected on subsequent init by ChainstateManager::CheckForUncleanShutdown().


Most of this change is unittested, though some logic (anything assuming on-disk leveldb data) can't be tested without some rework of unittest setup, given in-memory leveldb instances are used. I can look into how difficult this would be.

This change adds the ability to unittest using on-disk leveldb coins dbs.

Possible follow-ups

Merge request reports

Loading