Skip to content

Commit df06bb1

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 4ddb7a5 commit df06bb1

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
@@ -6024,7 +6024,9 @@ impl FundingNegotiationContext {
60246024
};
60256025

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

60306032
// Add change output if necessary
@@ -6078,7 +6080,7 @@ pub enum FundingTxContributions {
60786080
InputsOnly {
60796081
/// The inputs used to meet the contributed amount. Any excess amount will be sent to a
60806082
/// change output.
6081-
inputs: Vec<(TxIn, Transaction)>,
6083+
inputs: Vec<(TxIn, Transaction, Weight)>,
60826084

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

60896091
impl FundingTxContributions {
60906092
/// Returns an inputs to be contributed to the funding transaction.
6091-
pub fn inputs(&self) -> &[(TxIn, Transaction)] {
6093+
pub fn inputs(&self) -> &[(TxIn, Transaction, Weight)] {
60926094
match self {
60936095
FundingTxContributions::InputsOnly { inputs, .. } => &inputs[..],
60946096
}
@@ -10700,9 +10702,8 @@ where
1070010702
err,
1070110703
),
1070210704
})?;
10703-
// Convert inputs
10704-
let mut funding_inputs = Vec::new();
10705-
for (txin, tx, _) in our_funding_inputs.into_iter() {
10705+
10706+
for (_, tx, _) in our_funding_inputs.iter() {
1070610707
const MESSAGE_TEMPLATE: msgs::TxAddInput = msgs::TxAddInput {
1070710708
channel_id: ChannelId([0; 32]),
1070810709
serial_id: 0,
@@ -10717,12 +10718,10 @@ where
1071710718
err: format!("Funding input's prevtx is too large for tx_add_input"),
1071810719
});
1071910720
}
10720-
10721-
funding_inputs.push((txin, tx));
1072210721
}
1072310722

1072410723
let funding_tx_contributions =
10725-
FundingTxContributions::InputsOnly { inputs: funding_inputs, change_script };
10724+
FundingTxContributions::InputsOnly { inputs: our_funding_inputs, change_script };
1072610725

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

1266512664
let channel_value_satoshis =
1266612665
our_funding_contribution_sats.saturating_add(msg.common_fields.funding_satoshis);
@@ -12729,7 +12728,7 @@ where
1272912728
feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
1273012729
funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
1273112730
is_initiator: false,
12732-
inputs_to_contribute: our_funding_inputs,
12731+
inputs_to_contribute: our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect(),
1273312732
shared_funding_input: None,
1273412733
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
1273512734
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)