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

Function BOOST_AUTO_TEST_CASE

src/test/validation_chainstate_tests.cpp:38–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36//! Test resizing coins-related Chainstate caches during runtime.
37//!
38BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
39{
40 ChainstateManager& manager = *Assert(m_node.chainman);
41 CTxMemPool& mempool = *Assert(m_node.mempool);
42 Chainstate& c1 = WITH_LOCK(cs_main, return manager.InitializeChainstate(&mempool));
43 c1.InitCoinsDB(
44 /*cache_size_bytes=*/8_MiB, /*in_memory=*/true, /*should_wipe=*/false);
45 WITH_LOCK(::cs_main, c1.InitCoinsCache(8_MiB));
46 BOOST_REQUIRE(c1.LoadGenesisBlock()); // Need at least one block loaded to be able to flush caches
47
48 // Add a coin to the in-memory cache, upsize once, then downsize.
49 {
50 LOCK(::cs_main);
51 const auto outpoint = AddTestCoin(m_rng, c1.CoinsTip());
52
53 // Set a meaningless bestblock value in the coinsview cache - otherwise we won't
54 // flush during ResizecoinsCaches() and will subsequently hit an assertion.
55 c1.CoinsTip().SetBestBlock(m_rng.rand256());
56
57 BOOST_CHECK(c1.CoinsTip().HaveCoinInCache(outpoint));
58
59 c1.ResizeCoinsCaches(
60 16_MiB, // upsizing the coinsview cache
61 4_MiB // downsizing the coinsdb cache
62 );
63
64 // View should still have the coin cached, since we haven't destructed the cache on upsize.
65 BOOST_CHECK(c1.CoinsTip().HaveCoinInCache(outpoint));
66
67 c1.ResizeCoinsCaches(
68 4_MiB, // downsizing the coinsview cache
69 8_MiB // upsizing the coinsdb cache
70 );
71
72 // The view cache should be empty since we had to destruct to downsize.
73 BOOST_CHECK(!c1.CoinsTip().HaveCoinInCache(outpoint));
74 }
75}
76
77BOOST_FIXTURE_TEST_CASE(connect_tip_does_not_cache_inputs_on_failed_connect, TestChain100Setup)
78{

Callers

nothing calls this directly

Calls 8

AddTestCoinFunction · 0.85
InitCoinsDBMethod · 0.80
InitCoinsCacheMethod · 0.80
LoadGenesisBlockMethod · 0.80
rand256Method · 0.80
HaveCoinInCacheMethod · 0.80
ResizeCoinsCachesMethod · 0.80
SetBestBlockMethod · 0.45

Tested by

no test coverage detected