Skip to content

Commit 2fd1a9a

Browse files
committed
Implement support for accepting V2 channels
1 parent aee14fd commit 2fd1a9a

File tree

10 files changed

+1073
-125
lines changed

10 files changed

+1073
-125
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ mod tests {
621621
fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {}
622622
fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures) {}
623623
fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &ChannelUpdate) {}
624+
#[cfg(any(dual_funding, splicing))]
624625
fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _msg: &OpenChannelV2) {}
626+
#[cfg(any(dual_funding, splicing))]
625627
fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
626628
fn handle_stfu(&self, _their_node_id: &PublicKey, _msg: &Stfu) {}
627629
#[cfg(splicing)]
@@ -630,14 +632,23 @@ mod tests {
630632
fn handle_splice_ack(&self, _their_node_id: &PublicKey, _msg: &SpliceAck) {}
631633
#[cfg(splicing)]
632634
fn handle_splice_locked(&self, _their_node_id: &PublicKey, _msg: &SpliceLocked) {}
635+
#[cfg(any(dual_funding, splicing))]
633636
fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {}
637+
#[cfg(any(dual_funding, splicing))]
634638
fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {}
639+
#[cfg(any(dual_funding, splicing))]
635640
fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, _msg: &TxRemoveInput) {}
641+
#[cfg(any(dual_funding, splicing))]
636642
fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, _msg: &TxRemoveOutput) {}
643+
#[cfg(any(dual_funding, splicing))]
637644
fn handle_tx_complete(&self, _their_node_id: &PublicKey, _msg: &TxComplete) {}
645+
#[cfg(any(dual_funding, splicing))]
638646
fn handle_tx_signatures(&self, _their_node_id: &PublicKey, _msg: &TxSignatures) {}
647+
#[cfg(any(dual_funding, splicing))]
639648
fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, _msg: &TxInitRbf) {}
649+
#[cfg(any(dual_funding, splicing))]
640650
fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, _msg: &TxAckRbf) {}
651+
#[cfg(any(dual_funding, splicing))]
641652
fn handle_tx_abort(&self, _their_node_id: &PublicKey, _msg: &TxAbort) {}
642653
fn peer_disconnected(&self, their_node_id: &PublicKey) {
643654
if *their_node_id == self.expected_pubkey {

lightning/src/events/mod.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,18 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
536536
(10, UnexpectedError) => {}, ;
537537
);
538538

539+
/// Used to indicate the kind of funding for this channel by the channel acceptor (us).
540+
///
541+
/// Allows the differentiation between a request for a dual-funded and non-dual-funded channel.
542+
#[derive(Clone, Debug, PartialEq, Eq)]
543+
pub enum OpenChannelRequestAcceptorFunds {
544+
/// For a non-dual-funded channel, the `push_msat` value from the channel initiator to us.
545+
PushMsat(u64),
546+
/// Indicates the open request is for a dual funded channel and we may choose to contribute
547+
/// funds to the channel.
548+
DualFunded,
549+
}
550+
539551
/// An Event which you should probably take some action in response to.
540552
///
541553
/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
@@ -1114,14 +1126,28 @@ pub enum Event {
11141126
},
11151127
/// Indicates a request to open a new channel by a peer.
11161128
///
1117-
/// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the request,
1118-
/// call [`ChannelManager::force_close_without_broadcasting_txn`]. Note that a ['ChannelClosed`]
1119-
/// event will _not_ be triggered if the channel is rejected.
1129+
/// If `our_funds` is `OpenChannelRequest::DualFunded`, this indicates that the peer wishes to
1130+
/// open a dual-funded channel. In this case you can choose whether to contribute funds or not.
1131+
/// Otherwise, `our_funds` will be `OpenChannelRequest::PushMsats`, indicating the `push_msats`
1132+
/// value for a non-dual-funded channel.
1133+
///
1134+
/// To accept the request (and in the case of a dual-funded channel, not contribute funds),
1135+
/// call [`ChannelManager::accept_inbound_channel`].
1136+
// TODO(dual_funding): Make this a doc comment when dual-funding fully released.
1137+
// To accept the request and contribute funds for a dual-funded channel,
1138+
// call [`ChannelManager::accept_inbound_channel_with_contribution`].
1139+
/// To reject the request, call [`ChannelManager::force_close_without_broadcasting_txn`].
1140+
/// Note that a ['ChannelClosed`] event will _not_ be triggered if the channel is rejected.
11201141
///
11211142
/// The event is only triggered when a new open channel request is received and the
11221143
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1144+
/// Note that if you wish to be able to contribute funds to dual-funded open channel requests,
1145+
/// [`UserConfig::manually_accept_inbound_channels`] MUST be set to true so that you may
1146+
/// provide funding inputs when choosing to contribute to the channel capacity.
11231147
///
11241148
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1149+
// TODO(dual_funding): Make this a doc comment when dual-funding fully released.
1150+
// [`ChannelManager::accept_inbound_channel_with_contribution`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_with_contribution
11251151
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
11261152
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
11271153
OpenChannelRequest {
@@ -1147,7 +1173,7 @@ pub enum Event {
11471173
/// The channel value of the requested channel.
11481174
funding_satoshis: u64,
11491175
/// Our starting balance in the channel if the request is accepted, in milli-satoshi.
1150-
push_msat: u64,
1176+
acceptor_funds: OpenChannelRequestAcceptorFunds,
11511177
/// The features that this channel will operate with. If you reject the channel, a
11521178
/// well-behaved counterparty may automatically re-attempt the channel with a new set of
11531179
/// feature flags.

0 commit comments

Comments
 (0)