Skip to content

Commit 8712856

Browse files
authored
Merge pull request #4470 from Bortlesboat/feat/expose-dust-exposure
Expose current dust exposure in ChannelDetails
2 parents 0c7e6e7 + 1ee9480 commit 8712856

6 files changed

Lines changed: 35 additions & 0 deletions

File tree

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
255255
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
256256
pending_inbound_htlcs: Vec::new(),
257257
pending_outbound_htlcs: Vec::new(),
258+
current_dust_exposure_msat: None,
258259
});
259260
}
260261
Some(&$first_hops_vec[..])

lightning/src/ln/channel.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ pub struct AvailableBalances {
122122
pub next_outbound_htlc_limit_msat: u64,
123123
/// The minimum value we can assign to the next outbound HTLC
124124
pub next_outbound_htlc_minimum_msat: u64,
125+
/// The current total dust exposure on this channel, in millisatoshis.
126+
///
127+
/// This is the maximum of the dust exposure on the holder and counterparty commitment
128+
/// transactions, and includes both the value of all pending HTLCs that are below the dust
129+
/// threshold as well as any excess commitment transaction fees that contribute to dust
130+
/// exposure.
131+
///
132+
/// See [`ChannelConfig::max_dust_htlc_exposure`] for more information on the dust calculation and to configure a limit.
133+
pub dust_exposure_msat: u64,
125134
}
126135

127136
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -13621,6 +13630,7 @@ where
1362113630
next_outbound_htlc_minimum_msat: acc
1362213631
.next_outbound_htlc_minimum_msat
1362313632
.max(e.next_outbound_htlc_minimum_msat),
13633+
dust_exposure_msat: acc.dust_exposure_msat.max(e.dust_exposure_msat),
1362413634
})
1362513635
})
1362613636
}

lightning/src/ln/channel_state.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,21 @@ pub struct ChannelDetails {
479479
///
480480
/// This field will be `None` for objects serialized with LDK versions prior to 0.2.0.
481481
pub funding_redeem_script: Option<bitcoin::ScriptBuf>,
482+
/// The current total dust exposure on this channel, in millisatoshis.
483+
///
484+
/// This is the maximum of the dust exposure on the holder and counterparty commitment
485+
/// transactions, and includes both the value of all pending HTLCs that are below the dust
486+
/// threshold as well as the portion of commitment transaction fees that contribute to dust
487+
/// exposure.
488+
///
489+
/// The dust exposure is compared against
490+
/// [`ChannelConfig::max_dust_htlc_exposure`] to determine whether new HTLCs can be
491+
/// accepted or offered on this channel.
492+
///
493+
/// This field will be `None` for objects serialized with LDK versions prior to 0.3.
494+
///
495+
/// [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure
496+
pub current_dust_exposure_msat: Option<u64>,
482497
}
483498

484499
impl ChannelDetails {
@@ -533,6 +548,7 @@ impl ChannelDetails {
533548
outbound_capacity_msat: 0,
534549
next_outbound_htlc_limit_msat: 0,
535550
next_outbound_htlc_minimum_msat: u64::MAX,
551+
dust_exposure_msat: 0,
536552
}
537553
});
538554
let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
@@ -596,6 +612,7 @@ impl ChannelDetails {
596612
channel_shutdown_state: Some(context.shutdown_state()),
597613
pending_inbound_htlcs: context.get_pending_inbound_htlc_details(funding),
598614
pending_outbound_htlcs: context.get_pending_outbound_htlc_details(funding),
615+
current_dust_exposure_msat: Some(balance.dust_exposure_msat),
599616
}
600617
}
601618
}
@@ -636,6 +653,7 @@ impl_writeable_tlv_based!(ChannelDetails, {
636653
(43, pending_inbound_htlcs, optional_vec),
637654
(45, pending_outbound_htlcs, optional_vec),
638655
(47, funding_redeem_script, option),
656+
(49, current_dust_exposure_msat, option),
639657
(_unused, user_channel_id, (static_value,
640658
_user_channel_id_low.unwrap_or(0) as u128 | ((_user_channel_id_high.unwrap_or(0) as u128) << 64)
641659
)),
@@ -756,6 +774,7 @@ mod tests {
756774
skimmed_fee_msat: Some(42),
757775
is_dust: false,
758776
}],
777+
current_dust_exposure_msat: Some(150_000),
759778
};
760779
let mut buffer = Vec::new();
761780
channel_details.write(&mut buffer).unwrap();

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8121,6 +8121,7 @@ impl<
81218121
outbound_capacity_msat: 0,
81228122
next_outbound_htlc_limit_msat: 0,
81238123
next_outbound_htlc_minimum_msat: u64::MAX,
8124+
dust_exposure_msat: 0,
81248125
}
81258126
});
81268127
let is_in_range = (balances.next_outbound_htlc_minimum_msat

lightning/src/routing/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,6 +4164,7 @@ mod tests {
41644164
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
41654165
pending_inbound_htlcs: Vec::new(),
41664166
pending_outbound_htlcs: Vec::new(),
4167+
current_dust_exposure_msat: None,
41674168
}
41684169
}
41694170

@@ -9665,6 +9666,7 @@ pub(crate) mod bench_utils {
96659666
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
96669667
pending_inbound_htlcs: Vec::new(),
96679668
pending_outbound_htlcs: Vec::new(),
9669+
current_dust_exposure_msat: None,
96689670
}
96699671
}
96709672

lightning/src/sign/tx_builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,15 @@ fn get_available_balances(
576576
next_outbound_htlc_minimum_msat,
577577
available_capacity_msat,
578578
);
579+
let dust_exposure_msat = cmp::max(local_dust_exposure_msat, remote_dust_exposure_msat);
579580

580581
crate::ln::channel::AvailableBalances {
581582
inbound_capacity_msat: remote_balance_before_fee_msat
582583
.saturating_sub(channel_constraints.holder_selected_channel_reserve_satoshis * 1000),
583584
outbound_capacity_msat,
584585
next_outbound_htlc_limit_msat: available_capacity_msat,
585586
next_outbound_htlc_minimum_msat,
587+
dust_exposure_msat,
586588
}
587589
}
588590

0 commit comments

Comments
 (0)