Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
9 changes: 8 additions & 1 deletion lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1131,6 +1131,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
UnfundedOutboundV2(OutboundV2Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
UnfundedInboundV2(InboundV2Channel<SP>),
Funded(Channel<SP>),
}
Expand DownExpand Up@@ -4080,7 +4081,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
})
}

#[cfg(test)]
#[cfg(all(test, dual_funding))]
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
&mut self, logger: &L, channel_transaction_parameters: ChannelTransactionParameters,
counterparty_cur_commitment_point_override: PublicKey,
Expand DownExpand Up@@ -4150,6 +4151,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
}

#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub(super) fn calculate_our_funding_satoshis(
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
Expand DownExpand Up@@ -4199,6 +4201,7 @@ pub(super) struct DualFundingChannelContext {
/// to the current block height to align incentives against fee-sniping.
pub funding_tx_locktime: LockTime,
/// The feerate set by the initiator to be used for the funding transaction.
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub funding_feerate_sat_per_1000_weight: u32,
/// The funding inputs we will be contributing to the channel.
///
Expand DownExpand Up@@ -8276,6 +8279,7 @@ pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider
}

impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
#[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
Expand DownExpand Up@@ -8901,6 +8905,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// Creates a new dual-funded channel from a remote side's request for one.
/// Assumes chain_hash has already been checked and corresponds with what we expect!
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn new<ES: Deref, F: Deref, L: Deref>(
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
Expand DownExpand Up@@ -9005,6 +9010,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// should be sent back to the counterparty node.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
pub fn accept_inbound_dual_funded_channel(&self) -> msgs::AcceptChannelV2 {
if self.context.is_outbound() {
debug_assert!(false, "Tried to send accept_channel for an outbound channel?");
Expand All@@ -9027,6 +9033,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
/// use [`InboundV1Channel::accept_inbound_channel`] instead.
///
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
fn generate_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(
self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx)
Expand Down
23 changes: 19 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,9 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::InboundV2Channel;
use crate::ln::channel_state::ChannelDetails;
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
Expand DownExpand Up@@ -1376,11 +1378,13 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
#[derive(Clone)]
pub(super) enum OpenChannelMessage {
V1(msgs::OpenChannel),
#[cfg(dual_funding)]
V2(msgs::OpenChannelV2),
}

pub(super) enum OpenChannelMessageRef<'a> {
V1(&'a msgs::OpenChannel),
#[cfg(dual_funding)]
V2(&'a msgs::OpenChannelV2),
}

Expand DownExpand Up@@ -7686,8 +7690,8 @@ where

fn do_accept_inbound_channel(
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
user_channel_id: u128, funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
total_witness_weight: Weight,
user_channel_id: u128, _funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
_total_witness_weight: Weight,
) -> Result<(), APIError> {
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Expand DownExpand Up@@ -7728,10 +7732,11 @@ where
(*temporary_channel_id, ChannelPhase::UnfundedInboundV1(channel), message_send_event)
})
},
#[cfg(dual_funding)]
OpenChannelMessage::V2(open_channel_msg) => {
InboundV2Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), &peer_state.latest_features,
&open_channel_msg, funding_inputs, total_witness_weight, user_channel_id,
&open_channel_msg, _funding_inputs, _total_witness_weight, user_channel_id,
&self.default_configuration, best_block_height, &self.logger
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
ChannelError::Close(
Expand DownExpand Up@@ -7882,6 +7887,7 @@ where
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> {
let common_fields = match msg {
OpenChannelMessageRef::V1(msg) => &msg.common_fields,
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => &msg.common_fields,
};

Expand DownExpand Up@@ -7959,6 +7965,7 @@ where
funding_satoshis: common_fields.funding_satoshis,
channel_negotiation_type: match msg {
OpenChannelMessageRef::V1(msg) => InboundChannelFunds::PushMsat(msg.push_msat),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(_) => InboundChannelFunds::DualFunded,
},
channel_type,
Expand All@@ -7968,6 +7975,7 @@ where
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()),
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()),
},
ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS,
Expand DownExpand Up@@ -8000,6 +8008,7 @@ where
};
(ChannelPhase::UnfundedInboundV1(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
let channel = InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
&self.signer_provider, self.get_our_node_id(), *counterparty_node_id,
Expand DownExpand Up@@ -11273,6 +11282,7 @@ where
// Note that we never need to persist the updated ChannelManager for an inbound
// open_channel message - pre-funded channels are never written so there should be no
// change to the contents.
#[cfg(dual_funding)]
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
let res = self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V2(msg));
let persist = match &res {
Expand All@@ -11285,6 +11295,10 @@ where
let _ = handle_error!(self, res, counterparty_node_id);
persist
});
#[cfg(not(dual_funding))]
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Dual-funded channels not supported".to_owned(),
msg.common_fields.temporary_channel_id.clone())), counterparty_node_id);
}

fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) {
Expand DownExpand Up@@ -12332,6 +12346,7 @@ pub fn provided_init_features(config: &UserConfig) -> InitFeatures {
if config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx {
features.set_anchors_zero_fee_htlc_tx_optional();
}
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features
}
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,32 +9,36 @@

//! Tests that test the creation of dual-funded channels in ChannelManager.

use bitcoin::Weight;

use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
};
use crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
#[cfg(dual_funding)]
use {
crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator},
crate::events::{Event, MessageSendEvent, MessageSendEventsProvider},
crate::ln::chan_utils::{
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
CounterpartyChannelTransactionParameters,
},
crate::ln::channel::{
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
},
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
crate::ln::functional_test_utils::*,
crate::ln::msgs::ChannelMessageHandler,
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
crate::ln::types::ChannelId,
crate::prelude::*,
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
crate::util::ser::TransactionU16LenLimited,
crate::util::test_utils,
bitcoin::Weight,
};
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
use crate::ln::types::ChannelId;
use crate::prelude::*;
use crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT};
use crate::util::ser::TransactionU16LenLimited;
use crate::util::test_utils;

#[cfg(dual_funding)]
// Dual-funding: V2 Channel Establishment Tests
struct V2ChannelEstablishmentTestSession {
initiator_input_value_satoshis: u64,
}

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

#[test]
#[cfg(dual_funding)]
fn test_v2_channel_establishment() {
// Only initiator contributes, no persist pending
do_test_v2_channel_establishment(
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -340,6 +340,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
features.set_basic_mpp_optional();
features.set_wumbo_optional();
features.set_shutdown_any_segwit_optional();
#[cfg(dual_funding)]
features.set_dual_fund_optional();
features.set_channel_type_optional();
features.set_scid_privacy_optional();
Expand DownExpand Up@@ -1820,8 +1821,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
wire::Message::OpenChannel(msg) => {
self.message_handler.chan_handler.handle_open_channel(their_node_id, &msg);
},
wire::Message::OpenChannelV2(msg) => {
self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &msg);
wire::Message::OpenChannelV2(_msg) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this doesn't seem required :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yup. Ended up removing the cfg flag in the branch...

self.message_handler.chan_handler.handle_open_channel_v2(their_node_id, &_msg);
},
wire::Message::AcceptChannel(msg) => {
self.message_handler.chan_handler.handle_accept_channel(their_node_id, &msg);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# API Updates
Comment thread
dunxen marked this conversation as resolved.
# API Updates (0.2)
* Accepting dual-funded (V2 establishment) channels (without contibuting) is now supported (#3137).
Some particulars to be aware of for this feature:
* Creating dual-funded channels is not yet supported.
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/3137-channel-negotiation-type.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# API Updates
* `Event::OpenChannelRequest::push_msat` has been replaced by the field `channel_negotiation_type` to
differentiate between an inbound request for a dual-funded (V2) or non-dual-funded (V1) channel to be
opened, with value being either of the enum variants `InboundChannelFunds::DualFunded` and
`InboundChannelFunds::PushMsat(u64)` corresponding to V2 and V1 channel open requests respectively.
This is in preparation for supporting accepting dual-funded channels, which will be available in a later release.