Skip to content

Delegate FeeRate::to_sat_per_vb_ceil back to rust-bitcoin after the units 1.0 bump #1122

Description

@thunderbiscuit

#1076 fixes an overflow in FeeRate for fee rates near u64::MAX sat/kwu. The overflow is in rust-bitcoin's bitcoin-units 0.1.x, which rounds up with (sat_kwu + 249) / 250.

To fix it, #1076 stopped calling the upstream code in two places:

  • FeeRate::to_sat_per_vb_ceil does its own rounding with self.0.to_sat_per_kwu().div_ceil(250)
  • impl Display for FeeRate no longer calls upstream's {:#} formatter. It builds the same "{}.00 sat/vbyte" string itself.

Upstream status

This is fixed on rust-bitcoin master. In bitcoin-units 1.0 (currently 1.0.0-rc.4, used by the bitcoin 0.33 betas), to_sat_per_vb_ceil is implemented with div_ceil and does not overflow.

Todo when we move to bitcoin 0.33.0

  • Change FeeRate::to_sat_per_vb_ceil back to calling self.0.to_sat_per_vb_ceil().
  • Check whether ExtractTxError::AbsurdFeeRate still needs to convert through crate::bitcoin::FeeRate before calling to_sat_per_vb_ceil, or can call the upstream method directly.
  • Keep the regression tests from fix: prevent maximum fee rate overflow #1076 (maximum_fee_rate_converts_and_displays_without_overflow and test_extract_tx_fee_overflow_maps_to_maximum_fee_rate). Update them for the new API if needed, and make sure they still pass.

Notes

  • Display stays our own code. FeeRate in bitcoin-units 1.0 has no Display impl, so there is no upstream formatter to call.
  • This is a good time to reconsider the format. The current "{}.00 sat/vbyte" always rounds the .00 looks more precise than the value is (for example, 0.1 sat/vB displays as 1.00 sat/vbyte).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions