Skip to content

Commit a6f3661

Browse files
Add config knob for forwarding intercept payments
1 parent d35b63c commit a6f3661

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
22272227
// Note that this is likely a timing oracle for detecting whether an scid is a
22282228
// phantom or an intercept.
22292229
if fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash) ||
2230-
fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)
2230+
(fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)
2231+
&& self.default_configuration.accept_intercept_htlcs)
22312232
{
22322233
None
22332234
} else {
@@ -3050,14 +3051,16 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
30503051
/// Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
30513052
/// channel to a receiving node if the node lacks sufficient inbound liquidity.
30523053
///
3053-
/// To make use of intercepted HTLCs, use [`ChannelManager::get_intercept_scid`] to generate short
3054-
/// channel id(s) to put in the receiver's invoice route hints. These route hints will signal to
3055-
/// LDK to generate an [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this
3056-
/// method or [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
3054+
/// To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
3055+
/// [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
3056+
/// receiver's invoice route hints. These route hints will signal to LDK to generate an
3057+
/// [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
3058+
/// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
30573059
///
30583060
/// Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
30593061
/// you from forwarding more than you received.
30603062
///
3063+
/// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
30613064
/// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
30623065
// TODO: when we move to deciding the best outbound channel at forward time, only take
30633066
// `next_node_id` and not `next_hop_channel_id`

lightning/src/ln/payment_tests.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,9 +1384,13 @@ fn intercepted_payment() {
13841384
fn do_test_intercepted_payment(fail_intercept: bool) {
13851385
let chanmon_cfgs = create_chanmon_cfgs(3);
13861386
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
1387-
let mut chan_config = test_default_channel_config();
1388-
chan_config.manually_accept_inbound_channels = true;
1389-
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, Some(chan_config)]);
1387+
1388+
let mut zero_conf_chan_config = test_default_channel_config();
1389+
zero_conf_chan_config.manually_accept_inbound_channels = true;
1390+
let mut intercept_forwards_config = test_default_channel_config();
1391+
intercept_forwards_config.accept_intercept_htlcs = true;
1392+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(intercept_forwards_config), Some(zero_conf_chan_config)]);
1393+
13901394
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
13911395
let scorer = test_utils::TestScorer::with_penalty(0);
13921396
let random_seed_bytes = chanmon_cfgs[0].keys_manager.get_secure_random_bytes();

lightning/src/util/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@ pub struct UserConfig {
505505
/// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
506506
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
507507
pub manually_accept_inbound_channels: bool,
508+
/// If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
509+
/// fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
510+
/// intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
511+
///
512+
/// Setting this to true may break backwards compatibility with LDK versions <= 0.0.113.
513+
///
514+
/// Default value: false.
515+
///
516+
/// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
517+
/// [`Event::HTLCIntercepted`]: crate::util::events::Event::HTLCIntercepted
518+
pub accept_intercept_htlcs: bool,
508519
}
509520

510521
impl Default for UserConfig {
@@ -516,6 +527,7 @@ impl Default for UserConfig {
516527
accept_forwards_to_priv_channels: false,
517528
accept_inbound_channels: true,
518529
manually_accept_inbound_channels: false,
530+
accept_intercept_htlcs: false,
519531
}
520532
}
521533
}

lightning/src/util/events.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,14 @@ pub enum Event {
594594
},
595595
/// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
596596
/// you've encoded an intercept scid in the receiver's invoice route hints using
597-
/// [`ChannelManager::get_intercept_scid`].
597+
/// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
598598
///
599599
/// [`ChannelManager::forward_intercepted_htlc`] or
600600
/// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
601601
/// their docs for more information.
602602
///
603603
/// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
604+
/// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
604605
/// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
605606
/// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
606607
HTLCIntercepted {

0 commit comments

Comments
 (0)