| 36 | //! Test resizing coins-related Chainstate caches during runtime. |
| 37 | //! |
| 38 | BOOST_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 | |
| 77 | BOOST_FIXTURE_TEST_CASE(connect_tip_does_not_cache_inputs_on_failed_connect, TestChain100Setup) |
| 78 | { |
nothing calls this directly
no test coverage detected