@@ -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!(
@@ -12466,7 +12469,7 @@ where
12466
12469
pub fn new_outbound<ES: Deref, F: Deref, L: Deref>(
12467
12470
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
12468
12471
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
12469
- funding_inputs: Vec<(TxIn, Transaction, Weight) >, user_id: u128, config: &UserConfig,
12472
+ funding_inputs: Vec<FundingTxInput >, user_id: u128, config: &UserConfig,
12470
12473
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
12471
12474
logger: L,
12472
12475
) -> Result<Self, APIError>
@@ -12680,8 +12683,10 @@ where
12680
12683
value: Amount::from_sat(funding.get_value_satoshis()),
12681
12684
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
12682
12685
};
12683
- let inputs_to_contribute =
12684
- our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
12686
+ let inputs_to_contribute = our_funding_inputs
12687
+ .into_iter()
12688
+ .map(|FundingTxInput { txin, prevtx, .. }| (txin, prevtx))
12689
+ .collect();
12685
12690
12686
12691
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
12687
12692
InteractiveTxConstructorArgs {
@@ -14117,6 +14122,8 @@ mod tests {
14117
14122
TOTAL_BITCOIN_SUPPLY_SATOSHIS,
14118
14123
};
14119
14124
use crate::ln::channel_keys::{RevocationBasepoint, RevocationKey};
14125
+ #[cfg(splicing)]
14126
+ use crate::ln::channelmanager::FundingTxInput;
14120
14127
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
14121
14128
use crate::ln::msgs;
14122
14129
use crate::ln::msgs::{ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
@@ -14153,7 +14160,7 @@ mod tests {
14153
14160
use bitcoin::transaction::TxIn;
14154
14161
use bitcoin::transaction::{Transaction, TxOut, Version};
14155
14162
#[cfg(splicing)]
14156
- use bitcoin::Weight;
14163
+ use bitcoin::{ScriptBuf, Weight} ;
14157
14164
use bitcoin::{WitnessProgram, WitnessVersion};
14158
14165
use std::cmp;
14159
14166
@@ -15895,19 +15902,21 @@ mod tests {
15895
15902
15896
15903
#[cfg(splicing)]
15897
15904
#[rustfmt::skip]
15898
- fn funding_input_sats(input_value_sats: u64) -> (TxIn, Transaction, Weight) {
15905
+ fn funding_input_sats(input_value_sats: u64) -> FundingTxInput {
15899
15906
use crate::sign::P2WPKH_WITNESS_WEIGHT;
15900
15907
15901
- let input_1_prev_out = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: bitcoin:: ScriptBuf::default() };
15902
- let input_1_prev_tx = Transaction {
15903
- input: vec![], output: vec![input_1_prev_out ],
15908
+ let prevout = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: ScriptBuf::default() };
15909
+ let prevtx = Transaction {
15910
+ input: vec![], output: vec![prevout ],
15904
15911
version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
15905
15912
};
15906
- let input_1_txin = TxIn {
15907
- previous_output: bitcoin::OutPoint { txid: input_1_prev_tx .compute_txid(), vout: 0 },
15913
+ let txin = TxIn {
15914
+ previous_output: bitcoin::OutPoint { txid: prevtx .compute_txid(), vout: 0 },
15908
15915
..Default::default()
15909
15916
};
15910
- (input_1_txin, input_1_prev_tx, Weight::from_wu(P2WPKH_WITNESS_WEIGHT))
15917
+ let witness_weight = Weight::from_wu(P2WPKH_WITNESS_WEIGHT);
15918
+
15919
+ FundingTxInput { txin, prevtx, witness_weight }
15911
15920
}
15912
15921
15913
15922
#[cfg(splicing)]
0 commit comments