Skip to content

Commit

Permalink
Reintroduce cfg(dual_funding) for handling of open_channel2 messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dunxen committed Dec 13, 2024
1 parent fa58f3a commit 490b2ac
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ check-cfg = [
"cfg(require_route_graph_test)",
"cfg(splicing)",
"cfg(async_payments)",
"cfg(dual_funding)",
]
1 change: 1 addition & 0 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ mod tests {
) {
}
fn handle_channel_update(&self, _their_node_id: PublicKey, _msg: &ChannelUpdate) {}
#[cfg(dual_funding)]
fn handle_open_channel_v2(&self, _their_node_id: PublicKey, _msg: &OpenChannelV2) {}
fn handle_accept_channel_v2(&self, _their_node_id: PublicKey, _msg: &AcceptChannelV2) {}
fn handle_stfu(&self, _their_node_id: PublicKey, _msg: &Stfu) {}
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11269,6 +11269,7 @@ where
});
}

#[cfg(dual_funding)]
fn handle_open_channel_v2(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannelV2) {
// 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
Expand Down
43 changes: 24 additions & 19 deletions lightning/src/ln/dual_funding_tests.rs
Original file line number Diff line number Diff 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 Down Expand 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
1 change: 1 addition & 0 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
/// Handle an incoming `open_channel` message from the given peer.
fn handle_open_channel(&self, their_node_id: PublicKey, msg: &OpenChannel);
/// Handle an incoming `open_channel2` message from the given peer.
#[cfg(dual_funding)]
fn handle_open_channel_v2(&self, their_node_id: PublicKey, msg: &OpenChannelV2);
/// Handle an incoming `accept_channel` message from the given peer.
fn handle_accept_channel(&self, their_node_id: PublicKey, msg: &AcceptChannel);
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
None
}

#[cfg(dual_funding)]
fn handle_open_channel_v2(&self, their_node_id: PublicKey, msg: &msgs::OpenChannelV2) {
ErroringMessageHandler::push_error(self, their_node_id, msg.common_fields.temporary_channel_id);
}
Expand Down Expand Up @@ -1820,8 +1821,9 @@ 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) => {
#[cfg(dual_funding)]
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
1 change: 1 addition & 0 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
Some(vec![self.chain_hash])
}

#[cfg(dual_funding)]
fn handle_open_channel_v2(&self, _their_node_id: PublicKey, msg: &msgs::OpenChannelV2) {
self.received_msg(wire::Message::OpenChannelV2(msg.clone()));
}
Expand Down

0 comments on commit 490b2ac

Please sign in to comment.