Skip to content

Commit f53a09d

Browse files
authored
Merge pull request #3485 from dunxen/2024-12-cfgflagdualfunding
Reintroduce cfg(dual_funding) for handling of open_channel2 messages
2 parents c55f548 + 76608f7 commit f53a09d

7 files changed

+63
-27
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ check-cfg = [
6565
"cfg(require_route_graph_test)",
6666
"cfg(splicing)",
6767
"cfg(async_payments)",
68+
"cfg(dual_funding)",
6869
]

lightning/src/ln/channel.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
11291129
UnfundedInboundV1(InboundV1Channel<SP>),
11301130
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
11311131
UnfundedOutboundV2(OutboundV2Channel<SP>),
1132+
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
11321133
UnfundedInboundV2(InboundV2Channel<SP>),
11331134
Funded(Channel<SP>),
11341135
}
@@ -4089,7 +4090,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40894090
})
40904091
}
40914092

4092-
#[cfg(test)]
4093+
#[cfg(all(test, dual_funding))]
40934094
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
40944095
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
40954096
counterparty_cur_commitment_point_override: PublicKey,
@@ -4159,6 +4160,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
41594160
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
41604161
}
41614162

4163+
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
41624164
pub(super) fn calculate_our_funding_satoshis(
41634165
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
41644166
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
@@ -4208,6 +4210,7 @@ pub(super) struct DualFundingChannelContext {
42084210
/// to the current block height to align incentives against fee-sniping.
42094211
pub funding_tx_locktime: LockTime,
42104212
/// The feerate set by the initiator to be used for the funding transaction.
4213+
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
42114214
pub funding_feerate_sat_per_1000_weight: u32,
42124215
/// The funding inputs we will be contributing to the channel.
42134216
///
@@ -8292,6 +8295,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
82928295
}
82938296

82948297
impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
8298+
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
82958299
pub fn new<ES: Deref, F: Deref, L: Deref>(
82968300
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
82978301
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
@@ -9016,6 +9020,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
90169020
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
90179021
/// Creates a new dual-funded channel from a remote side's request for one.
90189022
/// Assumes chain_hash has already been checked and corresponds with what we expect!
9023+
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
90199024
pub fn new<ES: Deref, F: Deref, L: Deref>(
90209025
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
90219026
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
@@ -9124,6 +9129,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
91249129
/// should be sent back to the counterparty node.
91259130
///
91269131
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
9132+
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
91279133
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
91289134
if self.context.is_outbound() {
91299135
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
@@ -9146,6 +9152,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
91469152
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
91479153
///
91489154
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
9155+
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
91499156
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
91509157
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
91519158
self.unfunded_context.transaction_number(), &self.context.secp_ctx)

lightning/src/ln/channelmanager.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
4848
use crate::ln::inbound_payment;
4949
use crate::ln::types::ChannelId;
5050
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51-
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
51+
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
52+
#[cfg(any(dual_funding, splicing))]
53+
use crate::ln::channel::InboundV2Channel;
5254
use crate::ln::channel_state::ChannelDetails;
5355
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5456
#[cfg(any(feature = "_test_utils", test))]
@@ -1391,11 +1393,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
13911393
#[derive(Clone)]
13921394
pub(super) enum OpenChannelMessage {
13931395
V1(msgs::OpenChannel),
1396+
#[cfg(dual_funding)]
13941397
V2(msgs::OpenChannelV2),
13951398
}
13961399

13971400
pub(super) enum OpenChannelMessageRef<'a> {
13981401
V1(&'a msgs::OpenChannel),
1402+
#[cfg(dual_funding)]
13991403
V2(&'a msgs::OpenChannelV2),
14001404
}
14011405

@@ -7651,8 +7655,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
76517655

76527656
fn do_accept_inbound_channel(
76537657
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
7654-
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
7655-
total_witness_weight: Weight,
7658+
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
7659+
_total_witness_weight: Weight,
76567660
) -> Result<(), APIError> {
76577661
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
76587662
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -7696,10 +7700,11 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
76967700
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
76977701
})
76987702
},
7703+
#[cfg(dual_funding)]
76997704
OpenChannelMessage::V2(open_channel_msg) => {
77007705
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
77017706
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
7702-
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
7707+
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
77037708
&self.default_configuration, best_block_height, &self.logger
77047709
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
77057710
ChannelError::Close(
@@ -7852,6 +7857,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
78527857
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
78537858
let common_fields = match msg {
78547859
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
7860+
#[cfg(dual_funding)]
78557861
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
78567862
};
78577863

@@ -7929,6 +7935,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
79297935
funding_satoshis: common_fields.funding_satoshis,
79307936
channel_negotiation_type: match msg {
79317937
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
7938+
#[cfg(dual_funding)]
79327939
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
79337940
},
79347941
channel_type,
@@ -7938,6 +7945,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
79387945
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
79397946
open_channel_msg: match msg {
79407947
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
7948+
#[cfg(dual_funding)]
79417949
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
79427950
},
79437951
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
@@ -7973,6 +7981,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
79737981
});
79747982
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
79757983
},
7984+
#[cfg(dual_funding)]
79767985
OpenChannelMessageRef::V2(msg) => {
79777986
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
79787987
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
@@ -11271,6 +11280,7 @@ where
1127111280
// Note that we never need to persist the updated ChannelManager for an inbound
1127211281
// open_channel message - pre-funded channels are never written so there should be no
1127311282
// change to the contents.
11283+
#[cfg(dual_funding)]
1127411284
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
1127511285
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
1127611286
let persist = match &res {
@@ -11283,6 +11293,10 @@ where
1128311293
let _ = handle_error!(self, res, counterparty_node_id);
1128411294
persist
1128511295
});
11296+
#[cfg(not(dual_funding))]
11297+
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
11298+
"Dual-funded channels not supported".to_owned(),
11299+
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
1128611300
}
1128711301

1128811302
fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
@@ -12334,6 +12348,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
1233412348
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
1233512349
features.set_anchors_zero_fee_htlc_tx_optional();
1233612350
}
12351+
#[cfg(dual_funding)]
1233712352
features.set_dual_fund_optional();
1233812353
features
1233912354
}

lightning/src/ln/dual_funding_tests.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,36 @@
99

1010
//! Tests that test the creation of dual-funded channels in ChannelManager.
1111
12-
use bitcoin::Weight;
13-
14-
use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
15-
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
16-
use crate::ln::chan_utils::{
17-
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
18-
CounterpartyChannelTransactionParameters,
19-
};
20-
use crate::ln::channel::{
21-
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
12+
#[cfg(dual_funding)]
13+
use {
14+
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
15+
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
16+
crate::ln::chan_utils::{
17+
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
18+
CounterpartyChannelTransactionParameters,
19+
},
20+
crate::ln::channel::{
21+
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
22+
},
23+
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
24+
crate::ln::functional_test_utils::*,
25+
crate::ln::msgs::ChannelMessageHandler,
26+
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
27+
crate::ln::types::ChannelId,
28+
crate::prelude::*,
29+
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
30+
crate::util::ser::TransactionU16LenLimited,
31+
crate::util::test_utils,
32+
bitcoin::Weight,
2233
};
23-
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
24-
use crate::ln::functional_test_utils::*;
25-
use crate::ln::msgs::ChannelMessageHandler;
26-
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
27-
use crate::ln::types::ChannelId;
28-
use crate::prelude::*;
29-
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
30-
use crate::util::ser::TransactionU16LenLimited;
31-
use crate::util::test_utils;
3234

35+
#[cfg(dual_funding)]
3336
// Dual-funding: V2 Channel Establishment Tests
3437
struct V2ChannelEstablishmentTestSession {
3538
initiator_input_value_satoshis: u64,
3639
}
3740

41+
#[cfg(dual_funding)]
3842
// TODO(dual_funding): Use real node and API for creating V2 channels as initiator when available,
3943
// instead of manually constructing messages.
4044
fn do_test_v2_channel_establishment(
@@ -252,6 +256,7 @@ fn do_test_v2_channel_establishment(
252256
}
253257

254258
#[test]
259+
#[cfg(dual_funding)]
255260
fn test_v2_channel_establishment() {
256261
// Only initiator contributes, no persist pending
257262
do_test_v2_channel_establishment(

lightning/src/ln/peer_handler.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
340340
features.set_basic_mpp_optional();
341341
features.set_wumbo_optional();
342342
features.set_shutdown_any_segwit_optional();
343+
#[cfg(dual_funding)]
343344
features.set_dual_fund_optional();
344345
features.set_channel_type_optional();
345346
features.set_scid_privacy_optional();
@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
18201821
wire::Message::OpenChannel(msg) => {
18211822
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
18221823
},
1823-
wire::Message::OpenChannelV2(msg) => {
1824-
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
1824+
wire::Message::OpenChannelV2(_msg) => {
1825+
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
18251826
},
18261827
wire::Message::AcceptChannel(msg) => {
18271828
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);

pending_changelog/3137-accept-dual-funding-without-contributing.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# API Updates
1+
# API Updates (0.2)
22
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
33
Some particulars to be aware of for this feature:
44
* Creating dual-funded channels is not yet supported.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# API Updates
2+
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
3+
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
4+
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
5+
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
6+
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.
7+

0 commit comments

Comments
 (0)