BlockAssembler: return selected packages virtual size and fee #30391

pull ismaelsadeeq wants to merge 1 commits into bitcoin:master from ismaelsadeeq:07-2024-miner-return-package-sizes-and-fees changing 3 files +25 −4
  1. ismaelsadeeq commented at 11:04 am on July 4, 2024: member

    This PR enables BlockAssembler to add all selected packages’ feer and vrtual size to a vector, and then return the vector as a member of CBlockTemplate struct.

    This PR is the first step in the #30157 project.

    The packages’ vsize and fee are used in #30157 to select a percentile fee rate of the top block in the mempool.

  2. DrahtBot commented at 11:04 am on July 4, 2024: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30391.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Stale ACK rkrux

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #31318 (Drop script_pub_key arg from createNewBlock by Sjors)
    • #31283 (Add waitNext() to BlockTemplate interface by Sjors)
    • #31122 (cluster mempool: Implement changeset interface for mempool by sdaftuar)

    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.

  3. in src/policy/feerate.cpp:1 in 550a6c29e0 outdated


    maflcko commented at 3:53 pm on July 5, 2024:

    first commit: could adjust the test

    0src/test/amount_tests.cpp:86:    // Maximum size in bytes, should not crash
    

    To std::numeric_limits<uint64_t>::max() >> 1 ?

    And

    0src/test/fuzz/fee_rate.cpp:23:    const auto bytes = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
    

    to fuzzed_data_provider.ConsumeIntegral<uint64_t>() >> 1?


    ismaelsadeeq commented at 8:21 am on July 8, 2024:

    This causes a fuzz failure during the conversion of the size to feerate per KB because CAmount is int64_t.

    So I reverted back and static_cast the packageSize to be uint32_t, it is safe to do so because we are certain that nSizeWithAncestors will always be positive in BlockAssembler::addPackageTxs.


    It’s already done https://github.com/bitcoin/bitcoin/blob/bd5d1688b4311e21c0e0ff89a3ae02ef7d0543b8/src/node/miner.cpp#L365


    maflcko commented at 8:31 am on July 8, 2024:

    This causes a fuzz failure during the conversion of the size to feerate per KB because CAmount is int64_t.

    The fuzz failure is because you also changed MultiplicationOverflow to uint64_t, which is wrong.


    maflcko commented at 8:32 am on July 8, 2024:

    So I reverted back and static_cast the packageSize to be uint32_t, it is safe to do so because we are certain that nSizeWithAncestors will always be positive in BlockAssembler::addPackageTxs.

    Another thing to consider is that the package size is small enough to be representable in uint32_t.


    ismaelsadeeq commented at 8:50 am on July 8, 2024:

    Yeah thanks.


    unrelated but I wonder why we are using this big data type to represent size, not only while working in this PR, there are size datype inconsistencies in several places which sometimes cause overflows during calculation.

    Is it safe to instead represent a type alias for size just like it was done for CAmount in consensus/amount.h. And prevent generating large values for size in the fuzz test?

    Apart from the fuzz test size can never be greater than 4,000,000? https://github.com/bitcoin/bitcoin/blob/bd5d1688b4311e21c0e0ff89a3ae02ef7d0543b8/src/consensus/consensus.h#L12-L15


    ismaelsadeeq commented at 8:55 am on July 8, 2024:

    The fuzz failure is because you also changed MultiplicationOverflow to uint64_t, which is wrong.

    Yeah, I did that because MultiplicationOverflow requires that the type of both parameters be the same.


    maflcko commented at 9:27 am on July 8, 2024:

    Apart from the fuzz test size can never be greater than 4,000,000?

    In blocks, yes. In the mempool, it may depend on the user’s config.


    ismaelsadeeq commented at 10:04 am on July 8, 2024:
    thanks the commit is gone now.
  4. ismaelsadeeq force-pushed on Jul 6, 2024
  5. DrahtBot added the label CI failed on Jul 6, 2024
  6. ismaelsadeeq force-pushed on Jul 7, 2024
  7. DrahtBot removed the label CI failed on Jul 7, 2024
  8. ismaelsadeeq force-pushed on Jul 8, 2024
  9. ismaelsadeeq force-pushed on Jul 8, 2024
  10. in src/node/miner.h:44 in 83ac35e3eb outdated
    39@@ -38,6 +40,7 @@ struct CBlockTemplate
    40     std::vector<CAmount> vTxFees;
    41     std::vector<int64_t> vTxSigOpsCost;
    42     std::vector<unsigned char> vchCoinbaseCommitment;
    43+    std::vector<std::tuple<CFeeRate, uint32_t>> vFeeratePerSize;
    


    glozow commented at 11:22 am on July 10, 2024:
    probably FeeFrac would be better? CFeeRate loses precision and can be inferred from the fee and size

    ismaelsadeeq commented at 11:39 am on July 12, 2024:

    @glozow

    probably FeeFrac would be better? CFeeRate loses precision and can be inferred from the fee and size

    We will be using the package size to calculate the percentile package and select its fee rate as an estimate to return to the user.

    We then have to convert the fee and size to fee rate either by CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes).GetFeePerK or introduce and use a similar GetFeeRate method for the FeeFrac struct.

    So, I think using CFeeRate is okay for getting MEMPOOL_FORECAST estimate.


    I think the place we could benefit from changing this to FeeFrac is when comparing forecasters’ estimates.

    But this can’t be done now because the BLOCK_POLICY_ESTIMATOR forecaster performs its operations in nSatoshiPerK and returns a CFeeRate value as an estimate.

    It will require a refactor to change BLOCK_POLICY_ESTIMATOR to use and return FeeFrac as an estimate.

    But the forecasters estimates are values greater than 1 s/vb. Given this, I think using CFeeRate is okay and will avoid the conversions, or adding duplicate GetFeePerK method for FeeFrac and refactoring CBlockPolicyEstimator to use FeeFrac?


    ismaelsadeeq commented at 9:28 pm on November 4, 2024:
    @glozow, is the idea of making CFeeRate a wrapper around FeeFrac better, as suggested #30535 (comment)? If so, then no changes are needed, and we can proceed with this approach while pursuing that direction and mark this comment as resolved. Otherwise, I’m happy to change this to FeeFrac as you suggested if it’s a blocking comment.

    glozow commented at 8:11 pm on November 5, 2024:
    Nonblocking, I can understand it’s a larger change to use it.

    ismaelsadeeq commented at 8:34 pm on November 8, 2024:

    I’ve updated the code to use FeeFrac, and it simplified things – no need for tuples from the initial approach, just a vector of FeeFrac values which achieved same aim.

    Smaller diff and no precision loss 💯 I will update all the dependent commits to follow suite.

  11. DrahtBot added the label Needs rebase on Jul 18, 2024
  12. ismaelsadeeq force-pushed on Jul 18, 2024
  13. DrahtBot removed the label Needs rebase on Jul 18, 2024
  14. in src/test/miner_tests.cpp:182 in f581657b3a outdated
    181+
    182+    CFeeRate packageRate(packageFee, packageSize);
    183+    auto packageFeeRateFound = findFeeRate(blockFeeAndVsizes, packageRate);
    184+
    185+    CFeeRate mediumRate(mediumFeeTx.GetFee(), mediumFeeTx.GetTxSize());
    186+    auto mediumTxFeeRateFound = findFeeRate(blockFeeAndVsizes, mediumRate);
    


    rkrux commented at 11:58 am on August 11, 2024:
    IMO, depending upon finding only the feeRate in the vector of tuples gets rid of some level of robustness in the verification here because it ignores the possibility of duplicate feeRates, and makes the tester/author wary of writing the test in a way that ensures there are no duplicates. How about also checking for the packageSize as well?

    ismaelsadeeq commented at 8:41 am on August 12, 2024:
    That makes sense. I removed findFeeRate and explicitly checked the vector for the packages and verify the fee and size were as expected. I also took the opportunity to change the variables to be initialized uniformly.

    rkrux commented at 2:16 pm on August 12, 2024:
    Thank you for accepting the suggestion, the diff now has become smaller and to the point.
  15. rkrux approved
  16. rkrux commented at 11:59 am on August 11, 2024: none

    tACK f581657

    make, make check are successful. Left a suggestion. Thanks for keeping the PR short and focussed.

  17. ismaelsadeeq force-pushed on Aug 12, 2024
  18. Theschorpioen approved
  19. rkrux approved
  20. rkrux commented at 2:16 pm on August 12, 2024: none
    reACK 8a830f1
  21. achow101 requested review from Sjors on Oct 15, 2024
  22. achow101 requested review from josibake on Oct 15, 2024
  23. miner: `CreateNewBlock` will now track fee and virtual size of selected packages
    - The commit also tests this new behaviour.
    
    Co-authored-by: willcl-ark <will@256k1.dev>
    4dcea3afbc
  24. ismaelsadeeq force-pushed on Nov 7, 2024
  25. ismaelsadeeq renamed this:
    BlockAssembler: return selected packages vsize and feerate
    BlockAssembler: return selected packages virtual size and fee
    on Nov 7, 2024
  26. Sjors commented at 3:38 pm on November 8, 2024: member

    Just a comment about how this interacts with the Mining interface changes I’m working on.

    The Mining interface contains BlockTemplate:

    https://github.com/bitcoin/bitcoin/blob/018e5fcc462caebb25cf5d3eb6a19dc2787466c8/src/interfaces/mining.h#L31-L40

    I wonder if adding a field to CBlockTemplate would cause a breaking change for clients connecting via IPC. cc @ryanofsky?

    Update: I don’t think it does, because the interface doesn’t use CBlockTemplate directly.

    In any case it won’t matter as long as this PR is merged before v29, since we don’t ship the interface until then, so there’s clients to break.

  27. ismaelsadeeq commented at 10:00 pm on November 14, 2024: member

    so there’s clients to break. @Sjors, could you clarify your coment? Which clients would this affect?

  28. Sjors commented at 8:29 am on November 15, 2024: member

    @ismaelsadeeq are you referring to my statement at the end “so there’s clients to break”?

    Once we release the Mining interface, and multiprocess, people can build clients. If we then make changes in the next release, we could break those clients. But that’s not an issue yet.

  29. DrahtBot added the label Needs rebase on Nov 20, 2024
  30. DrahtBot commented at 2:49 pm on November 20, 2024: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.


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-11-23 18:12 UTC

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