Skip to content

Commit e90305a

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 6851b9e commit e90305a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lightning/src/ln/channelmanager.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -11984,6 +11984,12 @@ where
1198411984
}
1198511985

1198611986
fn handle_open_channel_v2(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannelV2) {
11987+
if !self.node_features().supports_dual_fund() {
11988+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
11989+
"Dual-funded channels not supported".to_owned(),
11990+
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
11991+
return;
11992+
}
1198711993
// Note that we never need to persist the updated ChannelManager for an inbound
1198811994
// open_channel message - pre-funded channels are never written so there should be no
1198911995
// change to the contents.
@@ -12873,7 +12879,9 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
1287312879
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
1287412880
features.set_anchors_zero_fee_htlc_tx_optional();
1287512881
}
12876-
features.set_dual_fund_optional();
12882+
if config.enable_dual_funded_channels {
12883+
features.set_dual_fund_optional();
12884+
}
1287712885
// Only signal quiescence support in tests for now, as we don't yet support any
1287812886
// quiescent-dependent protocols (e.g., splicing).
1287912887
#[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)