#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
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).
#1076 fixes an overflow in
FeeRatefor fee rates nearu64::MAXsat/kwu. The overflow is in rust-bitcoin'sbitcoin-units0.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_ceildoes its own rounding withself.0.to_sat_per_kwu().div_ceil(250)impl Display for FeeRateno longer calls upstream's{:#}formatter. It builds the same"{}.00 sat/vbyte"string itself.Upstream status
This is fixed on rust-bitcoin
master. Inbitcoin-units1.0 (currently1.0.0-rc.4, used by thebitcoin0.33 betas),to_sat_per_vb_ceilis implemented withdiv_ceiland does not overflow.Todo when we move to
bitcoin 0.33.0FeeRate::to_sat_per_vb_ceilback to callingself.0.to_sat_per_vb_ceil().ExtractTxError::AbsurdFeeRatestill needs to convert throughcrate::bitcoin::FeeRatebefore callingto_sat_per_vb_ceil, or can call the upstream method directly.maximum_fee_rate_converts_and_displays_without_overflowandtest_extract_tx_fee_overflow_maps_to_maximum_fee_rate). Update them for the new API if needed, and make sure they still pass.Notes
Displaystays our own code.FeeRateinbitcoin-units1.0 has noDisplayimpl, so there is no upstream formatter to call."{}.00 sat/vbyte"always rounds the.00looks more precise than the value is (for example, 0.1 sat/vB displays as1.00 sat/vbyte).