MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / SnapshotTestSetup

Class SnapshotTestSetup

src/test/validation_chainstatemanager_tests.cpp:211–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211struct SnapshotTestSetup : TestChain100Setup {
212 // Run with coinsdb on the filesystem to support, e.g., moving invalidated
213 // chainstate dirs to "*_invalid".
214 //
215 // Note that this means the tests run considerably slower than in-memory DB
216 // tests, but we can't otherwise test this functionality since it relies on
217 // destructive filesystem operations.
218 SnapshotTestSetup() : TestChain100Setup{
219 {},
220 {
221 .coins_db_in_memory = false,
222 .block_tree_db_in_memory = false,
223 },
224 }
225 {
226 }
227
228 std::tuple<Chainstate*, Chainstate*> SetupSnapshot()
229 {
230 ChainstateManager& chainman = *Assert(m_node.chainman);
231
232 {
233 LOCK(::cs_main);
234 BOOST_CHECK(!chainman.CurrentChainstate().m_from_snapshot_blockhash);
235 BOOST_CHECK(!node::FindAssumeutxoChainstateDir(chainman.m_options.datadir));
236 }
237
238 size_t initial_size;
239 size_t initial_total_coins{100};
240
241 // Make some initial assertions about the contents of the chainstate.
242 {
243 LOCK(::cs_main);
244 CCoinsViewCache& ibd_coinscache = chainman.ActiveChainstate().CoinsTip();
245 initial_size = ibd_coinscache.GetCacheSize();
246 size_t total_coins{0};
247
248 for (CTransactionRef& txn : m_coinbase_txns) {
249 COutPoint op{txn->GetHash(), 0};
250 BOOST_CHECK(ibd_coinscache.HaveCoin(op));
251 total_coins++;
252 }
253
254 BOOST_CHECK_EQUAL(total_coins, initial_total_coins);
255 BOOST_CHECK_EQUAL(initial_size, initial_total_coins);
256 }
257
258 Chainstate& validation_chainstate = chainman.ActiveChainstate();
259
260 // Snapshot should refuse to load at this height.
261 BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(this));
262 BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash);
263
264 // Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can
265 // be found.
266 constexpr int snapshot_height = 110;
267 mineBlocks(10);
268 initial_size += 10;

Callers

nothing calls this directly

Calls 8

ForceFlushStateToDiskMethod · 0.80
ResetChainstatesMethod · 0.80
GetBlocksDirPathMethod · 0.80
ParamsClass · 0.50
sizeMethod · 0.45
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected