@@ -13,7 +13,7 @@ use bitcoin::consensus::encode;
13
13
use bitcoin::constants::ChainHash;
14
14
use bitcoin::script::{Builder, Script, ScriptBuf, WScriptHash};
15
15
use bitcoin::sighash::EcdsaSighashType;
16
- use bitcoin::transaction::{Transaction, TxIn, TxOut};
16
+ use bitcoin::transaction::{Transaction, TxOut};
17
17
use bitcoin::{Weight, Witness};
18
18
19
19
use bitcoin::hash_types::{BlockHash, Txid};
@@ -24,9 +24,9 @@ use bitcoin::hashes::Hash;
24
24
use bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE;
25
25
use bitcoin::secp256k1::{ecdsa::Signature, Secp256k1};
26
26
use bitcoin::secp256k1::{PublicKey, SecretKey};
27
- #[cfg(splicing)]
28
- use bitcoin::Sequence;
29
27
use bitcoin::{secp256k1, sighash};
28
+ #[cfg(splicing)]
29
+ use bitcoin::{Sequence, TxIn};
30
30
31
31
use crate::chain::chaininterface::{
32
32
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
@@ -53,7 +53,7 @@ use crate::ln::channel_state::{
53
53
OutboundHTLCDetails, OutboundHTLCStateDetails,
54
54
};
55
55
use crate::ln::channelmanager::{
56
- self, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
56
+ self, FundingConfirmedMessage, FundingTxInput, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
57
57
PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus, RAACommitmentOrder, SentHTLCId,
58
58
BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
59
59
};
@@ -5915,10 +5915,11 @@ fn estimate_v2_funding_transaction_fee(
5915
5915
#[cfg(splicing)]
5916
5916
#[rustfmt::skip]
5917
5917
fn check_v2_funding_inputs_sufficient(
5918
- contribution_amount: i64, funding_inputs: &[(TxIn, Transaction, Weight) ], is_initiator: bool,
5918
+ contribution_amount: i64, funding_inputs: &[FundingTxInput ], is_initiator: bool,
5919
5919
is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
5920
5920
) -> Result<u64, ChannelError> {
5921
- let mut total_input_witness_weight = Weight::from_wu(funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
5921
+ let mut total_input_witness_weight =
5922
+ funding_inputs.iter().map(|FundingTxInput { witness_weight, .. }| witness_weight).sum();
5922
5923
let mut funding_inputs_len = funding_inputs.len();
5923
5924
if is_initiator && is_splice {
5924
5925
// consider the weight of the input and witness needed for spending the old funding transaction
@@ -5928,13 +5929,13 @@ fn check_v2_funding_inputs_sufficient(
5928
5929
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs_len, total_input_witness_weight, funding_feerate_sat_per_1000_weight);
5929
5930
5930
5931
let mut total_input_sats = 0u64;
5931
- for (idx, input ) in funding_inputs.iter().enumerate() {
5932
- if let Some(output) = input.1. output.get(input.0 .previous_output.vout as usize) {
5932
+ for (idx, FundingTxInput { txin, prevtx, .. } ) in funding_inputs.iter().enumerate() {
5933
+ if let Some(output) = prevtx. output.get(txin .previous_output.vout as usize) {
5933
5934
total_input_sats = total_input_sats.saturating_add(output.value.to_sat());
5934
5935
} else {
5935
5936
return Err(ChannelError::Warn(format!(
5936
5937
"Transaction with txid {} does not have an output with vout of {} corresponding to TxIn at funding_inputs[{}]",
5937
- input.1. compute_txid(), input.0 .previous_output.vout, idx
5938
+ prevtx. compute_txid(), txin .previous_output.vout, idx
5938
5939
)));
5939
5940
}
5940
5941
}
@@ -5978,7 +5979,7 @@ pub(super) struct FundingNegotiationContext {
5978
5979
pub shared_funding_input: Option<SharedOwnedInput>,
5979
5980
/// The funding inputs we will be contributing to the channel.
5980
5981
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
5981
- pub our_funding_inputs: Vec<(TxIn, Transaction, Weight) >,
5982
+ pub our_funding_inputs: Vec<FundingTxInput >,
5982
5983
/// The change output script. This will be used if needed or -- if not set -- generated using
5983
5984
/// `SignerProvider::get_destination_script`.
5984
5985
#[allow(dead_code)] // TODO(splicing): Remove once splicing is enabled.
@@ -6050,8 +6051,11 @@ impl FundingNegotiationContext {
6050
6051
}
6051
6052
}
6052
6053
6053
- let funding_inputs =
6054
- self.our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
6054
+ let funding_inputs = self
6055
+ .our_funding_inputs
6056
+ .into_iter()
6057
+ .map(|FundingTxInput { txin, prevtx, .. }| (txin, prevtx))
6058
+ .collect();
6055
6059
6056
6060
let constructor_args = InteractiveTxConstructorArgs {
6057
6061
entropy_source,
@@ -10604,9 +10608,8 @@ where
10604
10608
/// generated by `SignerProvider::get_destination_script`.
10605
10609
#[cfg(splicing)]
10606
10610
pub fn splice_channel(
10607
- &mut self, our_funding_contribution_satoshis: i64,
10608
- our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
10609
- funding_feerate_per_kw: u32, locktime: u32,
10611
+ &mut self, our_funding_contribution_satoshis: i64, our_funding_inputs: Vec<FundingTxInput>,
10612
+ change_script: Option<ScriptBuf>, funding_feerate_per_kw: u32, locktime: u32,
10610
10613
) -> Result<msgs::SpliceInit, APIError> {
10611
10614
// Check if a splice has been initiated already.
10612
10615
// Note: only a single outstanding splice is supported (per spec)
@@ -10672,7 +10675,7 @@ where
10672
10675
),
10673
10676
})?;
10674
10677
10675
- for ( txin, tx, _) in our_funding_inputs.iter() {
10678
+ for FundingTxInput { txin, prevtx, .. } in our_funding_inputs.iter() {
10676
10679
const MESSAGE_TEMPLATE: msgs::TxAddInput = msgs::TxAddInput {
10677
10680
channel_id: ChannelId([0; 32]),
10678
10681
serial_id: 0,
@@ -10681,7 +10684,7 @@ where
10681
10684
sequence: 0,
10682
10685
shared_input_txid: None,
10683
10686
};
10684
- let message_len = MESSAGE_TEMPLATE.serialized_length() + tx .serialized_length();
10687
+ let message_len = MESSAGE_TEMPLATE.serialized_length() + prevtx .serialized_length();
10685
10688
if message_len > LN_MAX_MSG_LEN {
10686
10689
return Err(APIError::APIMisuseError {
10687
10690
err: format!(
@@ -12468,7 +12471,7 @@ where
12468
12471
pub fn new_outbound<ES: Deref, F: Deref, L: Deref>(
12469
12472
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
12470
12473
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
12471
- funding_inputs: Vec<(TxIn, Transaction, Weight) >, user_id: u128, config: &UserConfig,
12474
+ funding_inputs: Vec<FundingTxInput >, user_id: u128, config: &UserConfig,
12472
12475
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
12473
12476
logger: L,
12474
12477
) -> Result<Self, APIError>
@@ -12682,8 +12685,10 @@ where
12682
12685
value: Amount::from_sat(funding.get_value_satoshis()),
12683
12686
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
12684
12687
};
12685
- let inputs_to_contribute =
12686
- our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
12688
+ let inputs_to_contribute = our_funding_inputs
12689
+ .into_iter()
12690
+ .map(|FundingTxInput { txin, prevtx, .. }| (txin, prevtx))
12691
+ .collect();
12687
12692
12688
12693
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
12689
12694
InteractiveTxConstructorArgs {
@@ -14119,6 +14124,8 @@ mod tests {
14119
14124
TOTAL_BITCOIN_SUPPLY_SATOSHIS,
14120
14125
};
14121
14126
use crate::ln::channel_keys::{RevocationBasepoint, RevocationKey};
14127
+ #[cfg(splicing)]
14128
+ use crate::ln::channelmanager::FundingTxInput;
14122
14129
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
14123
14130
use crate::ln::msgs;
14124
14131
use crate::ln::msgs::{ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
@@ -14155,7 +14162,7 @@ mod tests {
14155
14162
use bitcoin::transaction::TxIn;
14156
14163
use bitcoin::transaction::{Transaction, TxOut, Version};
14157
14164
#[cfg(splicing)]
14158
- use bitcoin::Weight;
14165
+ use bitcoin::{ScriptBuf, Weight} ;
14159
14166
use bitcoin::{WitnessProgram, WitnessVersion};
14160
14167
use std::cmp;
14161
14168
@@ -15897,19 +15904,21 @@ mod tests {
15897
15904
15898
15905
#[cfg(splicing)]
15899
15906
#[rustfmt::skip]
15900
- fn funding_input_sats(input_value_sats: u64) -> (TxIn, Transaction, Weight) {
15907
+ fn funding_input_sats(input_value_sats: u64) -> FundingTxInput {
15901
15908
use crate::sign::P2WPKH_WITNESS_WEIGHT;
15902
15909
15903
- let input_1_prev_out = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: bitcoin:: ScriptBuf::default() };
15904
- let input_1_prev_tx = Transaction {
15905
- input: vec![], output: vec![input_1_prev_out ],
15910
+ let prevout = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: ScriptBuf::default() };
15911
+ let prevtx = Transaction {
15912
+ input: vec![], output: vec![prevout ],
15906
15913
version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
15907
15914
};
15908
- let input_1_txin = TxIn {
15909
- previous_output: bitcoin::OutPoint { txid: input_1_prev_tx .compute_txid(), vout: 0 },
15915
+ let txin = TxIn {
15916
+ previous_output: bitcoin::OutPoint { txid: prevtx .compute_txid(), vout: 0 },
15910
15917
..Default::default()
15911
15918
};
15912
- (input_1_txin, input_1_prev_tx, Weight::from_wu(P2WPKH_WITNESS_WEIGHT))
15919
+ let witness_weight = Weight::from_wu(P2WPKH_WITNESS_WEIGHT);
15920
+
15921
+ FundingTxInput { txin, prevtx, witness_weight }
15913
15922
}
15914
15923
15915
15924
#[cfg(splicing)]
0 commit comments