You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In most cases we already call both in a pair, and in fact always
consolidate some of the returned values across both accessors, so
there's not much reason to have them be separate methods.
Here we merge them.
let on_counterparty_dust_htlc_exposure_msat = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat;
3025
-
if on_counterparty_dust_htlc_exposure_msat as i64 + htlc_success_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) {
3020
+
if htlc_stats.on_counterparty_tx_dust_exposure_msat as i64 + htlc_success_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) {
let on_holder_dust_htlc_exposure_msat = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat;
3032
-
if on_holder_dust_htlc_exposure_msat as i64 + htlc_timeout_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) {
3026
+
if htlc_stats.on_holder_tx_dust_exposure_msat as i64 + htlc_timeout_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) {
if outbound_stats.pending_htlcs + 1 > context.counterparty_max_accepted_htlcs as u32 {
3044
+
if htlc_stats.pending_outbound_htlcs + 1 > context.counterparty_max_accepted_htlcs as usize {
3051
3045
available_capacity_msat = 0;
3052
3046
}
3053
3047
3054
3048
AvailableBalances {
3055
3049
inbound_capacity_msat: cmp::max(context.channel_value_satoshis as i64 * 1000
3056
3050
- context.value_to_self_msat as i64
3057
-
- context.get_inbound_pending_htlc_stats(None).pending_htlcs_value_msat as i64
3051
+
- htlc_stats.pending_inbound_htlcs_value_msat as i64
3058
3052
- context.holder_selected_channel_reserve_satoshis as i64 * 1000,
3059
3053
0) as u64,
3060
3054
outbound_capacity_msat,
@@ -4143,11 +4137,11 @@ impl<SP: Deref> Channel<SP> where
4143
4137
return Err(ChannelError::Close(format!("Remote side tried to send less than our minimum HTLC value. Lower limit: ({}). Actual: ({})", self.context.holder_htlc_minimum_msat, msg.amount_msat)));
4144
4138
}
4145
4139
4146
-
let inbound_stats = self.context.get_inbound_pending_htlc_stats(None);
4147
-
if inbound_stats.pending_htlcs + 1 > self.context.holder_max_accepted_htlcs as u32 {
4140
+
let htlc_stats = self.context.get_pending_htlc_stats(None);
4141
+
if htlc_stats.pending_inbound_htlcs + 1 > self.context.holder_max_accepted_htlcs as usize {
4148
4142
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.context.holder_max_accepted_htlcs)));
4149
4143
}
4150
-
if inbound_stats.pending_htlcs_value_msat + msg.amount_msat > self.context.holder_max_htlc_value_in_flight_msat {
4144
+
if htlc_stats.pending_inbound_htlcs_value_msat + msg.amount_msat > self.context.holder_max_htlc_value_in_flight_msat {
4151
4145
return Err(ChannelError::Close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.context.holder_max_htlc_value_in_flight_msat)));
4152
4146
}
4153
4147
@@ -4173,7 +4167,7 @@ impl<SP: Deref> Channel<SP> where
@@ -4995,27 +4989,24 @@ impl<SP: Deref> Channel<SP> where
4995
4989
}
4996
4990
4997
4991
// Before proposing a feerate update, check that we can actually afford the new fee.
4998
-
let inbound_stats = self.context.get_inbound_pending_htlc_stats(Some(feerate_per_kw));
4999
-
let outbound_stats = self.context.get_outbound_pending_htlc_stats(Some(feerate_per_kw));
4992
+
let htlc_stats = self.context.get_pending_htlc_stats(Some(feerate_per_kw));
5000
4993
let keys = self.context.build_holder_transaction_keys(self.context.cur_holder_commitment_transaction_number);
5001
4994
let commitment_stats = self.context.build_commitment_transaction(self.context.cur_holder_commitment_transaction_number, &keys, true, true, logger);
5002
-
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_stats.num_nondust_htlcs + outbound_stats.on_holder_tx_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.context.get_channel_type()) * 1000;
5003
-
let holder_balance_msat = commitment_stats.local_balance_msat - outbound_stats.holding_cell_msat;
4995
+
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_stats.num_nondust_htlcs + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.context.get_channel_type()) * 1000;
4996
+
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
5004
4997
if holder_balance_msat < buffer_fee_msat + self.context.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
5005
4998
//TODO: auto-close after a number of failures?
5006
4999
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
5007
5000
return None;
5008
5001
}
5009
5002
5010
5003
// Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
5011
-
let holder_tx_dust_exposure = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat;
5012
-
let counterparty_tx_dust_exposure = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat;
5013
5004
let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(fee_estimator);
5014
-
if holder_tx_dust_exposure > max_dust_htlc_exposure_msat {
5005
+
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
5015
5006
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
5016
5007
return None;
5017
5008
}
5018
-
if counterparty_tx_dust_exposure > max_dust_htlc_exposure_msat {
5009
+
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
5019
5010
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
5020
5011
return None;
5021
5012
}
@@ -5249,18 +5240,15 @@ impl<SP: Deref> Channel<SP> where
5249
5240
self.context.update_time_counter += 1;
5250
5241
// Check that we won't be pushed over our dust exposure limit by the feerate increase.
5251
5242
if !self.context.channel_type.supports_anchors_zero_fee_htlc_tx() {
5252
-
let inbound_stats = self.context.get_inbound_pending_htlc_stats(None);
5253
-
let outbound_stats = self.context.get_outbound_pending_htlc_stats(None);
5254
-
let holder_tx_dust_exposure = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat;
5255
-
let counterparty_tx_dust_exposure = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat;
5243
+
let htlc_stats = self.context.get_pending_htlc_stats(None);
5256
5244
let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(fee_estimator);
5257
-
if holder_tx_dust_exposure > max_dust_htlc_exposure_msat {
5245
+
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
5258
5246
return Err(ChannelError::Close(format!("Peer sent update_fee with a feerate ({}) which may over-expose us to dust-in-flight on our own transactions (totaling {} msat)",
if counterparty_tx_dust_exposure > max_dust_htlc_exposure_msat {
5249
+
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
5262
5250
return Err(ChannelError::Close(format!("Peer sent update_fee with a feerate ({}) which may over-expose us to dust-in-flight on our counterparty's transactions (totaling {} msat)",
0 commit comments