Merge rust-bitcoin/rust-bitcoin#3604: Add constructor to `FeeRate`

b96501981f feat(units): add kvb constructor to `FeeRate` (Rob N)

Pull request description:

  This is partially to check my understanding. I did poorly in physics class as part of my misunderstanding of unit conversions.

  The `feefilter` message expresses the fee as satoshis per 1,000 vbyte, see the [p2p handling](1dda1892b6/src/net_processing.cpp (L5331)) which calls [this function](https://github.com/bitcoin/bitcoin/blob/master/src/policy/feerate.h#L63) on the mempool. I presume all that needs to happen to express this in `kwu` is to divide by 4, but ideally a `FeeRate` may be constructed directly from a `feefilter` message using a constructor.

  My conversion is (sat / kvb * kvb / 4 kwu)

ACKs for top commit:
  sanket1729:
    ACK b96501981f.
  apoelstra:
    ACK b96501981ffef1d32c839cd44861736ce3683964; successfully ran local tests
  tcharding:
    ACK b96501981f

Tree-SHA512: 5aec75d253a0955bfe0bdec42d2e13b69602da057ec7769126399473799455f8df1691f98f6e8dc1d6338958e05702a846d0a5f00bce6aa9079c2ceb0c54df0f
This commit is contained in:
merge-script 2024-11-13 00:19:50 +00:00
commit 708522394b
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 0 deletions

View File

@ -62,6 +62,9 @@ impl FeeRate {
/// Constructs a new [`FeeRate`] from satoshis per virtual bytes without overflow check. /// Constructs a new [`FeeRate`] from satoshis per virtual bytes without overflow check.
pub const fn from_sat_per_vb_unchecked(sat_vb: u64) -> Self { FeeRate(sat_vb * (1000 / 4)) } pub const fn from_sat_per_vb_unchecked(sat_vb: u64) -> Self { FeeRate(sat_vb * (1000 / 4)) }
/// Constructs a new [`FeeRate`] from satoshis per kilo virtual bytes (1,000 vbytes).
pub const fn from_sat_per_kvb(sat_kvb: u64) -> Self { FeeRate(sat_kvb / 4) }
/// Returns raw fee rate. /// Returns raw fee rate.
/// ///
/// Can be used instead of `into()` to avoid inference issues. /// Can be used instead of `into()` to avoid inference issues.