Skip to content

Commit fb00cb6

Browse files
committed
Add enable_dual_funded_channels to UserConfig
When this config field is enabled, the dual_fund feature bit will be set which determines support when receiving `open_channel2` messages.
1 parent 5cafaff commit fb00cb6

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

fuzz/src/full_stack.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
10901090
// our network key
10911091
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
10921092
// config
1093-
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000", &mut test);
1093+
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000", &mut test);
10941094

10951095
// new outbound connection with id 0
10961096
ext_from_hex("00", &mut test);
@@ -1606,7 +1606,7 @@ fn gossip_exchange_seed() -> Vec<u8> {
16061606
// our network key
16071607
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
16081608
// config
1609-
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000", &mut test);
1609+
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000", &mut test);
16101610

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

lightning/src/ln/channelmanager.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -11996,6 +11996,12 @@ where
1199611996
}
1199711997

1199811998
fn handle_open_channel_v2(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannelV2) {
11999+
if !self.init_features().supports_dual_fund() {
12000+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
12001+
"Dual-funded channels not supported".to_owned(),
12002+
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
12003+
return;
12004+
}
1199912005
// Note that we never need to persist the updated ChannelManager for an inbound
1200012006
// open_channel message - pre-funded channels are never written so there should be no
1200112007
// change to the contents.
@@ -12916,7 +12922,9 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
1291612922
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
1291712923
features.set_anchors_zero_fee_htlc_tx_optional();
1291812924
}
12919-
features.set_dual_fund_optional();
12925+
if config.enable_dual_funded_channels {
12926+
features.set_dual_fund_optional();
12927+
}
1292012928
// Only signal quiescence support in tests for now, as we don't yet support any
1292112929
// quiescent-dependent protocols (e.g., splicing).
1292212930
#[cfg(any(test, fuzzing))]

lightning/src/ln/dual_funding_tests.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ struct V2ChannelEstablishmentTestSession {
3939
fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession) {
4040
let chanmon_cfgs = create_chanmon_cfgs(2);
4141
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
42-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
42+
let mut node_1_user_config = test_default_channel_config();
43+
node_1_user_config.enable_dual_funded_channels = true;
44+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(node_1_user_config)]);
4345
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
4446
let logger_a = test_utils::TestLogger::with_id("node a".to_owned());
4547

lightning/src/util/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ pub struct UserConfig {
875875
/// [`ChannelManager::send_payment_for_bolt12_invoice`]: crate::ln::channelmanager::ChannelManager::send_payment_for_bolt12_invoice
876876
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
877877
pub manually_handle_bolt12_invoices: bool,
878+
/// If this is set to `true`, dual-funded channels will be enabled.
879+
///
880+
/// Default value: `false`
881+
pub enable_dual_funded_channels: bool,
878882
}
879883

880884
impl Default for UserConfig {
@@ -888,6 +892,7 @@ impl Default for UserConfig {
888892
manually_accept_inbound_channels: false,
889893
accept_intercept_htlcs: false,
890894
manually_handle_bolt12_invoices: false,
895+
enable_dual_funded_channels: false,
891896
}
892897
}
893898
}
@@ -907,6 +912,7 @@ impl Readable for UserConfig {
907912
manually_accept_inbound_channels: Readable::read(reader)?,
908913
accept_intercept_htlcs: Readable::read(reader)?,
909914
manually_handle_bolt12_invoices: Readable::read(reader)?,
915+
enable_dual_funded_channels: Readable::read(reader)?,
910916
})
911917
}
912918
}

0 commit comments

Comments
 (0)