Skip to content

Commit 1a1e097

Browse files
committed
can_send_update_fee
1 parent 3515d0e commit 1a1e097

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 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.
@@ -4468,23 +4466,23 @@ where
44684466
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
44694467
&fee_estimator, funding.get_channel_type(),
44704468
);
4471-
let htlc_stats = self.get_pending_htlc_stats(funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
4472-
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));
4473-
let holder_balance_msat = stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
4469+
let next_local_commitment_stats = self.get_next_local_commitment_stats(funding, None, true, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
44744470
// 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).
4475-
if holder_balance_msat < stats.commit_tx_fee_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
4471+
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 {
44764472
//TODO: auto-close after a number of failures?
44774473
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
44784474
return false;
44794475
}
44804476

44814477
// Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
44824478
let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
4483-
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
4479+
if next_local_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
44844480
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
44854481
return false;
44864482
}
4487-
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
4483+
4484+
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, None, true, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
4485+
if next_remote_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
44884486
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
44894487
return false;
44904488
}
@@ -4879,8 +4877,6 @@ where
48794877
}
48804878

48814879
let mut pending_outbound_htlcs_value_msat = 0;
4882-
let mut outbound_holding_cell_msat = 0;
4883-
let mut on_holder_tx_outbound_holding_cell_htlcs_count = 0;
48844880
let mut pending_outbound_htlcs = self.pending_outbound_htlcs.len();
48854881
{
48864882
let counterparty_dust_limit_success_sat = htlc_success_tx_fee_sat + context.counterparty_dust_limit_satoshis;
@@ -4901,16 +4897,13 @@ where
49014897
if let &HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, .. } = update {
49024898
pending_outbound_htlcs += 1;
49034899
pending_outbound_htlcs_value_msat += amount_msat;
4904-
outbound_holding_cell_msat += amount_msat;
49054900
if *amount_msat / 1000 < counterparty_dust_limit_success_sat {
49064901
on_counterparty_tx_dust_exposure_msat += amount_msat;
49074902
} else {
49084903
on_counterparty_tx_accepted_nondust_htlcs += 1;
49094904
}
49104905
if *amount_msat / 1000 < holder_dust_limit_timeout_sat {
49114906
on_holder_tx_dust_exposure_msat += amount_msat;
4912-
} else {
4913-
on_holder_tx_outbound_holding_cell_htlcs_count += 1;
49144907
}
49154908
}
49164909
}
@@ -4948,8 +4941,6 @@ where
49484941
on_counterparty_tx_dust_exposure_msat,
49494942
extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat,
49504943
on_holder_tx_dust_exposure_msat,
4951-
outbound_holding_cell_msat,
4952-
on_holder_tx_outbound_holding_cell_htlcs_count,
49534944
}
49544945
}
49554946

0 commit comments

Comments
 (0)