@@ -30,9 +30,7 @@ use bitcoin::hashes::{Hash, HashEngine, HmacEngine};
3030
3131use bitcoin::secp256k1::Secp256k1;
3232use bitcoin::secp256k1::{PublicKey, SecretKey};
33- use bitcoin::{secp256k1, Sequence};
34- #[cfg(splicing)]
35- use bitcoin::{TxIn, Weight};
33+ use bitcoin::{secp256k1, Sequence, TxIn, Weight};
3634
3735use crate::blinded_path::message::MessageForwardNode;
3836use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -122,8 +120,8 @@ use crate::util::errors::APIError;
122120use crate::util::logger::{Level, Logger, WithContext};
123121use crate::util::scid_utils::fake_scid;
124122use crate::util::ser::{
125- BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs, VecWriter,
126- Writeable, Writer,
123+ BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs,
124+ TransactionU16LenLimited, VecWriter, Writeable, Writer,
127125};
128126use crate::util::string::UntrustedString;
129127use crate::util::wakers::{Future, Notifier};
@@ -8314,6 +8312,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83148312 false,
83158313 user_channel_id,
83168314 config_overrides,
8315+ 0,
8316+ vec![],
83178317 )
83188318 }
83198319
@@ -8345,14 +8345,82 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83458345 true,
83468346 user_channel_id,
83478347 config_overrides,
8348+ 0,
8349+ vec![],
83488350 )
83498351 }
83508352
8353+ /// Accepts a request to open a dual-funded channel with a contribution provided by us after an
8354+ /// [`Event::OpenChannelRequest`].
8355+ ///
8356+ /// The [`Event::OpenChannelRequest::channel_negotiation_type`] field will indicate the open channel
8357+ /// request is for a dual-funded channel when the variant is `InboundChannelFunds::DualFunded`.
8358+ ///
8359+ /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
8360+ /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
8361+ /// the channel.
8362+ ///
8363+ /// The `user_channel_id` parameter will be provided back in
8364+ /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
8365+ /// with which `accept_inbound_channel_*` call.
8366+ ///
8367+ /// The `funding_inputs` parameter provides the `txin`s along with their previous transactions, and
8368+ /// a corresponding witness weight for each input that will be used to contribute towards our
8369+ /// portion of the channel value. Our contribution will be calculated as the total value of these
8370+ /// inputs minus the fees we need to cover for the interactive funding transaction. The witness
8371+ /// weights must correspond to the witnesses you will provide through [`ChannelManager::funding_transaction_signed`]
8372+ /// after receiving [`Event::FundingTransactionReadyForSigning`].
8373+ ///
8374+ /// Note that this method will return an error and reject the channel if it requires support for
8375+ /// zero confirmations.
8376+ // TODO(dual_funding): Discussion on complications with 0conf dual-funded channels where "locking"
8377+ // of UTXOs used for funding would be required and other issues.
8378+ // See https://diyhpl.us/~bryan/irc/bitcoin/bitcoin-dev/linuxfoundation-pipermail/lightning-dev/2023-May/003922.txt
8379+ ///
8380+ /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
8381+ /// [`Event::OpenChannelRequest::channel_negotiation_type`]: events::Event::OpenChannelRequest::channel_negotiation_type
8382+ /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
8383+ /// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
8384+ /// [`ChannelManager::funding_transaction_signed`]: ChannelManager::funding_transaction_signed
8385+ pub fn accept_inbound_channel_with_contribution(
8386+ &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey,
8387+ user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>,
8388+ our_funding_satoshis: u64, funding_inputs: Vec<(TxIn, Transaction, Weight)>,
8389+ ) -> Result<(), APIError> {
8390+ let funding_inputs = Self::length_limit_holder_input_prev_txs(funding_inputs)?;
8391+ self.do_accept_inbound_channel(
8392+ temporary_channel_id,
8393+ counterparty_node_id,
8394+ false,
8395+ user_channel_id,
8396+ config_overrides,
8397+ our_funding_satoshis,
8398+ funding_inputs,
8399+ )
8400+ }
8401+
8402+ fn length_limit_holder_input_prev_txs(
8403+ funding_inputs: Vec<(TxIn, Transaction, Weight)>,
8404+ ) -> Result<Vec<(TxIn, TransactionU16LenLimited, Weight)>, APIError> {
8405+ funding_inputs
8406+ .into_iter()
8407+ .map(|(txin, tx, witness_weight)| match TransactionU16LenLimited::new(tx) {
8408+ Ok(tx) => Ok((txin, tx, witness_weight)),
8409+ Err(err) => Err(err),
8410+ })
8411+ .collect::<Result<Vec<(TxIn, TransactionU16LenLimited, Weight)>, ()>>()
8412+ .map_err(|_| APIError::APIMisuseError {
8413+ err: "One or more transactions had a serialized length exceeding 65535 bytes"
8414+ .into(),
8415+ })
8416+ }
8417+
83518418 /// TODO(dual_funding): Allow contributions, pass intended amount and inputs
83528419 #[rustfmt::skip]
83538420 fn do_accept_inbound_channel(
83548421 &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
8355- user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>
8422+ user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>, our_funding_satoshis: u64,
8423+ funding_inputs: Vec<(TxIn, TransactionU16LenLimited, Weight)>
83568424 ) -> Result<(), APIError> {
83578425
83588426 let mut config = self.default_configuration.clone();
@@ -8411,7 +8479,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84118479 &self.channel_type_features(), &peer_state.latest_features,
84128480 &open_channel_msg,
84138481 user_channel_id, &config, best_block_height,
8414- &self.logger,
8482+ &self.logger, our_funding_satoshis, funding_inputs,
84158483 ).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
84168484 ChannelError::Close(
84178485 (
@@ -8698,7 +8766,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
86988766 &self.fee_estimator, &self.entropy_source, &self.signer_provider,
86998767 self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(),
87008768 &peer_state.latest_features, msg, user_channel_id,
8701- &self.default_configuration, best_block_height, &self.logger,
8769+ &self.default_configuration, best_block_height, &self.logger, 0, vec![],
87028770 ).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?;
87038771 let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
87048772 node_id: *counterparty_node_id,
0 commit comments