@@ -942,14 +942,6 @@ impl<Signer: Sign> Channel<Signer> {
942
942
fn check_remote_fee < F : Deref > ( fee_estimator : & F , feerate_per_kw : u32 ) -> Result < ( ) , ChannelError >
943
943
where F :: Target : FeeEstimator
944
944
{
945
- let lower_limit = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
946
- // Some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing
947
- // occasional issues with feerate disagreements between an initiator that wants a feerate
948
- // of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. Thus, we always add 250
949
- // sat/kw before the comparison here.
950
- if feerate_per_kw + 250 < lower_limit {
951
- return Err ( ChannelError :: Close ( format ! ( "Peer's feerate much too low. Actual: {}. Our expected lower limit: {} (- 250)" , feerate_per_kw, lower_limit) ) ) ;
952
- }
953
945
// We only bound the fee updates on the upper side to prevent completely absurd feerates,
954
946
// always accepting up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
955
947
// We generally don't care too much if they set the feerate to something very high, but it
@@ -959,6 +951,14 @@ impl<Signer: Sign> Channel<Signer> {
959
951
if feerate_per_kw as u64 > upper_limit {
960
952
return Err ( ChannelError :: Close ( format ! ( "Peer's feerate much too high. Actual: {}. Our expected upper limit: {}" , feerate_per_kw, upper_limit) ) ) ;
961
953
}
954
+ let lower_limit = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
955
+ // Some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing
956
+ // occasional issues with feerate disagreements between an initiator that wants a feerate
957
+ // of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. Thus, we always add 250
958
+ // sat/kw before the comparison here.
959
+ if feerate_per_kw + 250 < lower_limit {
960
+ return Err ( ChannelError :: Close ( format ! ( "Peer's feerate much too low. Actual: {}. Our expected lower limit: {} (- 250)" , feerate_per_kw, lower_limit) ) ) ;
961
+ }
962
962
Ok ( ( ) )
963
963
}
964
964
@@ -6154,6 +6154,13 @@ mod tests {
6154
6154
"MAX_FUNDING_SATOSHIS is greater than all satoshis in existence" ) ;
6155
6155
}
6156
6156
6157
+ #[ test]
6158
+ fn test_no_fee_check_overflow ( ) {
6159
+ // Previously, calling `check_remote_fee` with a fee of 0xffffffff would overflow in
6160
+ // arithmetic, causing a panic with debug assertions enabled.
6161
+ assert ! ( Channel :: <InMemorySigner >:: check_remote_fee( &&TestFeeEstimator { fee_est: 42 } , u32 :: max_value( ) ) . is_err( ) ) ;
6162
+ }
6163
+
6157
6164
struct Keys {
6158
6165
signer : InMemorySigner ,
6159
6166
}
0 commit comments