Skip to content

Commit c759b47

Browse files
committed
can_send_update_fee
1 parent ef2a9f7 commit c759b47

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,6 @@ struct HTLCStats {
11121112
// htlc on the counterparty's commitment transaction.
11131113
extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat: Option<u64>,
11141114
on_holder_tx_dust_exposure_msat: u64,
1115-
outbound_holding_cell_msat: u64,
1116-
on_holder_tx_outbound_holding_cell_htlcs_count: u32, // dust HTLCs *non*-included
11171115
}
11181116

11191117
/// A struct gathering data on a commitment, either local or remote.
@@ -4463,23 +4461,25 @@ where
44634461
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
44644462
&fee_estimator, funding.get_channel_type(),
44654463
);
4466-
let htlc_stats = self.get_pending_htlc_stats(funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
4467-
let stats = self.build_commitment_stats(funding, true, true, Some(feerate_per_kw), Some(htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize));
4468-
let holder_balance_msat = stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
4464+
// Include outbound update_add_htlc's in the holding cell, and those which haven't yet been ACK'ed by the counterparty (ie. LocalAnnounced HTLCs)
4465+
let include_counterparty_unknown_htlcs = true;
4466+
let next_local_commitment_stats = self.get_next_local_commitment_stats(funding, None, include_counterparty_unknown_htlcs, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
44694467
// Note that `stats.commit_tx_fee_sat` accounts for any HTLCs that transition from non-dust to dust under a higher feerate (in the case where HTLC-transactions pay endogenous fees).
4470-
if holder_balance_msat < stats.commit_tx_fee_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
4468+
if next_local_commitment_stats.holder_balance_msat.unwrap() < next_local_commitment_stats.commit_tx_fee_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
44714469
//TODO: auto-close after a number of failures?
44724470
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
44734471
return false;
44744472
}
44754473

44764474
// Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
44774475
let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
4478-
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
4476+
if next_local_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
44794477
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
44804478
return false;
44814479
}
4482-
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
4480+
4481+
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, None, include_counterparty_unknown_htlcs, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
4482+
if next_remote_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
44834483
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
44844484
return false;
44854485
}
@@ -4874,8 +4874,6 @@ where
48744874
}
48754875

48764876
let mut pending_outbound_htlcs_value_msat = 0;
4877-
let mut outbound_holding_cell_msat = 0;
4878-
let mut on_holder_tx_outbound_holding_cell_htlcs_count = 0;
48794877
let mut pending_outbound_htlcs = self.pending_outbound_htlcs.len();
48804878
{
48814879
let counterparty_dust_limit_success_sat = htlc_success_tx_fee_sat + context.counterparty_dust_limit_satoshis;
@@ -4896,16 +4894,13 @@ where
48964894
if let &HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, .. } = update {
48974895
pending_outbound_htlcs += 1;
48984896
pending_outbound_htlcs_value_msat += amount_msat;
4899-
outbound_holding_cell_msat += amount_msat;
49004897
if *amount_msat / 1000 < counterparty_dust_limit_success_sat {
49014898
on_counterparty_tx_dust_exposure_msat += amount_msat;
49024899
} else {
49034900
on_counterparty_tx_accepted_nondust_htlcs += 1;
49044901
}
49054902
if *amount_msat / 1000 < holder_dust_limit_timeout_sat {
49064903
on_holder_tx_dust_exposure_msat += amount_msat;
4907-
} else {
4908-
on_holder_tx_outbound_holding_cell_htlcs_count += 1;
49094904
}
49104905
}
49114906
}
@@ -4943,8 +4938,6 @@ where
49434938
on_counterparty_tx_dust_exposure_msat,
49444939
extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat,
49454940
on_holder_tx_dust_exposure_msat,
4946-
outbound_holding_cell_msat,
4947-
on_holder_tx_outbound_holding_cell_htlcs_count,
49484941
}
49494942
}
49504943

0 commit comments

Comments
 (0)