@@ -30,9 +30,7 @@ use bitcoin::hash_types::{BlockHash, Txid};
30
30
31
31
use bitcoin::secp256k1::{SecretKey,PublicKey};
32
32
use bitcoin::secp256k1::Secp256k1;
33
- use bitcoin::{secp256k1, Sequence};
34
- #[cfg(splicing)]
35
- use bitcoin::{TxIn, Weight};
33
+ use bitcoin::{secp256k1, Sequence, TxIn, Weight};
36
34
37
35
use crate::events::{FundingInfo, PaidBolt12Invoice};
38
36
use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
@@ -84,7 +82,7 @@ use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelConfigOverr
84
82
use crate::util::wakers::{Future, Notifier};
85
83
use crate::util::scid_utils::fake_scid;
86
84
use crate::util::string::UntrustedString;
87
- use crate::util::ser::{BigSize, FixedLengthReader, LengthReadable, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter };
85
+ use crate::util::ser::{BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs, TransactionU16LenLimited, VecWriter, Writeable, Writer };
88
86
use crate::util::logger::{Level, Logger, WithContext};
89
87
use crate::util::errors::APIError;
90
88
@@ -7874,7 +7872,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
7874
7872
/// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
7875
7873
/// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
7876
7874
pub fn accept_inbound_channel(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>) -> Result<(), APIError> {
7877
- self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, false, user_channel_id, config_overrides)
7875
+ self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, false, user_channel_id, config_overrides, vec![] )
7878
7876
}
7879
7877
7880
7878
/// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
@@ -7896,13 +7894,61 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
7896
7894
/// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
7897
7895
/// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
7898
7896
pub fn accept_inbound_channel_from_trusted_peer_0conf(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>) -> Result<(), APIError> {
7899
- self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, true, user_channel_id, config_overrides)
7897
+ self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, true, user_channel_id, config_overrides, vec![])
7898
+ }
7899
+
7900
+ /// Accepts a request to open a dual-funded channel with a contribution provided by us after an
7901
+ /// [`Event::OpenChannelRequest`].
7902
+ ///
7903
+ /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
7904
+ /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
7905
+ /// the channel.
7906
+ ///
7907
+ /// The `user_channel_id` parameter will be provided back in
7908
+ /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
7909
+ /// with which `accept_inbound_channel_*` call.
7910
+ ///
7911
+ /// The `funding_inputs` parameter provides the `txin`s along with their previous transactions, and
7912
+ /// a corresponding witness weight for each input that will be used to contribute towards our
7913
+ /// portion of the channel value. Our contribution will be calculated as the total value of these
7914
+ /// inputs minus the fees we need to cover for the interactive funding transaction. The witness
7915
+ /// weights must correspond to the witnesses you will provide through [`ChannelManager::funding_transaction_signed`]
7916
+ /// after receiving [`Event::FundingTransactionReadyForSigning`].
7917
+ ///
7918
+ /// Note that this method will return an error and reject the channel if it requires support for
7919
+ /// zero confirmations.
7920
+ // TODO(dual_funding): Discussion on complications with 0conf dual-funded channels where "locking"
7921
+ // of UTXOs used for funding would be required and other issues.
7922
+ // See https://diyhpl.us/~bryan/irc/bitcoin/bitcoin-dev/linuxfoundation-pipermail/lightning-dev/2023-May/003922.txt
7923
+ ///
7924
+ /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
7925
+ /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
7926
+ /// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
7927
+ /// [`ChannelManager::funding_transaction_signed`]: ChannelManager::funding_transaction_signed
7928
+ pub fn accept_inbound_channel_with_contribution(
7929
+ &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, user_channel_id: u128,
7930
+ config_overrides: Option<ChannelConfigOverrides>, funding_inputs: Vec<(TxIn, Transaction, Weight)>
7931
+ ) -> Result<(), APIError> {
7932
+ let funding_inputs = Self::length_limit_holder_input_prev_txs(funding_inputs)?;
7933
+ self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, false, user_channel_id,
7934
+ config_overrides, funding_inputs)
7935
+ }
7936
+
7937
+ fn length_limit_holder_input_prev_txs(funding_inputs: Vec<(TxIn, Transaction, Weight)>) -> Result<Vec<(TxIn, TransactionU16LenLimited, Weight)>, APIError> {
7938
+ funding_inputs.into_iter().map(|(txin, tx, witness_weight)| {
7939
+ match TransactionU16LenLimited::new(tx) {
7940
+ Ok(tx) => Ok((txin, tx, witness_weight)),
7941
+ Err(err) => Err(err)
7942
+ }
7943
+ }).collect::<Result<Vec<(TxIn, TransactionU16LenLimited, Weight)>, ()>>()
7944
+ .map_err(|_| APIError::APIMisuseError { err: "One or more transactions had a serialized length exceeding 65535 bytes".into() })
7900
7945
}
7901
7946
7902
7947
/// TODO(dual_funding): Allow contributions, pass intended amount and inputs
7903
7948
fn do_accept_inbound_channel(
7904
7949
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
7905
- user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>
7950
+ user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>,
7951
+ funding_inputs: Vec<(TxIn, TransactionU16LenLimited, Weight)>
7906
7952
) -> Result<(), APIError> {
7907
7953
7908
7954
let mut config = self.default_configuration.clone();
@@ -7961,7 +8007,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
7961
8007
&self.channel_type_features(), &peer_state.latest_features,
7962
8008
&open_channel_msg,
7963
8009
user_channel_id, &config, best_block_height,
7964
- &self.logger,
8010
+ &self.logger, funding_inputs,
7965
8011
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
7966
8012
ChannelError::Close(
7967
8013
(
@@ -8242,7 +8288,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8242
8288
&self.fee_estimator, &self.entropy_source, &self.signer_provider,
8243
8289
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(),
8244
8290
&peer_state.latest_features, msg, user_channel_id,
8245
- &self.default_configuration, best_block_height, &self.logger,
8291
+ &self.default_configuration, best_block_height, &self.logger, vec![],
8246
8292
).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?;
8247
8293
let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
8248
8294
node_id: *counterparty_node_id,
0 commit comments