3
3
Assumeutxo is a feature that allows fast bootstrapping of a validating bitcoind
4
4
instance with a very similar security model to assumevalid.
5
5
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.
9
9
10
10
## General background
11
11
@@ -22,10 +22,6 @@ be of use.
22
22
chainstate running asynchronously in the background. We also use this flag to control
23
23
which index entries are added to setBlockIndexCandidates during LoadBlockIndex().
24
24
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
-
29
25
- The concept of UTXO snapshots is treated as an implementation detail that lives
30
26
behind the ChainstateManager interface. The external presentation of the changes
31
27
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.
76
72
77
73
Once the snapshot chainstate is loaded and validated, it is promoted to active
78
74
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.
82
84
83
85
| | |
84
86
| ---------- | ----------- |
@@ -88,7 +90,7 @@ active on node startup (via `DetectSnapshotChainstate()`).
88
90
The snapshot begins to sync to tip from its base block, technically in parallel with
89
91
the original chainstate, but it is given priority during block download and is
90
92
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.
92
94
93
95
** Failure consideration:** if shutdown happens at any point during this phase, both
94
96
chainstates will be detected during the next init and the process will resume.
@@ -107,33 +109,32 @@ sequentially.
107
109
### Background chainstate hits snapshot base block
108
110
109
111
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 ` .
119
116
120
117
| | |
121
118
| ---------- | ----------- |
122
119
| number of chainstates | 2 (ibd has ` m_disabled=true ` ) |
123
120
| active chainstate | snapshot |
124
121
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.
129
123
130
124
### Bitcoind restarts sometime after snapshot validation has completed
131
125
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 .
135
129
136
130
| | |
137
131
| ---------- | ----------- |
138
132
| 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