bench: MempoolCheck actually runs with check_ratio = 0 #24634

issue dongcarl openend this issue on March 22, 2022
  1. dongcarl commented at 2:40 am on March 22, 2022: member

    For MempoolCheck, it seems that the intention was to have a mempool with check_ratio = 1 (see -checkmempool=1):

    https://github.com/bitcoin/bitcoin/blob/e66630cc87c017f40ec29f6c1edf2ed5a286e49d/src/bench/mempool_stress.cpp#L102-L116

    However in the subsequent line in the above snippet, a CTxMemPool gets constructed with no arguments, which means that check_ratio will default to 0:

    https://github.com/bitcoin/bitcoin/blob/e66630cc87c017f40ec29f6c1edf2ed5a286e49d/src/txmempool.h#L571

    Manually specifying check_ratio to 1 (according to the original intention) and running the MempoolCheck benchmark results in an assertion error:

     0diff --git a/src/bench/mempool_stress.cpp b/src/bench/mempool_stress.cpp
     1index afa4618e1b..32cdb70539 100644
     2--- a/src/bench/mempool_stress.cpp
     3+++ b/src/bench/mempool_stress.cpp
     4@@ -105,7 +105,7 @@ static void MempoolCheck(benchmark::Bench& bench)
     5     const int childTxs = bench.complexityN() > 1 ? static_cast<int>(bench.complexityN()) : 2000;
     6     const std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 5);
     7     const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN, {"-checkmempool=1"});
     8-    CTxMemPool pool;
     9+    CTxMemPool pool{nullptr, 1};
    10     LOCK2(cs_main, pool.cs);
    11     const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
    12     for (auto& tx : ordered_coins) AddTx(tx, pool);
    
    0$ ./src/bench/bench_bitcoin -filter='MempoolCheck'
    1...
    2bench_bitcoin: txmempool.cpp:759: void CTxMemPool::check(const CCoinsViewCache &, int64_t) const: Assertion `mempoolDuplicate.HaveCoin(txin.prevout)' failed.
    

    Aside from this problem, we should also probably just re-use the CTxMemPool in TestingSetup.

    Ping @glozow

  2. glozow commented at 11:17 am on March 22, 2022: member

    Wow, good catch! No wonder it runs so fast, we’re benching a no-op… :facepalm:

    Aside from this problem, we should also probably just re-use the CTxMemPool in TestingSetup.

    Agreed.

    Manually specifying check_ratio to 1 (according to the original intention) and running the MempoolCheck benchmark results in an assertion error:

    This is because CreateOrderedCoins references UTXOs which don’t actually exist on chain to construct transactions. My bad for not realizing that. The solution is to either use a TestChain100Setup instead of TestingSetup so we have some coins to work with, or create a fake CCoinsCache with the UTXOs needed in CreateOrderedCoins.

  3. glozow added the label Bug on Mar 22, 2022
  4. dongcarl commented at 7:31 pm on March 22, 2022: member
    It seems like you care about min_ancestors here, so perhaps TestChain100Setup wouldn’t work well?
  5. glozow commented at 11:48 pm on April 18, 2022: member
    I don’t think min_ancestors is an issue, but using TestChain100Setup slows it down massively. I guess the solution is to make a fake CCoinsCache, but at that point we’re just testing that we can use a coins cache properly. Leaning towards just deleting the test. We call check() all the time in functional tests anyway…
  6. dongcarl commented at 6:43 pm on April 19, 2022: member
    Slows it down because there are too many coins?
  7. glozow commented at 7:03 pm on April 19, 2022: member
    I think because it has to initialize TestChain100Setup (which involves mining 100 blocks and some other stuff)
  8. mzumsande commented at 7:20 pm on April 19, 2022: member
    What do you mean with “slows it down massively” and why is that important? It’s only done once during the setup part, whereas the actual benchmark just calls check() in a loop and should be unaffected by this.
  9. glozow commented at 11:50 pm on April 19, 2022: member

    Omg, thanks for keeping me honest @dongcarl @mzumsande. You’re right that it makes no sense, not sure why my “massive slowdown” happened yesterday but I tried again from scratch today and it seems to work.

    I’ve opened #24927 to fix this in the original way proposed: “use a TestChain100Setup instead of TestingSetup so we have some coins to work with,” adding a PopulateMempool() util function to randomly add a bunch of transactions to the mempool.

  10. laanwj closed this on Jun 2, 2022

  11. DrahtBot locked this on Jun 2, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me