miner: bug fix? update for ancestor inclusion using modified fees, not base #24538

pull glozow wants to merge 3 commits into bitcoin:master from glozow:2022-03-miner-prioritised changing 2 files +138 −49
  1. glozow commented at 4:55 PM on March 11, 2022: member

    Came up while reviewing #24364, where some of us incorrectly assumed that we use the same fee deduction in CTxMemPoolModifiedEntry::nModFeesWithAncestors when first constructing an entry and in update_for_parent_inclusion.

    Actually, the behavior is this: when a mempool entry's ancestor is included in the block template, we create a CTxMemPoolModifiedEntry for it, subtracting the ancestor's modified fees from nModFeesWithAncestors. If another ancestor is included, we update it again, but use the ancestor's base fees instead.

    I can't explain why we use GetFee in one place and GetModifiedFee in the other, but I'm quite certain we should be using the same one for both.

    And should it be base or modified fees? Modified, otherwise the child inherits the prioritisation of the parent, but only until the parent gets mined. If we want prioritisation to cascade down to current in-mempool descendants, we should probably document that in the prioritsetransaction helpstring and implement it in CTxMemPool::mapDeltas, not as a quirk in the mining code?

    Wrote a test in which a mempool entry has 2 ancestors, both prioritised, and both included in a block template individually. This test should fail without the s/GetFee/GetModifiedFee commit.

  2. glozow added the label Mining on Mar 11, 2022
  3. glozow commented at 4:55 PM on March 11, 2022: member
  4. in src/node/miner.h:119 in 1177b7965f outdated
     115 | @@ -116,7 +116,7 @@ struct update_for_parent_inclusion
     116 |  
     117 |      void operator() (CTxMemPoolModifiedEntry &e)
     118 |      {
     119 | -        e.nModFeesWithAncestors -= iter->GetFee();
     120 | +        e.nModFeesWithAncestors -= iter->GetModifiedFee();
    


    sdaftuar commented at 4:57 PM on March 11, 2022:

    Oops. Good catch!

  5. MarcoFalke commented at 4:59 PM on March 11, 2022: member

    Concept ACK

  6. MarcoFalke cross-referenced this on Mar 11, 2022 from issue refactor: remove duplicate code from BlockAssembler by jamesob
  7. DrahtBot commented at 9:33 PM on March 12, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24595 (deploymentstatus: move g_versionbitscache global to ChainstateManager by ajtowns)

    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.

  8. DrahtBot cross-referenced this on Mar 13, 2022 from issue policy: Remove unused locktime flags by MarcoFalke
  9. MOVEONLY: group miner tests into MinerTestingSetup functions
    No behavior changes. Recommend using --color-moved=dimmed_zebra.
    0f9a44461c
  10. [miner] bug fix: update for parent inclusion using modified fee 7a8d60676b
  11. [unit test] prioritisation in mining e4303c337c
  12. glozow force-pushed on Mar 14, 2022
  13. glozow commented at 4:04 PM on March 14, 2022: member

    Rebased for #24080.

  14. DrahtBot cross-referenced this on Mar 19, 2022 from issue deploymentstatus: move g_versionbitscache global to ChainstateManager by ajtowns
  15. theStack commented at 6:11 PM on April 20, 2022: contributor

    Concept ACK

  16. ccdle12 commented at 9:56 AM on April 25, 2022: contributor

    tested ACK e4303c3

    and I guess concept ACK as well, since it seems undesirable for a miner to think they are prioritizing a single tx but actually has after effects on other txs (descendants) in terms of selection

  17. DrahtBot cross-referenced this on Apr 29, 2022 from issue refactor: Remove unused CTxMemPool::clear() helper by MarcoFalke
  18. MarcoFalke commented at 9:04 AM on May 6, 2022: member

    LGTM. I also checked that without the fix, CNB will incorrectly include the 0-fee, non-prioritized child:

    diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
    index 7e26e732f5..fa67ddb419 100644
    --- a/src/test/miner_tests.cpp
    +++ b/src/test/miner_tests.cpp
    @@ -530,15 +530,15 @@ void MinerTestingSetup::TestPrioritisedMining(const CChainParams& chainparams, c
         m_node.mempool->addUnchecked(entry.Fee(0).SpendsCoinbase(false).FromTx(tx));
     
         auto pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
    -    BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6U);
    +    BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 7U);
         BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashFreeParent);
         BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashFreePrioritisedTx);
         BOOST_CHECK(pblocktemplate->block.vtx[3]->GetHash() == hashParentTx);
         BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashPrioritsedChild);
         BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashFreeChild);
    +        // The FreeParent and FreeChild's prioritisations *does* impact the child.
    +        BOOST_CHECK(pblocktemplate->block.vtx[6]->GetHash() == hashFreeGrandchild);
         for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
    -        // The FreeParent and FreeChild's prioritisations should not impact the child.
    -        BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeGrandchild);
             // De-prioritised transaction should not be included.
             BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashMediumFeeTx);
         }
    
  19. MarcoFalke commented at 9:05 AM on May 6, 2022: member

    ACK e4303c337c8423f21c2c72ee1bcca3aaf46fa1cb 🚗

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

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    ACK e4303c337c8423f21c2c72ee1bcca3aaf46fa1cb 🚗
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUhmJAwAuY9dx5XOXwABGKOcz5KDvk2LekoeYMJgUe9H0Lql2sEi/BcZcU95c3HN
    f3yRTEHWneiqhUz4jNcks+wXTM2e93wSTGZc0AxF20B2VUlnks1MD5EC1MQK2Bzc
    Ip+yh43QZck21xoyyyOnBjiVO0gk8a+AAjSxHRmGB5rni2dEhSFX/nZef9fEGZq2
    Cjp65fd8V6JOHiMIdHrscp228jm5K8Dsa/c6ucqGZuab8kl9vFj/GpV4FrisIlFo
    7t6fJv9fSb6MWILwr3C7Hu8hDZr2Dhd13O1T2afhoBxD9W2sfLQcmtTuQvjZl5qt
    St5PtWeztYcaMKWUlBcFHjsbdatTFYosA2qFiCHRUPGwf/UBeEGZlz0XlqvzRD9X
    nMj+/oSGKSStTSszhIyIk7DHb4ZhRmKkq7n32GBSZq4qGXmmfy8S00LwQO1I8OOK
    PhISXSJ3aj0O4w7KrgmrwrnP8do257J4NCk1v9NHFtEmxBN8p96t1rPqYg+bBwdm
    xhL7ZPDe
    =zM+y
    -----END PGP SIGNATURE-----
    

    </details>

  20. MarcoFalke merged this on May 6, 2022
  21. MarcoFalke closed this on May 6, 2022

  22. glozow deleted the branch on May 8, 2022
  23. sidhujag referenced this in commit c8d2687323 on May 9, 2022
  24. Fabcien referenced this in commit be44aca7ae on Jan 6, 2023
  25. bitcoin locked this on May 8, 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: 2026-05-19 06:53 UTC