Skip to content

Commit aec4e43

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 cfedf38 commit aec4e43

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

Diff for: fuzz/src/full_stack.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ mod tests {
11191119
// our network key
11201120
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
11211121
// config
1122-
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000", &mut test);
1122+
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000", &mut test);
11231123

11241124
// new outbound connection with id 0
11251125
ext_from_hex("00", &mut test);
@@ -1674,7 +1674,7 @@ mod tests {
16741674
// our network key
16751675
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
16761676
// config
1677-
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000", &mut test);
1677+
ext_from_hex("0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000", &mut test);
16781678

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

Diff for: lightning/src/ln/channelmanager.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -11987,6 +11987,12 @@ where
1198711987
}
1198811988

1198911989
fn handle_open_channel_v2(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannelV2) {
11990+
if !self.node_features().supports_dual_fund() {
11991+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
11992+
"Dual-funded channels not supported".to_owned(),
11993+
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
11994+
return;
11995+
}
1199011996
// Note that we never need to persist the updated ChannelManager for an inbound
1199111997
// open_channel message - pre-funded channels are never written so there should be no
1199211998
// change to the contents.
@@ -12902,7 +12908,9 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
1290212908
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
1290312909
features.set_anchors_zero_fee_htlc_tx_optional();
1290412910
}
12905-
features.set_dual_fund_optional();
12911+
if config.enable_dual_funded_channels {
12912+
features.set_dual_fund_optional();
12913+
}
1290612914
// Only signal quiescence support in tests for now, as we don't yet support any
1290712915
// quiescent-dependent protocols (e.g., splicing).
1290812916
#[cfg(any(test, fuzzing))]

Diff for: 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

Diff for: 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)