Skip to content

Commit ddcd9b0

Browse files
Add config knob for forwarding intercept payments
1 parent f79ad2e commit ddcd9b0

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
22332233
None => { // unknown_next_peer
22342234
// Note that this is likely a timing oracle for detecting whether an scid is a
22352235
// phantom or an intercept.
2236-
if fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash) ||
2237-
fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)
2236+
if (self.default_configuration.accept_intercept_htlcs &&
2237+
fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)) ||
2238+
fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)
22382239
{
22392240
None
22402241
} else {
@@ -3057,14 +3058,16 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
30573058
/// Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
30583059
/// channel to a receiving node if the node lacks sufficient inbound liquidity.
30593060
///
3060-
/// To make use of intercepted HTLCs, use [`ChannelManager::get_intercept_scid`] to generate short
3061-
/// channel id(s) to put in the receiver's invoice route hints. These route hints will signal to
3062-
/// LDK to generate an [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this
3063-
/// method or [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
3061+
/// To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
3062+
/// [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
3063+
/// receiver's invoice route hints. These route hints will signal to LDK to generate an
3064+
/// [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
3065+
/// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
30643066
///
30653067
/// Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
30663068
/// you from forwarding more than you received.
30673069
///
3070+
/// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
30683071
/// [`HTLCIntercepted`]: events::Event::HTLCIntercepted
30693072
// TODO: when we move to deciding the best outbound channel at forward time, only take
30703073
// `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
@@ -1385,9 +1385,13 @@ fn intercepted_payment() {
13851385
fn do_test_intercepted_payment(fail_intercept: bool) {
13861386
let chanmon_cfgs = create_chanmon_cfgs(3);
13871387
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
1388-
let mut chan_config = test_default_channel_config();
1389-
chan_config.manually_accept_inbound_channels = true;
1390-
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, Some(chan_config)]);
1388+
1389+
let mut zero_conf_chan_config = test_default_channel_config();
1390+
zero_conf_chan_config.manually_accept_inbound_channels = true;
1391+
let mut intercept_forwards_config = test_default_channel_config();
1392+
intercept_forwards_config.accept_intercept_htlcs = true;
1393+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(intercept_forwards_config), Some(zero_conf_chan_config)]);
1394+
13911395
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
13921396
let scorer = test_utils::TestScorer::with_penalty(0);
13931397
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
@@ -612,13 +612,14 @@ pub enum Event {
612612
},
613613
/// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
614614
/// you've encoded an intercept scid in the receiver's invoice route hints using
615-
/// [`ChannelManager::get_intercept_scid`].
615+
/// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
616616
///
617617
/// [`ChannelManager::forward_intercepted_htlc`] or
618618
/// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
619619
/// their docs for more information.
620620
///
621621
/// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
622+
/// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
622623
/// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
623624
/// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
624625
HTLCIntercepted {

0 commit comments

Comments
 (0)