Skip to content

Commit 2b373fe

Browse files
committed
docs: update assumeutxo.md
Include notes about the `chainstate_snapshot` rename as well as updates for the included code.
1 parent 87a1108 commit 2b373fe

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

doc/design/assumeutxo.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Assumeutxo is a feature that allows fast bootstrapping of a validating bitcoind
44
instance with a very similar security model to assumevalid.
55

6-
The RPC commands `dumptxoutset` and `loadtxoutset` are used to respectively generate
7-
and load UTXO snapshots. The utility script `./contrib/devtools/utxo_snapshot.sh` may
8-
be of use.
6+
The RPC commands `dumptxoutset` and `loadtxoutset` (yet to be merged) are used to
7+
respectively generate and load UTXO snapshots. The utility script
8+
`./contrib/devtools/utxo_snapshot.sh` may be of use.
99

1010
## General background
1111

@@ -22,10 +22,6 @@ be of use.
2222
chainstate running asynchronously in the background. We also use this flag to control
2323
which index entries are added to setBlockIndexCandidates during LoadBlockIndex().
2424

25-
- Indexing implementations via BaseIndex can no longer assume that indexation happens
26-
sequentially, since background validation chainstates can submit BlockConnected
27-
events out of order with the active chain.
28-
2925
- The concept of UTXO snapshots is treated as an implementation detail that lives
3026
behind the ChainstateManager interface. The external presentation of the changes
3127
required to facilitate the use of UTXO snapshots is the understanding that there are
@@ -76,9 +72,15 @@ original chainstate remains in use as active.
7672

7773
Once the snapshot chainstate is loaded and validated, it is promoted to active
7874
chainstate and a sync to tip begins. A new chainstate directory is created in the
79-
datadir for the snapshot chainstate called `chainstate_snapshot`. When this directory
80-
is present in the datadir, the snapshot chainstate will be detected and loaded as
81-
active on node startup (via `DetectSnapshotChainstate()`).
75+
datadir for the snapshot chainstate called `chainstate_snapshot`.
76+
77+
When this directory is present in the datadir, the snapshot chainstate will be detected
78+
and loaded as active on node startup (via `DetectSnapshotChainstate()`).
79+
80+
A special file is created within that directory, `base_blockhash`, which contains the
81+
serialized `uint256` of the base block of the snapshot. This is used to reinitialize
82+
the snapshot chainstate on subsequent inits. Otherwise, the directory is a normal
83+
leveldb database.
8284

8385
| | |
8486
| ---------- | ----------- |
@@ -88,7 +90,7 @@ active on node startup (via `DetectSnapshotChainstate()`).
8890
The snapshot begins to sync to tip from its base block, technically in parallel with
8991
the original chainstate, but it is given priority during block download and is
9092
allocated most of the cache (see `MaybeRebalanceCaches()` and usages) as our chief
91-
consideration is getting to network tip.
93+
goal is getting to network tip.
9294

9395
**Failure consideration:** if shutdown happens at any point during this phase, both
9496
chainstates will be detected during the next init and the process will resume.
@@ -107,33 +109,32 @@ sequentially.
107109
### Background chainstate hits snapshot base block
108110

109111
Once the tip of the background chainstate hits the base block of the snapshot
110-
chainstate, we stop use of the background chainstate by setting `m_disabled` (not yet
111-
committed - see #15606), in `CompleteSnapshotValidation()`, which is checked in
112-
`ActivateBestChain()`). We hash the background chainstate's UTXO set contents and
113-
ensure it matches the compiled value in `CMainParams::m_assumeutxo_data`.
114-
115-
The background chainstate data lingers on disk until shutdown, when in
116-
`ChainstateManager::Reset()`, the background chainstate is cleaned up with
117-
`ValidatedSnapshotShutdownCleanup()`, which renames the `chainstate_[hash]` datadir as
118-
`chainstate`.
112+
chainstate, we stop use of the background chainstate by setting `m_disabled`, in
113+
`CompleteSnapshotValidation()`, which is checked in `ActivateBestChain()`). We hash the
114+
background chainstate's UTXO set contents and ensure it matches the compiled value in
115+
`CMainParams::m_assumeutxo_data`.
119116

120117
| | |
121118
| ---------- | ----------- |
122119
| number of chainstates | 2 (ibd has `m_disabled=true`) |
123120
| active chainstate | snapshot |
124121

125-
**Failure consideration:** if bitcoind unexpectedly halts after `m_disabled` is set on
126-
the background chainstate but before `CompleteSnapshotValidation()` can finish, the
127-
need to complete snapshot validation will be detected on subsequent init by
128-
`ChainstateManager::CheckForUncleanShutdown()`.
122+
The background chainstate data lingers on disk until the program is restarted.
129123

130124
### Bitcoind restarts sometime after snapshot validation has completed
131125

132-
When bitcoind initializes again, what began as the snapshot chainstate is now
133-
indistinguishable from a chainstate that has been built from the traditional IBD
134-
process, and will be initialized as such.
126+
After a shutdown and subsequent restart, `LoadChainstate()` cleans up the background
127+
chainstate with `ValidatedSnapshotCleanup()`, which renames the `chainstate_snapshot`
128+
datadir as `chainstate` and removes the now unnecessary background chainstate data.
135129

136130
| | |
137131
| ---------- | ----------- |
138132
| number of chainstates | 1 |
139-
| active chainstate | ibd |
133+
| active chainstate | ibd (was snapshot, but is now fully validated) |
134+
135+
What began as the snapshot chainstate is now indistinguishable from a chainstate that
136+
has been built from the traditional IBD process, and will be initialized as such.
137+
138+
A file will be left in `chainstate/base_blockhash`, which indicates that the
139+
chainstate, even though now fully validated, was originally started from a snapshot
140+
with the corresponding base blockhash.

0 commit comments

Comments
 (0)