@@ -870,14 +870,6 @@ impl<Signer: Sign> Channel<Signer> {
870
870
fn check_remote_fee < F : Deref > ( fee_estimator : & F , feerate_per_kw : u32 ) -> Result < ( ) , ChannelError >
871
871
where F :: Target : FeeEstimator
872
872
{
873
- let lower_limit = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
874
- // Some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing
875
- // occasional issues with feerate disagreements between an initiator that wants a feerate
876
- // of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. Thus, we always add 250
877
- // sat/kw before the comparison here.
878
- if feerate_per_kw + 250 < lower_limit {
879
- return Err ( ChannelError :: Close ( format ! ( "Peer's feerate much too low. Actual: {}. Our expected lower limit: {} (- 250)" , feerate_per_kw, lower_limit) ) ) ;
880
- }
881
873
// We only bound the fee updates on the upper side to prevent completely absurd feerates,
882
874
// always accepting up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
883
875
// We generally don't care too much if they set the feerate to something very high, but it
@@ -887,6 +879,14 @@ impl<Signer: Sign> Channel<Signer> {
887
879
if feerate_per_kw as u64 > upper_limit {
888
880
return Err ( ChannelError :: Close ( format ! ( "Peer's feerate much too high. Actual: {}. Our expected upper limit: {}" , feerate_per_kw, upper_limit) ) ) ;
889
881
}
882
+ let lower_limit = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
883
+ // Some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing
884
+ // occasional issues with feerate disagreements between an initiator that wants a feerate
885
+ // of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. Thus, we always add 250
886
+ // sat/kw before the comparison here.
887
+ if feerate_per_kw + 250 < lower_limit {
888
+ return Err ( ChannelError :: Close ( format ! ( "Peer's feerate much too low. Actual: {}. Our expected lower limit: {} (- 250)" , feerate_per_kw, lower_limit) ) ) ;
889
+ }
890
890
Ok ( ( ) )
891
891
}
892
892
@@ -5859,6 +5859,13 @@ mod tests {
5859
5859
"MAX_FUNDING_SATOSHIS is greater than all satoshis in existence" ) ;
5860
5860
}
5861
5861
5862
+ #[ test]
5863
+ fn test_no_fee_check_overflow ( ) {
5864
+ // Previously, calling `check_remote_fee` with a fee of 0xffffffff would overflow in
5865
+ // arithmetic, causing a panic with debug assertions enabled.
5866
+ assert ! ( Channel :: <InMemorySigner >:: check_remote_fee( &&TestFeeEstimator { fee_est: 42 } , u32 :: max_value( ) ) . is_err( ) ) ;
5867
+ }
5868
+
5862
5869
struct Keys {
5863
5870
signer : InMemorySigner ,
5864
5871
}
0 commit comments