Skip to content

Commit 7238c24

Browse files
Add config knob for forwarding intercept payments
1 parent 26ec1a6 commit 7238c24

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
23382338
// Note that this is likely a timing oracle for detecting whether an scid is a
23392339
// phantom or an intercept.
23402340
if fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash) ||
2341-
fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)
2341+
(fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, *short_channel_id, &self.genesis_hash)
2342+
&& self.default_configuration.accept_intercept_htlcs)
23422343
{
23432344
None
23442345
} else {

lightning/src/ln/payment_tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,11 @@ fn intercepted_payment() {
13991399
fn do_test_intercepted_payment(fail_intercept: bool) {
14001400
let chanmon_cfgs = create_chanmon_cfgs(3);
14011401
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
1402-
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
1402+
1403+
let mut intercept_forwards_config = test_default_channel_config();
1404+
intercept_forwards_config.accept_intercept_htlcs = true;
1405+
1406+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(intercept_forwards_config), None]);
14031407
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
14041408
let scorer = test_utils::TestScorer::with_penalty(0);
14051409
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
}

0 commit comments

Comments
 (0)