@@ -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,7 +120,7 @@ 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,
123+ BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs, TransactionU16LenLimited, VecWriter,
126124 Writeable, Writer,
127125};
128126use crate::util::string::UntrustedString;
@@ -8180,6 +8178,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81808178 false,
81818179 user_channel_id,
81828180 config_overrides,
8181+ 0,
8182+ vec![],
81838183 )
81848184 }
81858185
@@ -8211,14 +8211,69 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82118211 true,
82128212 user_channel_id,
82138213 config_overrides,
8214+ 0,
8215+ vec![],
82148216 )
82158217 }
82168218
8219+ /// Accepts a request to open a dual-funded channel with a contribution provided by us after an
8220+ /// [`Event::OpenChannelRequest`].
8221+ ///
8222+ /// The [`Event::OpenChannelRequest::channel_negotiation_type`] field will indicate the open channel
8223+ /// request is for a dual-funded channel when the variant is `InboundChannelFunds::DualFunded`.
8224+ ///
8225+ /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
8226+ /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
8227+ /// the channel.
8228+ ///
8229+ /// The `user_channel_id` parameter will be provided back in
8230+ /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
8231+ /// with which `accept_inbound_channel_*` call.
8232+ ///
8233+ /// The `funding_inputs` parameter provides the `txin`s along with their previous transactions, and
8234+ /// a corresponding witness weight for each input that will be used to contribute towards our
8235+ /// portion of the channel value. Our contribution will be calculated as the total value of these
8236+ /// inputs minus the fees we need to cover for the interactive funding transaction. The witness
8237+ /// weights must correspond to the witnesses you will provide through [`ChannelManager::funding_transaction_signed`]
8238+ /// after receiving [`Event::FundingTransactionReadyForSigning`].
8239+ ///
8240+ /// Note that this method will return an error and reject the channel if it requires support for
8241+ /// zero confirmations.
8242+ // TODO(dual_funding): Discussion on complications with 0conf dual-funded channels where "locking"
8243+ // of UTXOs used for funding would be required and other issues.
8244+ // See https://diyhpl.us/~bryan/irc/bitcoin/bitcoin-dev/linuxfoundation-pipermail/lightning-dev/2023-May/003922.txt
8245+ ///
8246+ /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
8247+ /// [`Event::OpenChannelRequest::channel_negotiation_type`]: events::Event::OpenChannelRequest::channel_negotiation_type
8248+ /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
8249+ /// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
8250+ /// [`ChannelManager::funding_transaction_signed`]: ChannelManager::funding_transaction_signed
8251+ pub fn accept_inbound_channel_with_contribution(
8252+ &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, user_channel_id: u128,
8253+ config_overrides: Option<ChannelConfigOverrides>, our_funding_satoshis: u64,
8254+ funding_inputs: Vec<(TxIn, Transaction, Weight)>
8255+ ) -> Result<(), APIError> {
8256+ let funding_inputs = Self::length_limit_holder_input_prev_txs(funding_inputs)?;
8257+ self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, false, user_channel_id,
8258+ config_overrides, our_funding_satoshis, funding_inputs)
8259+ }
8260+
8261+ fn length_limit_holder_input_prev_txs(funding_inputs: Vec<(TxIn, Transaction, Weight)>) -> Result<Vec<(TxIn, TransactionU16LenLimited, Weight)>, APIError> {
8262+ funding_inputs.into_iter().map(|(txin, tx, witness_weight)| {
8263+ match TransactionU16LenLimited::new(tx) {
8264+ Ok(tx) => Ok((txin, tx, witness_weight)),
8265+ Err(err) => Err(err)
8266+ }
8267+ }).collect::<Result<Vec<(TxIn, TransactionU16LenLimited, Weight)>, ()>>()
8268+ .map_err(|_| APIError::APIMisuseError { err: "One or more transactions had a serialized length exceeding 65535 bytes".into() })
8269+ }
8270+
82178271 /// TODO(dual_funding): Allow contributions, pass intended amount and inputs
82188272 #[rustfmt::skip]
82198273 fn do_accept_inbound_channel(
82208274 &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
8221- user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>
8275+ user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>, our_funding_satoshis: u64,
8276+ funding_inputs: Vec<(TxIn, TransactionU16LenLimited, Weight)>
82228277 ) -> Result<(), APIError> {
82238278
82248279 let mut config = self.default_configuration.clone();
@@ -8277,7 +8332,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82778332 &self.channel_type_features(), &peer_state.latest_features,
82788333 &open_channel_msg,
82798334 user_channel_id, &config, best_block_height,
8280- &self.logger,
8335+ &self.logger, our_funding_satoshis, funding_inputs,
82818336 ).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
82828337 ChannelError::Close(
82838338 (
@@ -8561,7 +8616,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
85618616 &self.fee_estimator, &self.entropy_source, &self.signer_provider,
85628617 self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(),
85638618 &peer_state.latest_features, msg, user_channel_id,
8564- &self.default_configuration, best_block_height, &self.logger,
8619+ &self.default_configuration, best_block_height, &self.logger, 0, vec![],
85658620 ).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?;
85668621 let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
85678622 node_id: *counterparty_node_id,
0 commit comments