Skip to content

Commit 2937000

Browse files
committed
Unify get_{inbound,outbound}_pending_htlc_stats
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.
1 parent 8701b1b commit 2937000

File tree

1 file changed

+76
-89
lines changed

1 file changed

+76
-89
lines changed

lightning/src/ln/channel.rs

Lines changed: 76 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -998,14 +998,16 @@ enum HTLCInitiator {
998998
RemoteOffered,
999999
}
10001000

1001-
/// An enum gathering stats on pending HTLCs, either inbound or outbound side.
1001+
/// Current counts of various HTLCs, useful for calculating current balances available exactly.
10021002
struct HTLCStats {
1003-
pending_htlcs: u32,
1004-
pending_htlcs_value_msat: u64,
1003+
pending_inbound_htlcs: usize,
1004+
pending_outbound_htlcs: usize,
1005+
pending_inbound_htlcs_value_msat: u64,
1006+
pending_outbound_htlcs_value_msat: u64,
10051007
on_counterparty_tx_dust_exposure_msat: u64,
10061008
on_holder_tx_dust_exposure_msat: u64,
1007-
holding_cell_msat: u64,
1008-
on_holder_tx_holding_cell_htlcs_count: u32, // dust HTLCs *non*-included
1009+
outbound_holding_cell_msat: u64,
1010+
on_holder_tx_outbound_holding_cell_htlcs_count: u32, // dust HTLCs *non*-included
10091011
}
10101012

10111013
/// An enum gathering stats on commitment transaction, either local or remote.
@@ -2738,86 +2740,81 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27382740
self.counterparty_forwarding_info.clone()
27392741
}
27402742

2741-
/// Returns a HTLCStats about inbound pending htlcs
2742-
fn get_inbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
2743+
/// Returns a HTLCStats about pending htlcs
2744+
fn get_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
27432745
let context = self;
2744-
let mut stats = HTLCStats {
2745-
pending_htlcs: context.pending_inbound_htlcs.len() as u32,
2746-
pending_htlcs_value_msat: 0,
2747-
on_counterparty_tx_dust_exposure_msat: 0,
2748-
on_holder_tx_dust_exposure_msat: 0,
2749-
holding_cell_msat: 0,
2750-
on_holder_tx_holding_cell_htlcs_count: 0,
2751-
};
2746+
let uses_0_htlc_fee_anchors = self.get_channel_type().supports_anchors_zero_fee_htlc_tx();
27522747

2753-
let (htlc_timeout_dust_limit, htlc_success_dust_limit) = if context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
2748+
let (htlc_timeout_dust_limit, htlc_success_dust_limit) = if uses_0_htlc_fee_anchors {
27542749
(0, 0)
27552750
} else {
27562751
let dust_buffer_feerate = context.get_dust_buffer_feerate(outbound_feerate_update) as u64;
27572752
(dust_buffer_feerate * htlc_timeout_tx_weight(context.get_channel_type()) / 1000,
27582753
dust_buffer_feerate * htlc_success_tx_weight(context.get_channel_type()) / 1000)
27592754
};
2755+
2756+
let mut on_holder_tx_dust_exposure_msat = 0;
2757+
let mut on_counterparty_tx_dust_exposure_msat = 0;
2758+
2759+
let mut pending_inbound_htlcs_value_msat = 0;
2760+
{
27602761
let counterparty_dust_limit_timeout_sat = htlc_timeout_dust_limit + context.counterparty_dust_limit_satoshis;
27612762
let holder_dust_limit_success_sat = htlc_success_dust_limit + context.holder_dust_limit_satoshis;
27622763
for ref htlc in context.pending_inbound_htlcs.iter() {
2763-
stats.pending_htlcs_value_msat += htlc.amount_msat;
2764+
pending_inbound_htlcs_value_msat += htlc.amount_msat;
27642765
if htlc.amount_msat / 1000 < counterparty_dust_limit_timeout_sat {
2765-
stats.on_counterparty_tx_dust_exposure_msat += htlc.amount_msat;
2766+
on_counterparty_tx_dust_exposure_msat += htlc.amount_msat;
27662767
}
27672768
if htlc.amount_msat / 1000 < holder_dust_limit_success_sat {
2768-
stats.on_holder_tx_dust_exposure_msat += htlc.amount_msat;
2769+
on_holder_tx_dust_exposure_msat += htlc.amount_msat;
27692770
}
27702771
}
2771-
stats
2772-
}
2773-
2774-
/// Returns a HTLCStats about pending outbound htlcs, *including* pending adds in our holding cell.
2775-
fn get_outbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
2776-
let context = self;
2777-
let mut stats = HTLCStats {
2778-
pending_htlcs: context.pending_outbound_htlcs.len() as u32,
2779-
pending_htlcs_value_msat: 0,
2780-
on_counterparty_tx_dust_exposure_msat: 0,
2781-
on_holder_tx_dust_exposure_msat: 0,
2782-
holding_cell_msat: 0,
2783-
on_holder_tx_holding_cell_htlcs_count: 0,
2784-
};
2772+
}
27852773

2786-
let (htlc_timeout_dust_limit, htlc_success_dust_limit) = if context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
2787-
(0, 0)
2788-
} else {
2789-
let dust_buffer_feerate = context.get_dust_buffer_feerate(outbound_feerate_update) as u64;
2790-
(dust_buffer_feerate * htlc_timeout_tx_weight(context.get_channel_type()) / 1000,
2791-
dust_buffer_feerate * htlc_success_tx_weight(context.get_channel_type()) / 1000)
2792-
};
2774+
let mut pending_outbound_htlcs_value_msat = 0;
2775+
let mut outbound_holding_cell_msat = 0;
2776+
let mut on_holder_tx_outbound_holding_cell_htlcs_count = 0;
2777+
let mut pending_outbound_htlcs = self.pending_outbound_htlcs.len();
2778+
{
27932779
let counterparty_dust_limit_success_sat = htlc_success_dust_limit + context.counterparty_dust_limit_satoshis;
27942780
let holder_dust_limit_timeout_sat = htlc_timeout_dust_limit + context.holder_dust_limit_satoshis;
27952781
for ref htlc in context.pending_outbound_htlcs.iter() {
2796-
stats.pending_htlcs_value_msat += htlc.amount_msat;
2782+
pending_outbound_htlcs_value_msat += htlc.amount_msat;
27972783
if htlc.amount_msat / 1000 < counterparty_dust_limit_success_sat {
2798-
stats.on_counterparty_tx_dust_exposure_msat += htlc.amount_msat;
2784+
on_counterparty_tx_dust_exposure_msat += htlc.amount_msat;
27992785
}
28002786
if htlc.amount_msat / 1000 < holder_dust_limit_timeout_sat {
2801-
stats.on_holder_tx_dust_exposure_msat += htlc.amount_msat;
2787+
on_holder_tx_dust_exposure_msat += htlc.amount_msat;
28022788
}
28032789
}
28042790

28052791
for update in context.holding_cell_htlc_updates.iter() {
28062792
if let &HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, .. } = update {
2807-
stats.pending_htlcs += 1;
2808-
stats.pending_htlcs_value_msat += amount_msat;
2809-
stats.holding_cell_msat += amount_msat;
2793+
pending_outbound_htlcs += 1;
2794+
pending_outbound_htlcs_value_msat += amount_msat;
2795+
outbound_holding_cell_msat += amount_msat;
28102796
if *amount_msat / 1000 < counterparty_dust_limit_success_sat {
2811-
stats.on_counterparty_tx_dust_exposure_msat += amount_msat;
2797+
on_counterparty_tx_dust_exposure_msat += amount_msat;
28122798
}
28132799
if *amount_msat / 1000 < holder_dust_limit_timeout_sat {
2814-
stats.on_holder_tx_dust_exposure_msat += amount_msat;
2800+
on_holder_tx_dust_exposure_msat += amount_msat;
28152801
} else {
2816-
stats.on_holder_tx_holding_cell_htlcs_count += 1;
2802+
on_holder_tx_outbound_holding_cell_htlcs_count += 1;
28172803
}
28182804
}
28192805
}
2820-
stats
2806+
}
2807+
2808+
HTLCStats {
2809+
pending_inbound_htlcs: self.pending_inbound_htlcs.len(),
2810+
pending_outbound_htlcs,
2811+
pending_inbound_htlcs_value_msat,
2812+
pending_outbound_htlcs_value_msat,
2813+
on_counterparty_tx_dust_exposure_msat,
2814+
on_holder_tx_dust_exposure_msat,
2815+
outbound_holding_cell_msat,
2816+
on_holder_tx_outbound_holding_cell_htlcs_count,
2817+
}
28212818
}
28222819

28232820
/// Returns information on all pending inbound HTLCs.
@@ -2923,19 +2920,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29232920
{
29242921
let context = &self;
29252922
// Note that we have to handle overflow due to the above case.
2926-
let inbound_stats = context.get_inbound_pending_htlc_stats(None);
2927-
let outbound_stats = context.get_outbound_pending_htlc_stats(None);
2923+
let htlc_stats = context.get_pending_htlc_stats(None);
29282924

29292925
let mut balance_msat = context.value_to_self_msat;
29302926
for ref htlc in context.pending_inbound_htlcs.iter() {
29312927
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state {
29322928
balance_msat += htlc.amount_msat;
29332929
}
29342930
}
2935-
balance_msat -= outbound_stats.pending_htlcs_value_msat;
2931+
balance_msat -= htlc_stats.pending_outbound_htlcs_value_msat;
29362932

29372933
let outbound_capacity_msat = context.value_to_self_msat
2938-
.saturating_sub(outbound_stats.pending_htlcs_value_msat)
2934+
.saturating_sub(htlc_stats.pending_outbound_htlcs_value_msat)
29392935
.saturating_sub(
29402936
context.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000);
29412937

@@ -2995,7 +2991,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29952991

29962992
let holder_selected_chan_reserve_msat = context.holder_selected_channel_reserve_satoshis * 1000;
29972993
let remote_balance_msat = (context.channel_value_satoshis * 1000 - context.value_to_self_msat)
2998-
.saturating_sub(inbound_stats.pending_htlcs_value_msat);
2994+
.saturating_sub(htlc_stats.pending_inbound_htlcs_value_msat);
29992995

30002996
if remote_balance_msat < max_reserved_commit_tx_fee_msat + holder_selected_chan_reserve_msat + anchor_outputs_value_msat {
30012997
// If another HTLC's fee would reduce the remote's balance below the reserve limit
@@ -3021,18 +3017,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30213017
(context.counterparty_dust_limit_satoshis + dust_buffer_feerate * htlc_success_tx_weight(context.get_channel_type()) / 1000,
30223018
context.holder_dust_limit_satoshis + dust_buffer_feerate * htlc_timeout_tx_weight(context.get_channel_type()) / 1000)
30233019
};
3024-
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()) {
30263021
remaining_msat_below_dust_exposure_limit =
3027-
Some(max_dust_htlc_exposure_msat.saturating_sub(on_counterparty_dust_htlc_exposure_msat));
3022+
Some(max_dust_htlc_exposure_msat.saturating_sub(htlc_stats.on_counterparty_tx_dust_exposure_msat));
30283023
dust_exposure_dust_limit_msat = cmp::max(dust_exposure_dust_limit_msat, htlc_success_dust_limit * 1000);
30293024
}
30303025

3031-
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()) {
30333027
remaining_msat_below_dust_exposure_limit = Some(cmp::min(
30343028
remaining_msat_below_dust_exposure_limit.unwrap_or(u64::max_value()),
3035-
max_dust_htlc_exposure_msat.saturating_sub(on_holder_dust_htlc_exposure_msat)));
3029+
max_dust_htlc_exposure_msat.saturating_sub(htlc_stats.on_holder_tx_dust_exposure_msat)));
30363030
dust_exposure_dust_limit_msat = cmp::max(dust_exposure_dust_limit_msat, htlc_timeout_dust_limit * 1000);
30373031
}
30383032

@@ -3045,16 +3039,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30453039
}
30463040

30473041
available_capacity_msat = cmp::min(available_capacity_msat,
3048-
context.counterparty_max_htlc_value_in_flight_msat - outbound_stats.pending_htlcs_value_msat);
3042+
context.counterparty_max_htlc_value_in_flight_msat - htlc_stats.pending_outbound_htlcs_value_msat);
30493043

3050-
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 {
30513045
available_capacity_msat = 0;
30523046
}
30533047

30543048
AvailableBalances {
30553049
inbound_capacity_msat: cmp::max(context.channel_value_satoshis as i64 * 1000
30563050
- 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
30583052
- context.holder_selected_channel_reserve_satoshis as i64 * 1000,
30593053
0) as u64,
30603054
outbound_capacity_msat,
@@ -4143,11 +4137,11 @@ impl<SP: Deref> Channel<SP> where
41434137
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)));
41444138
}
41454139

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 {
41484142
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.context.holder_max_accepted_htlcs)));
41494143
}
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 {
41514145
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)));
41524146
}
41534147

@@ -4173,7 +4167,7 @@ impl<SP: Deref> Channel<SP> where
41734167
}
41744168

41754169
let pending_value_to_self_msat =
4176-
self.context.value_to_self_msat + inbound_stats.pending_htlcs_value_msat - removed_outbound_total_msat;
4170+
self.context.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
41774171
let pending_remote_value_msat =
41784172
self.context.channel_value_satoshis * 1000 - pending_value_to_self_msat;
41794173
if pending_remote_value_msat < msg.amount_msat {
@@ -4995,27 +4989,24 @@ impl<SP: Deref> Channel<SP> where
49954989
}
49964990

49974991
// 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));
50004993
let keys = self.context.build_holder_transaction_keys(self.context.cur_holder_commitment_transaction_number);
50014994
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;
50044997
if holder_balance_msat < buffer_fee_msat + self.context.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
50054998
//TODO: auto-close after a number of failures?
50064999
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
50075000
return None;
50085001
}
50095002

50105003
// 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;
50135004
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 {
50155006
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
50165007
return None;
50175008
}
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 {
50195010
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
50205011
return None;
50215012
}
@@ -5249,18 +5240,15 @@ impl<SP: Deref> Channel<SP> where
52495240
self.context.update_time_counter += 1;
52505241
// Check that we won't be pushed over our dust exposure limit by the feerate increase.
52515242
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);
52565244
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 {
52585246
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)",
5259-
msg.feerate_per_kw, holder_tx_dust_exposure)));
5247+
msg.feerate_per_kw, htlc_stats.on_holder_tx_dust_exposure_msat)));
52605248
}
5261-
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 {
52625250
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)",
5263-
msg.feerate_per_kw, counterparty_tx_dust_exposure)));
5251+
msg.feerate_per_kw, htlc_stats.on_counterparty_tx_dust_exposure_msat)));
52645252
}
52655253
}
52665254
Ok(())
@@ -6105,8 +6093,7 @@ impl<SP: Deref> Channel<SP> where
61056093
return Err(("Shutdown was already sent", 0x4000|8))
61066094
}
61076095

6108-
let inbound_stats = self.context.get_inbound_pending_htlc_stats(None);
6109-
let outbound_stats = self.context.get_outbound_pending_htlc_stats(None);
6096+
let htlc_stats = self.context.get_pending_htlc_stats(None);
61106097
let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(fee_estimator);
61116098
let (htlc_timeout_dust_limit, htlc_success_dust_limit) = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
61126099
(0, 0)
@@ -6117,7 +6104,7 @@ impl<SP: Deref> Channel<SP> where
61176104
};
61186105
let exposure_dust_limit_timeout_sats = htlc_timeout_dust_limit + self.context.counterparty_dust_limit_satoshis;
61196106
if msg.amount_msat / 1000 < exposure_dust_limit_timeout_sats {
6120-
let on_counterparty_tx_dust_htlc_exposure_msat = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat + msg.amount_msat;
6107+
let on_counterparty_tx_dust_htlc_exposure_msat = htlc_stats.on_counterparty_tx_dust_exposure_msat + msg.amount_msat;
61216108
if on_counterparty_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
61226109
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx",
61236110
on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
@@ -6127,7 +6114,7 @@ impl<SP: Deref> Channel<SP> where
61276114

61286115
let exposure_dust_limit_success_sats = htlc_success_dust_limit + self.context.holder_dust_limit_satoshis;
61296116
if msg.amount_msat / 1000 < exposure_dust_limit_success_sats {
6130-
let on_holder_tx_dust_htlc_exposure_msat = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat + msg.amount_msat;
6117+
let on_holder_tx_dust_htlc_exposure_msat = htlc_stats.on_holder_tx_dust_exposure_msat + msg.amount_msat;
61316118
if on_holder_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
61326119
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
61336120
on_holder_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
@@ -6151,7 +6138,7 @@ impl<SP: Deref> Channel<SP> where
61516138
}
61526139

61536140
let pending_value_to_self_msat =
6154-
self.context.value_to_self_msat + inbound_stats.pending_htlcs_value_msat - removed_outbound_total_msat;
6141+
self.context.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
61556142
let pending_remote_value_msat =
61566143
self.context.channel_value_satoshis * 1000 - pending_value_to_self_msat;
61576144

0 commit comments

Comments
 (0)