Skip to content

Commit 27126a3

Browse files
committed
Fold anchor amounts in can_accept_incoming_htlc
1 parent 41ab89b commit 27126a3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7944,27 +7944,27 @@ impl<SP: Deref> FundedChannel<SP> where
79447944
}
79457945
}
79467946

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+
}
79597955
}
7960-
}
79617956

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+
);
79667967

7967-
if !self.funding.is_outbound() {
79687968
// `Some(())` is for the fee spike buffer we keep for the remote. This deviates from
79697969
// the spec because the fee spike buffer requirement doesn't exist on the receiver's
79707970
// 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
79767976
if !self.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
79777977
remote_fee_cost_incl_stuck_buffer_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
79787978
}
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 {
79807980
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.context.channel_id());
79817981
return Err(LocalHTLCFailureReason::FeeSpikeBuffer);
79827982
}

0 commit comments

Comments
 (0)