test: construct fee estimator test transactions declaratively #36797

pull yuvicc wants to merge 2 commits into bitcoin:master from yuvicc:test-declarative-blockpolicyestimator changing 2 files +43 −56
  1. yuvicc commented at 7:52 AM on November 7, 2026: contributor

    Part of #36692.

    blockpolicyestimator_tests: Replace the transaction template, whose prevout index was overwritten to make each txid unique, with make_tx(), which constructs each transaction with COutPoint, CTxIn and CTxOut constructor calls.

    Move the code that submits a transaction to the estimator, which was repeated in three places, into add_tx(). Each transaction is now built once and shared between its mempool entry and the estimator. The transactions submitted to the estimator and its estimates are unchanged.

    mempool_fee_estimator_tests: Construct the input and output of MakeRandomTx() in place instead of resizing the vectors and assigning each field afterwards. Apart from the random prevout hash, the transaction is identical to before.

  2. DrahtBot added the label Tests on Nov 7, 2026
  3. DrahtBot commented at 7:52 AM on November 7, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK alexanderwiederin, maflcko

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35713 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35713.svg"></sub> (Remove boost as a unit test runner by rustaceanrob)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. yuvicc renamed this:
    test: construct `blockpolicyestimator_tests` transactions declaratively
    test: construct fee estimator test transactions declaratively
    on Nov 7, 2026
  5. yuvicc marked this as ready for review on Nov 7, 2026
  6. in src/test/blockpolicyestimator_tests.cpp:39 in 89d3808d91


    alexanderwiederin commented at 3:37 PM on November 9, 2026:

    This comment is not accurate anymore.

  7. in src/test/blockpolicyestimator_tests.cpp:59 in 89d3808d91
      60 |  
      61 |      // Create a fake block
      62 |      std::vector<RemovedMempoolTransactionInfo> block_txs;
      63 |      int blocknum = 0;
      64 |  
      65 | +    const auto add_tx{[&](int j, int k) {
    


    alexanderwiederin commented at 6:11 PM on November 9, 2026:

    The extraction hides the blocknum dependency that the inline code made visible: add_tx(j, k) reads blocknum, which changes between calls, through the capture.

    I would recommend at least passing the arguments that change between calls:

    const auto add_tx{[&](CAmount fee, int height, uint32_t prevout_n) {...}
    

    A standalone function with no captured state would probably be ideal, but to stay in the scope of #36692 I would stick to that.


    yuvicc commented at 5:41 AM on November 10, 2026:

    Make sense. Thanks.

  8. in src/test/blockpolicyestimator_tests.cpp:81 in 89d3808d91
      95 | -                                                                                  /*mempool_limit_bypassed=*/false,
      96 | -                                                                                  /*submitted_in_package=*/false,
      97 | -                                                                                  /*chainstate_is_current=*/true,
      98 | -                                                                                  /*has_no_mempool_parents=*/true)};
      99 | -                feeEst.processTransaction(tx_info);
     100 | +                mempool_txs[j].push_back(add_tx(j, k));
    


    alexanderwiederin commented at 6:16 PM on November 9, 2026:

    Follow-up to the add_tx signature suggestion above:

    mempool_txs[j].push_back(add_tx(feeV[j], blocknum, 10000 * blocknum + 100 * j + k)); // make transaction unique
    
  9. in src/test/blockpolicyestimator_tests.cpp:184 in 89d3808d91
     179 | @@ -183,22 +180,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
     180 |      while (blocknum < 665) {
     181 |          for (int j = 0; j < 10; j++) { // For each fee multiple
     182 |              for (int k = 0; k < 4; k++) { // add 4 fee txs
     183 | -                tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
     184 |                  // These txs are mined in the same block, so there is no need to
     185 |                  // retain them in mempool_txs; use a local entry to build block_txs.
    


    alexanderwiederin commented at 6:17 PM on November 9, 2026:

    There’s no local entry anymore, so the second half of this comment is stale.

  10. alexanderwiederin changes_requested
  11. alexanderwiederin commented at 6:20 PM on November 9, 2026: contributor

    The helper goes slightly beyond the scope of #36692, but I think it's worth it here.

    Nice!

  12. yuvicc force-pushed on Nov 10, 2026
  13. yuvicc commented at 5:52 AM on November 10, 2026: contributor

    Addressed some nits on stale comments(comment & comment) and change the arguments in add_tx method comment.

  14. in src/test/blockpolicyestimator_tests.cpp:58 in 304894f484 outdated
      60 | +    CFeeRate baseRate(basefee, GetVirtualTransactionSize(*make_tx(0)));
      61 |  
      62 |      // Create a fake block
      63 |      std::vector<RemovedMempoolTransactionInfo> block_txs;
      64 |      int blocknum = 0;
      65 |  
    


    alexanderwiederin commented at 9:06 AM on November 10, 2026:

    nit, only if you retouch: the refactor dropped the comment explaining the manual processTransaction() call:

    // Simulate a transaction entering the mempool by calling
    // processTransaction(), and return its mempool entry for mining later.
    

    yuvicc commented at 2:20 PM on November 10, 2026:

    Done, thanks.

  15. alexanderwiederin approved
  16. alexanderwiederin commented at 9:06 AM on November 10, 2026: contributor

    ACK 4ff2588a1f3227778b532cdca085a189b543bb9c

  17. in src/test/blockpolicyestimator_tests.cpp:43 in 4ff2588a1f
      45 | -    tx.vin.resize(1);
      46 | -    tx.vin[0].scriptSig = garbage;
      47 | -    tx.vout.resize(1);
      48 | -    tx.vout[0].nValue=0LL;
      49 | -    CFeeRate baseRate(basefee, GetVirtualTransactionSize(CTransaction(tx)));
      50 | +    const auto make_tx{[&](uint32_t prevout_n) {
    


    purpleKarrot commented at 1:18 PM on November 10, 2026:

    Personal preference: I really dislike curly braces directly attached to variable names. I think it severely impacts readability. I prefer to always use = for initialization, with the type on the right-hand side when explicit construction is required. This provides a clear visual separation between the variable declaration and its initializer.

    Rather than I prefer
    int count{0}; auto count = 0;
    std::string name{"foo"}; auto name = std::string{"foo"};
    Widget widget{}; auto widget = Widget{};
    Widget widget{a, b}; auto widget = Widget{a, b};
    std::vector<int> v{1, 2, 3}; auto v = std::vector{1, 2, 3};
    auto f{[a](int x) { return x + a; }}; auto f = [a](int x) { return x + a; };

    yuvicc commented at 2:06 PM on November 10, 2026:

    Alright, that would make it more readable and also developer doc doesn't explicitly mentions about lambdas. I'll change that.

  18. yuvicc force-pushed on Nov 10, 2026
  19. yuvicc commented at 2:22 PM on November 10, 2026: contributor
  20. test: construct blockpolicyestimator_tests transactions declaratively
    Replace the transaction template, whose prevout index was overwritten
    to make each txid unique, with make_tx(), which constructs each
    transaction with COutPoint, CTxIn and CTxOut constructor calls.
    
    Move the code that submits a transaction to the estimator, which was
    repeated in three places, into add_tx(). Each transaction is now built
    once and shared between its mempool entry and the estimator.
    
    The transactions submitted to the estimator and its estimates are
    unchanged.
    4ee2adf54a
  21. test: construct mempool_fee_estimator_tests transactions declaratively
    Build the input and output of MakeRandomTx() in place instead of
    resizing the vectors and assigning each field afterwards.
    235fee0e1a
  22. in src/test/blockpolicyestimator_tests.cpp:43 in a448ea565b
      45 | -    tx.vin.resize(1);
      46 | -    tx.vin[0].scriptSig = garbage;
      47 | -    tx.vout.resize(1);
      48 | -    tx.vout[0].nValue=0LL;
      49 | -    CFeeRate baseRate(basefee, GetVirtualTransactionSize(CTransaction(tx)));
      50 | +    const auto make_tx = [&](uint32_t prevout_n) {
    


    maflcko commented at 3:09 PM on November 10, 2026:

    nit: should move/copy garbage instead of taking a mutable ref?


    yuvicc commented at 4:49 PM on November 10, 2026:

    Done, thanks.

  23. yuvicc force-pushed on Nov 10, 2026
  24. yuvicc commented at 4:50 PM on November 10, 2026: contributor

    make_tx now captures garbage by move instead of by mutable reference suggestion by @maflcko

  25. alexanderwiederin commented at 6:18 PM on November 10, 2026: contributor

    ACK 235fee0e1afc4fb771adacbdcf169cf80aca23ff

  26. maflcko commented at 11:14 AM on November 11, 2026: member

    review ACK 235fee0e1afc4fb771adacbdcf169cf80aca23ff 🍪

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: review ACK 235fee0e1afc4fb771adacbdcf169cf80aca23ff 🍪
    kGQI/QFL4laAdkKA2i2AnpqpeudYolF4EuAr0WGGeA9IozoggIQhHUaDm51rp0wbCnSbMShqrfg1FDaaXW0BCQ==
    

    </details>

  27. yuvicc requested review from purpleKarrot on Nov 12, 2026

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: 2026-11-18 16:51 UTC

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