@@ -7944,27 +7944,27 @@ impl<SP: Deref> FundedChannel<SP> where
7944
7944
}
7945
7945
}
7946
7946
7947
- let anchor_outputs_value_msat = if self.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7948
- ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
7949
- } else {
7950
- 0
7951
- };
7952
-
7953
- let mut removed_outbound_total_msat = 0;
7954
- for ref htlc in self.context.pending_outbound_htlcs.iter() {
7955
- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
7956
- removed_outbound_total_msat += htlc.amount_msat;
7957
- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
7958
- removed_outbound_total_msat += htlc.amount_msat;
7947
+ if !self.funding.is_outbound() {
7948
+ let mut removed_outbound_total_msat = 0;
7949
+ for ref htlc in self.context.pending_outbound_htlcs.iter() {
7950
+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
7951
+ removed_outbound_total_msat += htlc.amount_msat;
7952
+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
7953
+ removed_outbound_total_msat += htlc.amount_msat;
7954
+ }
7959
7955
}
7960
- }
7961
7956
7962
- let pending_value_to_self_msat =
7963
- self.funding.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
7964
- let pending_remote_value_msat =
7965
- self.funding.get_value_satoshis() * 1000 - pending_value_to_self_msat;
7957
+ let pending_value_to_self_msat =
7958
+ self.funding.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
7959
+ let pending_remote_value_msat =
7960
+ self.funding.get_value_satoshis() * 1000 - pending_value_to_self_msat;
7961
+ let (_local_balance_before_fee_msat, remote_balance_before_fee_msat) = SpecTxBuilder {}.balances_excluding_tx_fee(
7962
+ self.funding.is_outbound(), // ie. false
7963
+ self.funding.get_channel_type(),
7964
+ pending_value_to_self_msat,
7965
+ pending_remote_value_msat,
7966
+ );
7966
7967
7967
- if !self.funding.is_outbound() {
7968
7968
// `Some(())` is for the fee spike buffer we keep for the remote. This deviates from
7969
7969
// the spec because the fee spike buffer requirement doesn't exist on the receiver's
7970
7970
// side, only on the sender's. Note that with anchor outputs we are no longer as
@@ -7976,7 +7976,7 @@ impl<SP: Deref> FundedChannel<SP> where
7976
7976
if !self.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7977
7977
remote_fee_cost_incl_stuck_buffer_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
7978
7978
}
7979
- if pending_remote_value_msat .saturating_sub(self.funding.holder_selected_channel_reserve_satoshis * 1000).saturating_sub(anchor_outputs_value_msat ) < remote_fee_cost_incl_stuck_buffer_msat {
7979
+ if remote_balance_before_fee_msat .saturating_sub(self.funding.holder_selected_channel_reserve_satoshis * 1000) < remote_fee_cost_incl_stuck_buffer_msat {
7980
7980
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.context.channel_id());
7981
7981
return Err(LocalHTLCFailureReason::FeeSpikeBuffer);
7982
7982
}
0 commit comments