@@ -52,7 +52,7 @@ use crate::ln::channel_state::{
52
52
OutboundHTLCDetails, OutboundHTLCStateDetails,
53
53
};
54
54
use crate::ln::channelmanager::{
55
- self, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
55
+ self, FundingConfirmedMessage, FundingTxInput, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
56
56
PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus, RAACommitmentOrder, SentHTLCId,
57
57
BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
58
58
};
@@ -5914,10 +5914,11 @@ fn estimate_v2_funding_transaction_fee(
5914
5914
#[cfg(splicing)]
5915
5915
#[rustfmt::skip]
5916
5916
fn check_v2_funding_inputs_sufficient(
5917
- contribution_amount: i64, funding_inputs: &[(TxIn, Transaction, Weight) ], is_initiator: bool,
5917
+ contribution_amount: i64, funding_inputs: &[FundingTxInput ], is_initiator: bool,
5918
5918
is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
5919
5919
) -> Result<u64, ChannelError> {
5920
- let mut total_input_witness_weight = Weight::from_wu(funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
5920
+ let mut total_input_witness_weight =
5921
+ funding_inputs.iter().map(|FundingTxInput { witness_weight, .. }| witness_weight).sum();
5921
5922
let mut funding_inputs_len = funding_inputs.len();
5922
5923
if is_initiator && is_splice {
5923
5924
// consider the weight of the input and witness needed for spending the old funding transaction
@@ -5927,13 +5928,13 @@ fn check_v2_funding_inputs_sufficient(
5927
5928
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs_len, total_input_witness_weight, funding_feerate_sat_per_1000_weight);
5928
5929
5929
5930
let mut total_input_sats = 0u64;
5930
- for (idx, input ) in funding_inputs.iter().enumerate() {
5931
- if let Some(output) = input.1. output.get(input.0 .previous_output.vout as usize) {
5931
+ for (idx, FundingTxInput { txin, prevtx, .. } ) in funding_inputs.iter().enumerate() {
5932
+ if let Some(output) = prevtx. output.get(txin .previous_output.vout as usize) {
5932
5933
total_input_sats = total_input_sats.saturating_add(output.value.to_sat());
5933
5934
} else {
5934
5935
return Err(ChannelError::Warn(format!(
5935
5936
"Transaction with txid {} does not have an output with vout of {} corresponding to TxIn at funding_inputs[{}]",
5936
- input.1. compute_txid(), input.0 .previous_output.vout, idx
5937
+ prevtx. compute_txid(), txin .previous_output.vout, idx
5937
5938
)));
5938
5939
}
5939
5940
}
@@ -5977,7 +5978,7 @@ pub(super) struct FundingNegotiationContext {
5977
5978
pub shared_funding_input: Option<SharedOwnedInput>,
5978
5979
/// The funding inputs we will be contributing to the channel.
5979
5980
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
5980
- pub our_funding_inputs: Vec<(TxIn, Transaction, Weight) >,
5981
+ pub our_funding_inputs: Vec<FundingTxInput >,
5981
5982
/// The change output script. This will be used if needed or -- if not set -- generated using
5982
5983
/// `SignerProvider::get_destination_script`.
5983
5984
#[allow(dead_code)] // TODO(splicing): Remove once splicing is enabled.
@@ -6049,8 +6050,11 @@ impl FundingNegotiationContext {
6049
6050
}
6050
6051
}
6051
6052
6052
- let funding_inputs =
6053
- self.our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
6053
+ let funding_inputs = self
6054
+ .our_funding_inputs
6055
+ .into_iter()
6056
+ .map(|FundingTxInput { txin, prevtx, .. }| (txin, prevtx))
6057
+ .collect();
6054
6058
6055
6059
let constructor_args = InteractiveTxConstructorArgs {
6056
6060
entropy_source,
@@ -10610,9 +10614,8 @@ where
10610
10614
/// generated by `SignerProvider::get_destination_script`.
10611
10615
#[cfg(splicing)]
10612
10616
pub fn splice_channel(
10613
- &mut self, our_funding_contribution_satoshis: i64,
10614
- our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
10615
- funding_feerate_per_kw: u32, locktime: u32,
10617
+ &mut self, our_funding_contribution_satoshis: i64, our_funding_inputs: Vec<FundingTxInput>,
10618
+ change_script: Option<ScriptBuf>, funding_feerate_per_kw: u32, locktime: u32,
10616
10619
) -> Result<msgs::SpliceInit, APIError> {
10617
10620
// Check if a splice has been initiated already.
10618
10621
// Note: only a single outstanding splice is supported (per spec)
@@ -10678,7 +10681,7 @@ where
10678
10681
),
10679
10682
})?;
10680
10683
10681
- for (_, tx, _) in our_funding_inputs.iter() {
10684
+ for FundingTxInput { txin, prevtx, .. } in our_funding_inputs.iter() {
10682
10685
const MESSAGE_TEMPLATE: msgs::TxAddInput = msgs::TxAddInput {
10683
10686
channel_id: ChannelId([0; 32]),
10684
10687
serial_id: 0,
@@ -10687,7 +10690,7 @@ where
10687
10690
sequence: 0,
10688
10691
shared_input_txid: None,
10689
10692
};
10690
- let message_len = MESSAGE_TEMPLATE.serialized_length() + tx .serialized_length();
10693
+ let message_len = MESSAGE_TEMPLATE.serialized_length() + prevtx .serialized_length();
10691
10694
if message_len > LN_MAX_MSG_LEN {
10692
10695
return Err(APIError::APIMisuseError {
10693
10696
err: format!(
@@ -12472,7 +12475,7 @@ where
12472
12475
pub fn new_outbound<ES: Deref, F: Deref, L: Deref>(
12473
12476
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
12474
12477
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
12475
- funding_inputs: Vec<(TxIn, Transaction, Weight) >, user_id: u128, config: &UserConfig,
12478
+ funding_inputs: Vec<FundingTxInput >, user_id: u128, config: &UserConfig,
12476
12479
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
12477
12480
logger: L,
12478
12481
) -> Result<Self, APIError>
@@ -12686,8 +12689,10 @@ where
12686
12689
value: Amount::from_sat(funding.get_value_satoshis()),
12687
12690
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
12688
12691
};
12689
- let inputs_to_contribute =
12690
- our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
12692
+ let inputs_to_contribute = our_funding_inputs
12693
+ .into_iter()
12694
+ .map(|FundingTxInput { txin, prevtx, .. }| (txin, prevtx))
12695
+ .collect();
12691
12696
12692
12697
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
12693
12698
InteractiveTxConstructorArgs {
@@ -14123,7 +14128,7 @@ mod tests {
14123
14128
TOTAL_BITCOIN_SUPPLY_SATOSHIS,
14124
14129
};
14125
14130
use crate::ln::channel_keys::{RevocationBasepoint, RevocationKey};
14126
- use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
14131
+ use crate::ln::channelmanager::{self, FundingTxInput, HTLCSource, PaymentId};
14127
14132
use crate::ln::msgs;
14128
14133
use crate::ln::msgs::{ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
14129
14134
use crate::ln::onion_utils::{AttributionData, LocalHTLCFailureReason};
@@ -15896,19 +15901,21 @@ mod tests {
15896
15901
15897
15902
#[cfg(splicing)]
15898
15903
#[rustfmt::skip]
15899
- fn funding_input_sats(input_value_sats: u64) -> (TxIn, Transaction, Weight) {
15904
+ fn funding_input_sats(input_value_sats: u64) -> FundingTxInput {
15900
15905
use crate::sign::P2WPKH_WITNESS_WEIGHT;
15901
15906
15902
- let input_1_prev_out = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: ScriptBuf::default() };
15903
- let input_1_prev_tx = Transaction {
15904
- input: vec![], output: vec![input_1_prev_out ],
15907
+ let prevout = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: ScriptBuf::default() };
15908
+ let prevtx = Transaction {
15909
+ input: vec![], output: vec![prevout ],
15905
15910
version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
15906
15911
};
15907
- let input_1_txin = TxIn {
15908
- previous_output: bitcoin::OutPoint { txid: input_1_prev_tx .compute_txid(), vout: 0 },
15912
+ let txin = TxIn {
15913
+ previous_output: bitcoin::OutPoint { txid: prevtx .compute_txid(), vout: 0 },
15909
15914
..Default::default()
15910
15915
};
15911
- (input_1_txin, input_1_prev_tx, Weight::from_wu(P2WPKH_WITNESS_WEIGHT))
15916
+ let witness_weight = Weight::from_wu(P2WPKH_WITNESS_WEIGHT);
15917
+
15918
+ FundingTxInput { txin, prevtx, witness_weight }
15912
15919
}
15913
15920
15914
15921
#[cfg(splicing)]
0 commit comments