Skip to content

Commit eeb5b14

Browse files
authored
Merge pull request #4150 from wpaulino/user-config-reject-inbound-splice
Add UserConfig::reject_inbound_splices
2 parents 3e79de2 + 8d31a9b commit eeb5b14

File tree

5 files changed

+88
-7
lines changed

5 files changed

+88
-7
lines changed

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
10481048
// our network key
10491049
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
10501050
// config
1051-
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test);
1051+
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test);
10521052

10531053
// new outbound connection with id 0
10541054
ext_from_hex("00", &mut test);
@@ -1502,7 +1502,7 @@ fn gossip_exchange_seed() -> Vec<u8> {
15021502
// our network key
15031503
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
15041504
// config
1505-
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test);
1505+
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test);
15061506

15071507
// new outbound connection with id 0
15081508
ext_from_hex("00", &mut test);

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11476,6 +11476,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1147611476
counterparty_node_id, msg.channel_id,
1147711477
), msg.channel_id)),
1147811478
hash_map::Entry::Occupied(mut chan_entry) => {
11479+
if self.config.read().unwrap().reject_inbound_splices {
11480+
let err = ChannelError::WarnAndDisconnect(
11481+
"Inbound channel splices are currently not allowed".to_owned()
11482+
);
11483+
return Err(MsgHandleErrInternal::from_chan_no_close(err, msg.channel_id));
11484+
}
11485+
1147911486
if let Some(ref mut funded_channel) = chan_entry.get_mut().as_funded_mut() {
1148011487
let init_res = funded_channel.splice_init(
1148111488
msg, our_funding_contribution, &self.signer_provider, &self.entropy_source,
@@ -15325,16 +15332,15 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
1532515332
features.set_provide_storage_optional();
1532615333
#[cfg(simple_close)]
1532715334
features.set_simple_close_optional();
15335+
features.set_quiescence_optional();
15336+
features.set_splicing_optional();
15337+
1532815338
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
1532915339
features.set_anchors_zero_fee_htlc_tx_optional();
1533015340
}
1533115341
if config.enable_dual_funded_channels {
1533215342
features.set_dual_fund_optional();
1533315343
}
15334-
// Only signal quiescence support in tests for now, as we don't yet support any
15335-
// quiescent-dependent protocols (e.g., splicing).
15336-
#[cfg(any(test, fuzzing))]
15337-
features.set_quiescence_optional();
1533815344

1533915345
if config.channel_handshake_config.negotiate_anchor_zero_fee_commitments {
1534015346
features.set_anchor_zero_fee_commitments_optional();

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ macro_rules! reload_node {
13721372
($node: expr, $chanman_encoded: expr, $monitors_encoded: expr, $persister: ident, $new_chain_monitor: ident, $new_channelmanager: ident) => {
13731373
reload_node!(
13741374
$node,
1375-
$crate::util::config::UserConfig::default(),
1375+
test_default_channel_config(),
13761376
$chanman_encoded,
13771377
$monitors_encoded,
13781378
$persister,
@@ -4331,6 +4331,7 @@ pub fn test_default_channel_config() -> UserConfig {
43314331
// feerate of 253).
43324332
default_config.channel_config.max_dust_htlc_exposure =
43334333
MaxDustHTLCExposure::FeeRateMultiplier(50_000_000 / 253);
4334+
default_config.reject_inbound_splices = false;
43344335
default_config
43354336
}
43364337

lightning/src/ln/splicing_tests.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,66 @@ fn do_test_splice_state_reset_on_disconnect(reload: bool) {
507507
lock_splice_after_blocks(&nodes[0], &nodes[1], channel_id, ANTI_REORG_DELAY - 1);
508508
}
509509

510+
#[test]
511+
fn test_config_reject_inbound_splices() {
512+
// Tests that nodes with `reject_inbound_splices` properly reject inbound splices but still
513+
// allow outbound ones.
514+
let chanmon_cfgs = create_chanmon_cfgs(2);
515+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
516+
let mut config = test_default_channel_config();
517+
config.reject_inbound_splices = true;
518+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(config)]);
519+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
520+
521+
let node_id_0 = nodes[0].node.get_our_node_id();
522+
let node_id_1 = nodes[1].node.get_our_node_id();
523+
524+
let (_, _, channel_id, _) =
525+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 50_000_000);
526+
527+
let contribution = SpliceContribution::SpliceOut {
528+
outputs: vec![TxOut {
529+
value: Amount::from_sat(1_000),
530+
script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(),
531+
}],
532+
};
533+
nodes[0]
534+
.node
535+
.splice_channel(
536+
&channel_id,
537+
&node_id_1,
538+
contribution.clone(),
539+
FEERATE_FLOOR_SATS_PER_KW,
540+
None,
541+
)
542+
.unwrap();
543+
544+
let stfu = get_event_msg!(nodes[0], MessageSendEvent::SendStfu, node_id_1);
545+
nodes[1].node.handle_stfu(node_id_0, &stfu);
546+
let stfu = get_event_msg!(nodes[1], MessageSendEvent::SendStfu, node_id_0);
547+
nodes[0].node.handle_stfu(node_id_1, &stfu);
548+
549+
let splice_init = get_event_msg!(nodes[0], MessageSendEvent::SendSpliceInit, node_id_1);
550+
nodes[1].node.handle_splice_init(node_id_0, &splice_init);
551+
552+
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
553+
assert_eq!(msg_events.len(), 1);
554+
if let MessageSendEvent::HandleError { action, .. } = &msg_events[0] {
555+
assert!(matches!(action, msgs::ErrorAction::DisconnectPeerWithWarning { .. }));
556+
} else {
557+
panic!("Expected MessageSendEvent::HandleError");
558+
}
559+
560+
nodes[0].node.peer_disconnected(node_id_1);
561+
nodes[1].node.peer_disconnected(node_id_0);
562+
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
563+
reconnect_args.send_channel_ready = (true, true);
564+
reconnect_args.send_announcement_sigs = (true, true);
565+
reconnect_nodes(reconnect_args);
566+
567+
let _ = splice_channel(&nodes[1], &nodes[0], channel_id, contribution);
568+
}
569+
510570
#[test]
511571
fn test_splice_in() {
512572
let chanmon_cfgs = create_chanmon_cfgs(2);

lightning/src/util/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,18 @@ pub struct UserConfig {
956956
///
957957
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
958958
pub hold_outbound_htlcs_at_next_hop: bool,
959+
/// If this is set to `true`, then inbound channel splice requests will be rejected. This
960+
/// ensures backwards compatibility is not broken with LDK versions < 0.2 while a splice is
961+
/// pending.
962+
///
963+
/// Outbound channel splice requests (via [`ChannelManager::splice_channel`], an opt-in API) are
964+
/// still allowed as users should be aware of the backwards compatibility risk prior to using
965+
/// the functionality.
966+
///
967+
/// Default value: `true`
968+
///
969+
/// [`ChannelManager::splice_channel`]: crate::ln::channelmanager::ChannelManager::splice_channel
970+
pub reject_inbound_splices: bool,
959971
}
960972

961973
impl Default for UserConfig {
@@ -972,6 +984,7 @@ impl Default for UserConfig {
972984
enable_dual_funded_channels: false,
973985
enable_htlc_hold: false,
974986
hold_outbound_htlcs_at_next_hop: false,
987+
reject_inbound_splices: true,
975988
}
976989
}
977990
}
@@ -994,6 +1007,7 @@ impl Readable for UserConfig {
9941007
enable_dual_funded_channels: Readable::read(reader)?,
9951008
hold_outbound_htlcs_at_next_hop: Readable::read(reader)?,
9961009
enable_htlc_hold: Readable::read(reader)?,
1010+
reject_inbound_splices: Readable::read(reader)?,
9971011
})
9981012
}
9991013
}

0 commit comments

Comments
 (0)