bitcoin/src/policy
Samuel Dobson 24abd8312e
Merge bitcoin/bitcoin#22949: fee: Round up fee calculation to avoid a lower than expected feerate
80dc829be7 tests: Calculate fees more similarly to CFeeRate::GetFee (Andrew Chow)
ce2cc44afd tests: Test for assertion when feerate is rounded down (Andrew Chow)
0fbaef9676 fees: Always round up fee calculated from a feerate (Andrew Chow)

Pull request description:

  When calculating the fee for a feerate, it is possible that the final calculation will have fractional satoshis. Currently those are ignored via truncation which results in the absolute fee being rounded down. Rounding down is problematic because it results in a feerate that is slightly lower than the feerate represented by the `CFeeRate` object. A slightly lower feerate particularly causes issues for coin selection as it can trigger an assertion error. To avoid potentially underpaying the feerate (and the assertion), always round up the calculated fee.

  A test is added for the assertion, along with a comment explaining what happens.

  It is unlikely that a user can trigger this as it requires a very specific set of rounding errors to occur as well as the transaction not needing any change and being right on the lower bound of the exact match window. However I was able to trigger the assertion while running coin selection simulations, albeit after thousands of transactions and with some weird feerates.

ACKs for top commit:
  ryanofsky:
    Code review ACK 80dc829be7
  promag:
    Tested ACK 80dc829be7.
  lsilva01:
    tACK 80dc829
  meshcollider:
    utACK 80dc829be7

Tree-SHA512: fe26684c60f236cab48ea6a4600c141ce766dbe59504ec77595dcbd7fd0b34559acc617007f4f499c9155d8fda0a336954413410ba862b19c765c0cfac79d642
2021-11-05 00:08:00 +13:00
..
feerate.cpp fees: Always round up fee calculated from a feerate 2021-10-08 13:53:48 -04:00
feerate.h fees: Always round up fee calculated from a feerate 2021-10-08 13:53:48 -04:00
fees.cpp Merge bitcoin/bitcoin#23258: doc: Fix outdated comments referring to ::ChainActive() 2021-10-20 13:28:28 +08:00
fees.h [MOVEONLY] consensus: move amount.h into consensus 2021-09-30 07:41:57 +08:00
packages.cpp MOVEONLY: context-free package policies 2021-06-02 17:26:44 +01:00
packages.h MOVEONLY: context-free package policies 2021-06-02 17:26:44 +01:00
policy.cpp policy: document we intentionally don't lower the dust threshold for Taproot 2021-09-02 13:41:28 +02:00
policy.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
rbf.cpp [mempool] delete exists(uint256) function 2021-10-21 16:26:59 +01:00
rbf.h add missing includes in policy/rbf 2021-09-20 13:34:48 +01:00
settings.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
settings.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00