Skip to content

Commit 283e3c6

Browse files
committed
Include prevtx weight in FundingTxContributions::InputsOnly
In preparation for having ChannelManager::splice_channel take FundingTxContributions, add a weight to the FundingTxContributions::InputsOnly, which supports the splice-in use case.
1 parent 1f4ce55 commit 283e3c6

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6025,7 +6025,9 @@ impl FundingNegotiationContext {
60256025
};
60266026

60276027
let (inputs_to_contribute, change_script) = match self.funding_tx_contributions {
6028-
FundingTxContributions::InputsOnly { inputs, change_script } => (inputs, change_script),
6028+
FundingTxContributions::InputsOnly { inputs, change_script } => {
6029+
(inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect(), change_script)
6030+
},
60296031
};
60306032

60316033
// Add change output if necessary
@@ -6079,7 +6081,7 @@ pub enum FundingTxContributions {
60796081
InputsOnly {
60806082
/// The inputs used to meet the contributed amount. Any excess amount will be sent to a
60816083
/// change output.
6082-
inputs: Vec<(TxIn, Transaction)>,
6084+
inputs: Vec<(TxIn, Transaction, Weight)>,
60836085

60846086
/// An optional change output script. This will be used if needed or, if not set, generated
60856087
/// using `SignerProvider::get_destination_script`.
@@ -6089,7 +6091,7 @@ pub enum FundingTxContributions {
60896091

60906092
impl FundingTxContributions {
60916093
/// Returns an inputs to be contributed to the funding transaction.
6092-
pub fn inputs(&self) -> &[(TxIn, Transaction)] {
6094+
pub fn inputs(&self) -> &[(TxIn, Transaction, Weight)] {
60936095
match self {
60946096
FundingTxContributions::InputsOnly { inputs, .. } => &inputs[..],
60956097
}
@@ -10701,9 +10703,8 @@ where
1070110703
err,
1070210704
),
1070310705
})?;
10704-
// Convert inputs
10705-
let mut funding_inputs = Vec::new();
10706-
for (txin, tx, _) in our_funding_inputs.into_iter() {
10706+
10707+
for (_, tx, _) in our_funding_inputs.iter() {
1070710708
const MESSAGE_TEMPLATE: msgs::TxAddInput = msgs::TxAddInput {
1070810709
channel_id: ChannelId([0; 32]),
1070910710
serial_id: 0,
@@ -10718,12 +10719,10 @@ where
1071810719
err: format!("Funding input's prevtx is too large for tx_add_input"),
1071910720
});
1072010721
}
10721-
10722-
funding_inputs.push((txin, tx));
1072310722
}
1072410723

1072510724
let funding_tx_contributions =
10726-
FundingTxContributions::InputsOnly { inputs: funding_inputs, change_script };
10725+
FundingTxContributions::InputsOnly { inputs: our_funding_inputs, change_script };
1072710726

1072810727
let prev_funding_input = self.funding.to_splice_funding_input();
1072910728
let funding_negotiation_context = FundingNegotiationContext {
@@ -12500,7 +12499,7 @@ where
1250012499
pub fn new_outbound<ES: Deref, F: Deref, L: Deref>(
1250112500
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
1250212501
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
12503-
funding_inputs: Vec<(TxIn, Transaction)>, user_id: u128, config: &UserConfig,
12502+
funding_inputs: Vec<(TxIn, Transaction, Weight)>, user_id: u128, config: &UserConfig,
1250412503
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
1250512504
logger: L,
1250612505
) -> Result<Self, APIError>
@@ -12661,7 +12660,7 @@ where
1266112660
{
1266212661
// TODO(dual_funding): Take these as input once supported
1266312662
let (our_funding_contribution, our_funding_contribution_sats) = (SignedAmount::ZERO, 0u64);
12664-
let our_funding_inputs = Vec::new();
12663+
let our_funding_inputs: Vec<(TxIn, Transaction, Weight)> = Vec::new();
1266512664

1266612665
let channel_value_satoshis =
1266712666
our_funding_contribution_sats.saturating_add(msg.common_fields.funding_satoshis);
@@ -12730,7 +12729,7 @@ where
1273012729
feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
1273112730
funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
1273212731
is_initiator: false,
12733-
inputs_to_contribute: our_funding_inputs,
12732+
inputs_to_contribute: our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect(),
1273412733
shared_funding_input: None,
1273512734
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
1273612735
outputs_to_contribute: Vec::new(),

lightning/src/ln/dual_funding_tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
4848
let initiator_funding_inputs: Vec<_> = create_dual_funding_utxos_with_prev_txs(
4949
&nodes[0],
5050
&[session.initiator_input_value_satoshis],
51-
)
52-
.into_iter()
53-
.map(|(txin, tx, _)| (txin, tx))
54-
.collect();
51+
);
5552

5653
// Alice creates a dual-funded channel as initiator.
5754
let funding_satoshis = session.funding_input_sats;

lightning/src/ln/interactivetxs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ pub(super) fn calculate_change_output_value(
18841884

18851885
let mut total_input_satoshis = 0u64;
18861886
let mut our_funding_inputs_weight = 0u64;
1887-
for (txin, tx) in context.funding_tx_contributions.inputs().iter() {
1887+
for (txin, tx, _) in context.funding_tx_contributions.inputs().iter() {
18881888
let txid = tx.compute_txid();
18891889
if txin.previous_output.txid != txid {
18901890
return Err(AbortReason::PrevTxOutInvalid);
@@ -1894,6 +1894,7 @@ pub(super) fn calculate_change_output_value(
18941894
.get(txin.previous_output.vout as usize)
18951895
.ok_or(AbortReason::PrevTxOutInvalid)?;
18961896
total_input_satoshis = total_input_satoshis.saturating_add(output.value.to_sat());
1897+
// FIXME: Can we use the Weight from context.funding_tx_contributions.inputs()?
18971898
let weight = estimate_input_weight(output).to_wu();
18981899
our_funding_inputs_weight = our_funding_inputs_weight.saturating_add(weight);
18991900
}
@@ -1958,7 +1959,7 @@ mod tests {
19581959
use bitcoin::transaction::Version;
19591960
use bitcoin::{
19601961
OutPoint, PubkeyHash, ScriptBuf, Sequence, SignedAmount, Transaction, TxIn, TxOut,
1961-
WPubkeyHash, Witness,
1962+
WPubkeyHash, Weight, Witness,
19621963
};
19631964
use core::ops::Deref;
19641965

@@ -2969,9 +2970,10 @@ mod tests {
29692970
sequence: Sequence::ZERO,
29702971
witness: Witness::new(),
29712972
};
2972-
(txin, tx)
2973+
let weight = Weight::ZERO;
2974+
(txin, tx, weight)
29732975
})
2974-
.collect::<Vec<(TxIn, Transaction)>>();
2976+
.collect::<Vec<(TxIn, Transaction, Weight)>>();
29752977
let funding_tx_contributions =
29762978
FundingTxContributions::InputsOnly { inputs, change_script: None };
29772979
let our_contributed = 110_000;

0 commit comments

Comments
 (0)