Skip to content

Commit cb34df1

Browse files
Bortlesboatcodex
andcommitted
Expose current dust exposure in ChannelDetails
Co-authored-by: Codex <codex@openai.com>
1 parent 9f73a98 commit cb34df1

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

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)]
@@ -13603,6 +13612,7 @@ where
1360313612
next_outbound_htlc_minimum_msat: acc
1360413613
.next_outbound_htlc_minimum_msat
1360513614
.max(e.next_outbound_htlc_minimum_msat),
13615+
dust_exposure_msat: acc.dust_exposure_msat.max(e.dust_exposure_msat),
1360613616
})
1360713617
})
1360813618
}

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.0.
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
@@ -8025,6 +8025,7 @@ impl<
80258025
outbound_capacity_msat: 0,
80268026
next_outbound_htlc_limit_msat: 0,
80278027
next_outbound_htlc_minimum_msat: u64::MAX,
8028+
dust_exposure_msat: 0,
80288029
}
80298030
});
80308031
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
@@ -575,13 +575,15 @@ fn get_available_balances(
575575
next_outbound_htlc_minimum_msat,
576576
available_capacity_msat,
577577
);
578+
let dust_exposure_msat = cmp::max(local_dust_exposure_msat, remote_dust_exposure_msat);
578579

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

0 commit comments

Comments
 (0)