Skip to content

Commit

Permalink
Add OpenChannelV2Request & dual-funded channel contribute config
Browse files Browse the repository at this point in the history
  • Loading branch information
dunxen committed Jul 12, 2023
1 parent 60ff104 commit a77c22f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,59 @@ pub enum Event {
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
channel_type: ChannelTypeFeatures,
},
/// Indicates a request to open a new dual-funded channel by a peer.
///
/// To accept the request, call [`ChannelManager::accept_inbound_dual_funded_channel`].
/// To reject the request, call [`ChannelManager::force_close_without_broadcasting_txn`].
///
/// The event is always triggered when a new open channel request is received for a dual-funded
/// channel, regardless of the value of the [`UserConfig::manually_accept_inbound_channels`]
/// config flag. This is so that funding inputs can be manually provided to contribute to the
/// overall channel capacity on the acceptor side.
///
/// [`ChannelManager::accept_inbound_dual_funded_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_dual_funded_channel
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
OpenChannelV2Request {
/// The temporary channel ID of the channel requested to be opened.
///
/// When responding to the request, the `temporary_channel_id` should be passed
/// back to the ChannelManager through [`ChannelManager::accept_inbound_dual_funded_channel`] to
/// accept, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
///
/// [`ChannelManager::accept_inbound_dual_funded_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_dual_funded_channel
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
temporary_channel_id: [u8; 32],
/// The node_id of the counterparty requesting to open the channel.
///
/// When responding to the request, the `counterparty_node_id` should be passed
/// back to the `ChannelManager` through [`ChannelManager::accept_inbound_dual_funded_channel`] to
/// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
/// request.
///
/// [`ChannelManager::accept_inbound_dual_funded_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_dual_funded_channel
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
counterparty_node_id: PublicKey,
/// The counterparty's contribution to the channel value in satoshis.
funding_satoshis: u64,
/// The features that this channel will operate with. If you reject the channel, a
/// well-behaved counterparty may automatically re-attempt the channel with a new set of
/// feature flags.
///
/// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
/// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
/// 0.0.106.
///
/// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
/// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
/// 0.0.107.
///
/// NOTE: Zero-conf dual-funded channels are not currently accepted.
// TODO(dual_funding): Maybe support opportunistic zero-conf channels like Eclair?
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
channel_type: ChannelTypeFeatures,
},
/// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
/// forward it.
///
Expand Down Expand Up @@ -1058,6 +1111,12 @@ impl Writeable for Event {
(8, funding_txo, required),
});
},
&Event::OpenChannelV2Request { .. } => {
33u8.write(writer)?;
// We never write the OpenChannelV2Request events as, upon disconnection, peers
// drop any channels which have not yet completed any interactive funding transaction
// construction.
},
// Note that, going forward, all new events must only write data inside of
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
// data via `write_tlv_fields`.
Expand Down
16 changes: 16 additions & 0 deletions lightning/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,21 @@ pub struct UserConfig {
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
pub accept_mpp_keysend: bool,
/// If this is set to true, regardless of `accept_inbound_channels`, the user needs to manually
/// accept inbound requests to open a new dual-funded channel and provide any UTXOs they'd like
/// to contribute to the funding transaction.
///
/// When set to true, [`Event::OpenChannelV2Request`] will be triggered once a request to open a
/// new inbound dual-funded channel is received through a [`msgs::OpenChannelV2`] message. In that
/// case, a [`msgs::AcceptChannelV2`] message will not be sent back to the counterparty node unless
/// the user explicitly chooses to accept the request.
///
/// Default value: false.
///
/// [`Event::OpenChannelV2Request`]: crate::events::Event::OpenChannelV2Request
/// [`msgs::OpenChannelV2`]: crate::ln::msgs::OpenChannelV2
/// [`msgs::AcceptChannelV2`]: crate::ln::msgs::AcceptChannelV2
pub contribute_to_dual_funded_channels: bool,
}

impl Default for UserConfig {
Expand All @@ -777,6 +792,7 @@ impl Default for UserConfig {
manually_accept_inbound_channels: false,
accept_intercept_htlcs: false,
accept_mpp_keysend: false,
contribute_to_dual_funded_channels: false,
}
}
}

0 comments on commit a77c22f

Please sign in to comment.