BlockAssembler: return selected packages vsize and feerate #30391

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

    This PR enables BlockAssembler to add all selected packages’ feerate and vsize to a vector, and then return the vector as vFeeratePerSize in the CBlockTemplate struct.

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

    The packages’ vsize and fee rates are used in #30157 to determine the 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

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    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:

    • #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?

  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. [BlockAssembler]: return selected packages feerate and vsize
    - The commit also test that block assembler now returns selected package
      vsize's and fee rates.
    
    Co-authored-by: ismaelsadeeq <ask4ismailsadiq@gmail.com>
    8a830f15cf
  18. ismaelsadeeq force-pushed on Aug 12, 2024
  19. Theschorpioen approved
  20. rkrux approved
  21. rkrux commented at 2:16 pm on August 12, 2024: none
    reACK 8a830f1
  22. achow101 requested review from Sjors on Oct 15, 2024
  23. achow101 requested review from josibake on Oct 15, 2024

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-10-31 06:12 UTC

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