Skip to content

Commit 4644ab5

Browse files
committed
Implement support for accepting V2 channels
1 parent 1491387 commit 4644ab5

File tree

10 files changed

+1059
-125
lines changed

10 files changed

+1059
-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
@@ -491,6 +491,18 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
491491
(10, UnexpectedError) => {}, ;
492492
);
493493

494+
/// Used to indicate the kind of funding for this channel by the channel acceptor (us).
495+
///
496+
/// Allows the differentiation between a request for a dual-funded and non-dual-funded channel.
497+
#[derive(Clone, Debug, PartialEq, Eq)]
498+
pub enum OpenChannelRequestAcceptorFunds {
499+
/// For a non-dual-funded channel, the `push_msat` value from the channel initiator to us.
500+
PushMsat(u64),
501+
/// Indicates the open request is for a dual funded channel and we may choose to contribute
502+
/// funds to the channel.
503+
DualFunded,
504+
}
505+
494506
/// An Event which you should probably take some action in response to.
495507
///
496508
/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
@@ -1069,14 +1081,28 @@ pub enum Event {
10691081
},
10701082
/// Indicates a request to open a new channel by a peer.
10711083
///
1072-
/// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the request,
1073-
/// call [`ChannelManager::force_close_without_broadcasting_txn`]. Note that a ['ChannelClosed`]
1074-
/// event will _not_ be triggered if the channel is rejected.
1084+
/// If `our_funds` is `OpenChannelRequest::DualFunded`, this indicates that the peer wishes to
1085+
/// open a dual-funded channel. In this case you can choose whether to contribute funds or not.
1086+
/// Otherwise, `our_funds` will be `OpenChannelRequest::PushMsats`, indicating the `push_msats`
1087+
/// value for a non-dual-funded channel.
1088+
///
1089+
/// To accept the request (and in the case of a dual-funded channel, not contribute funds),
1090+
/// call [`ChannelManager::accept_inbound_channel`].
1091+
// TODO(dual_funding): Make this a doc comment when dual-funding fully released.
1092+
// To accept the request and contribute funds for a dual-funded channel,
1093+
// call [`ChannelManager::accept_inbound_channel_with_contribution`].
1094+
/// To reject the request, call [`ChannelManager::force_close_without_broadcasting_txn`].
1095+
/// Note that a ['ChannelClosed`] event will _not_ be triggered if the channel is rejected.
10751096
///
10761097
/// The event is only triggered when a new open channel request is received and the
10771098
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1099+
/// Note that if you wish to be able to contribute funds to dual-funded open channel requests,
1100+
/// [`UserConfig::manually_accept_inbound_channels`] MUST be set to true so that you may
1101+
/// provide funding inputs when choosing to contribute to the channel capacity.
10781102
///
10791103
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1104+
// TODO(dual_funding): Make this a doc comment when dual-funding fully released.
1105+
// [`ChannelManager::accept_inbound_channel_with_contribution`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_with_contribution
10801106
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
10811107
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
10821108
OpenChannelRequest {
@@ -1102,7 +1128,7 @@ pub enum Event {
11021128
/// The channel value of the requested channel.
11031129
funding_satoshis: u64,
11041130
/// Our starting balance in the channel if the request is accepted, in milli-satoshi.
1105-
push_msat: u64,
1131+
acceptor_funds: OpenChannelRequestAcceptorFunds,
11061132
/// The features that this channel will operate with. If you reject the channel, a
11071133
/// well-behaved counterparty may automatically re-attempt the channel with a new set of
11081134
/// feature flags.

0 commit comments

Comments
 (0)