@@ -30,9 +30,7 @@ use bitcoin::hashes::{Hash, HashEngine, HmacEngine};
30
30
31
31
use bitcoin::secp256k1::Secp256k1;
32
32
use bitcoin::secp256k1::{PublicKey, SecretKey};
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::blinded_path::message::MessageForwardNode;
38
36
use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -122,7 +120,7 @@ use crate::util::errors::APIError;
122
120
use crate::util::logger::{Level, Logger, WithContext};
123
121
use crate::util::scid_utils::fake_scid;
124
122
use crate::util::ser::{
125
- BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs, VecWriter,
123
+ BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs, TransactionU16LenLimited, VecWriter,
126
124
Writeable, Writer,
127
125
};
128
126
use crate::util::string::UntrustedString;
@@ -8180,6 +8178,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8180
8178
false,
8181
8179
user_channel_id,
8182
8180
config_overrides,
8181
+ 0,
8182
+ vec![],
8183
8183
)
8184
8184
}
8185
8185
@@ -8211,14 +8211,69 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8211
8211
true,
8212
8212
user_channel_id,
8213
8213
config_overrides,
8214
+ 0,
8215
+ vec![],
8214
8216
)
8215
8217
}
8216
8218
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
+
8217
8271
/// TODO(dual_funding): Allow contributions, pass intended amount and inputs
8218
8272
#[rustfmt::skip]
8219
8273
fn do_accept_inbound_channel(
8220
8274
&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)>
8222
8277
) -> Result<(), APIError> {
8223
8278
8224
8279
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/
8277
8332
&self.channel_type_features(), &peer_state.latest_features,
8278
8333
&open_channel_msg,
8279
8334
user_channel_id, &config, best_block_height,
8280
- &self.logger,
8335
+ &self.logger, our_funding_satoshis, funding_inputs,
8281
8336
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
8282
8337
ChannelError::Close(
8283
8338
(
@@ -8561,7 +8616,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8561
8616
&self.fee_estimator, &self.entropy_source, &self.signer_provider,
8562
8617
self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(),
8563
8618
&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![],
8565
8620
).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?;
8566
8621
let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
8567
8622
node_id: *counterparty_node_id,
0 commit comments