Skip to content

Commit c7bc41f

Browse files
committed
Implement support for accepting V2 channels
1 parent fd19f61 commit c7bc41f

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
@@ -538,6 +538,18 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
538538
(10, UnexpectedError) => {}, ;
539539
);
540540

541+
/// Used to indicate the kind of funding for this channel by the channel acceptor (us).
542+
///
543+
/// Allows the differentiation between a request for a dual-funded and non-dual-funded channel.
544+
#[derive(Clone, Debug, PartialEq, Eq)]
545+
pub enum OpenChannelRequestAcceptorFunds {
546+
/// For a non-dual-funded channel, the `push_msat` value from the channel initiator to us.
547+
PushMsat(u64),
548+
/// Indicates the open request is for a dual funded channel and we may choose to contribute
549+
/// funds to the channel.
550+
DualFunded,
551+
}
552+
541553
/// An Event which you should probably take some action in response to.
542554
///
543555
/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
@@ -1141,14 +1153,28 @@ pub enum Event {
11411153
},
11421154
/// Indicates a request to open a new channel by a peer.
11431155
///
1144-
/// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the request,
1145-
/// call [`ChannelManager::force_close_without_broadcasting_txn`]. Note that a ['ChannelClosed`]
1146-
/// event will _not_ be triggered if the channel is rejected.
1156+
/// If `our_funds` is `OpenChannelRequest::DualFunded`, this indicates that the peer wishes to
1157+
/// open a dual-funded channel. In this case you can choose whether to contribute funds or not.
1158+
/// Otherwise, `our_funds` will be `OpenChannelRequest::PushMsats`, indicating the `push_msats`
1159+
/// value for a non-dual-funded channel.
1160+
///
1161+
/// To accept the request (and in the case of a dual-funded channel, not contribute funds),
1162+
/// call [`ChannelManager::accept_inbound_channel`].
1163+
// TODO(dual_funding): Make this a doc comment when dual-funding fully released.
1164+
// To accept the request and contribute funds for a dual-funded channel,
1165+
// call [`ChannelManager::accept_inbound_channel_with_contribution`].
1166+
/// To reject the request, call [`ChannelManager::force_close_without_broadcasting_txn`].
1167+
/// Note that a ['ChannelClosed`] event will _not_ be triggered if the channel is rejected.
11471168
///
11481169
/// The event is only triggered when a new open channel request is received and the
11491170
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1171+
/// Note that if you wish to be able to contribute funds to dual-funded open channel requests,
1172+
/// [`UserConfig::manually_accept_inbound_channels`] MUST be set to true so that you may
1173+
/// provide funding inputs when choosing to contribute to the channel capacity.
11501174
///
11511175
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1176+
// TODO(dual_funding): Make this a doc comment when dual-funding fully released.
1177+
// [`ChannelManager::accept_inbound_channel_with_contribution`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_with_contribution
11521178
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
11531179
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
11541180
OpenChannelRequest {
@@ -1174,7 +1200,7 @@ pub enum Event {
11741200
/// The channel value of the requested channel.
11751201
funding_satoshis: u64,
11761202
/// Our starting balance in the channel if the request is accepted, in milli-satoshi.
1177-
push_msat: u64,
1203+
acceptor_funds: OpenChannelRequestAcceptorFunds,
11781204
/// The features that this channel will operate with. If you reject the channel, a
11791205
/// well-behaved counterparty may automatically re-attempt the channel with a new set of
11801206
/// feature flags.

0 commit comments

Comments
 (0)