@@ -1451,7 +1451,7 @@ impl Channel {
14511451 return Err ( HandleError { err : "Remote side tried to send less than our minimum HTLC value" , action : None } ) ;
14521452 }
14531453
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 ) ;
14551455 if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
14561456 return Err ( HandleError { err : "Remote tried to push more than our max accepted HTLCs" , action : None } ) ;
14571457 }
@@ -1463,7 +1463,7 @@ impl Channel {
14631463 // Check our_channel_reserve_satoshis (we're getting paid, so they have to at least meet
14641464 // the reserve_satoshis we told them to always have as direct payment so that they lose
14651465 // 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 {
14671467 return Err ( HandleError { err : "Remote HTLC add would put them over their reserve value" , action : None } ) ;
14681468 }
14691469 if self . next_remote_htlc_id != msg. htlc_id {
@@ -2605,7 +2605,7 @@ impl Channel {
26052605 return Err ( HandleError { err : "Cannot send an HTLC while disconnected" , action : Some ( ErrorAction :: IgnoreError ) } ) ;
26062606 }
26072607
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 ) ;
26092609 if outbound_htlc_count + 1 > self . their_max_accepted_htlcs as u32 {
26102610 return Err ( HandleError { err : "Cannot push more than their max accepted HTLCs" , action : None } ) ;
26112611 }
@@ -2614,8 +2614,19 @@ impl Channel {
26142614 if htlc_outbound_value_msat + amount_msat > self . their_max_htlc_value_in_flight_msat {
26152615 return Err ( HandleError { err : "Cannot send value that would put us over our max HTLC value in flight" , action : None } ) ;
26162616 }
2617+
2618+ let mut holding_cell_outbound_amount_msat = 0 ;
2619+ for ref 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+
26172628 // 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 {
2629+ if self . value_to_self_msat < self . their_channel_reserve_satoshis * 1000 + amount_msat + holding_cell_outbound_amount_msat + htlc_outbound_value_msat {
26192630 return Err ( HandleError { err : "Cannot send value that would put us over our reserve value" , action : None } ) ;
26202631 }
26212632
0 commit comments