@@ -1451,7 +1451,7 @@ impl Channel {
1451
1451
return Err ( HandleError { err : "Remote side tried to send less than our minimum HTLC value" , action : None } ) ;
1452
1452
}
1453
1453
1454
- let ( inbound_htlc_count, _, htlc_outbound_value_msat , htlc_inbound_value_msat) = self . get_pending_htlc_stats ( true ) ;
1454
+ let ( inbound_htlc_count, _, _ , htlc_inbound_value_msat) = self . get_pending_htlc_stats ( true ) ;
1455
1455
if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
1456
1456
return Err ( HandleError { err : "Remote tried to push more than our max accepted HTLCs" , action : None } ) ;
1457
1457
}
@@ -1463,7 +1463,7 @@ impl Channel {
1463
1463
// Check our_channel_reserve_satoshis (we're getting paid, so they have to at least meet
1464
1464
// the reserve_satoshis we told them to always have as direct payment so that they lose
1465
1465
// something if we punish them for broadcasting an old state).
1466
- if htlc_inbound_value_msat + htlc_outbound_value_msat + msg. amount_msat + self . value_to_self_msat > ( self . channel_value_satoshis - Channel :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ) * 1000 {
1466
+ if htlc_inbound_value_msat + msg. amount_msat + self . value_to_self_msat > ( self . channel_value_satoshis - Channel :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ) * 1000 {
1467
1467
return Err ( HandleError { err : "Remote HTLC add would put them over their reserve value" , action : None } ) ;
1468
1468
}
1469
1469
if self . next_remote_htlc_id != msg. htlc_id {
@@ -2605,7 +2605,7 @@ impl Channel {
2605
2605
return Err ( HandleError { err : "Cannot send an HTLC while disconnected" , action : Some ( ErrorAction :: IgnoreError ) } ) ;
2606
2606
}
2607
2607
2608
- let ( _, outbound_htlc_count, htlc_outbound_value_msat, htlc_inbound_value_msat ) = self . get_pending_htlc_stats ( false ) ;
2608
+ let ( _, outbound_htlc_count, htlc_outbound_value_msat, _ ) = self . get_pending_htlc_stats ( false ) ;
2609
2609
if outbound_htlc_count + 1 > self . their_max_accepted_htlcs as u32 {
2610
2610
return Err ( HandleError { err : "Cannot push more than their max accepted HTLCs" , action : None } ) ;
2611
2611
}
@@ -2614,8 +2614,19 @@ impl Channel {
2614
2614
if htlc_outbound_value_msat + amount_msat > self . their_max_htlc_value_in_flight_msat {
2615
2615
return Err ( HandleError { err : "Cannot send value that would put us over our max HTLC value in flight" , action : None } ) ;
2616
2616
}
2617
- // Check their_channel_reserve_satoshis:
2618
- if htlc_inbound_value_msat + htlc_outbound_value_msat + amount_msat + ( self . channel_value_satoshis * 1000 - self . value_to_self_msat ) > ( self . channel_value_satoshis - self . their_channel_reserve_satoshis ) * 1000 {
2617
+
2618
+ let mut holding_cell_outbound_amount_msat = 0 ;
2619
+ for holding_htlc in self . holding_cell_htlc_updates . iter ( ) {
2620
+ match holding_htlc {
2621
+ & HTLCUpdateAwaitingACK :: AddHTLC { ref amount_msat, .. } => {
2622
+ holding_cell_outbound_amount_msat += * amount_msat;
2623
+ }
2624
+ _ => { }
2625
+ }
2626
+ }
2627
+
2628
+ // Check self.their_channel_reserve_satoshis (i.e our channel reserve):
2629
+ if self . value_to_self_msat < self . their_channel_reserve_satoshis * 1000 + amount_msat + holding_cell_outbound_amount_msat + htlc_outbound_value_msat {
2619
2630
return Err ( HandleError { err : "Cannot send value that would put us over our reserve value" , action : None } ) ;
2620
2631
}
2621
2632
0 commit comments