Skip to content

Commit 5a84daf

Browse files
authored
Merge pull request #4097 from jkczyz/2025-09-interactive-tx-refactor
Refactor `ConstructedTransaction` to contain `Transaction`
2 parents 334a70c + 86ed012 commit 5a84daf

File tree

5 files changed

+282
-348
lines changed

5 files changed

+282
-348
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6059,8 +6059,8 @@ where
60596059
{
60606060
let mut output_index = None;
60616061
let expected_spk = funding.get_funding_redeemscript().to_p2wsh();
6062-
for (idx, outp) in signing_session.unsigned_tx().outputs().enumerate() {
6063-
if outp.script_pubkey() == &expected_spk && outp.value() == funding.get_value_satoshis() {
6062+
for (idx, outp) in signing_session.unsigned_tx().tx().output.iter().enumerate() {
6063+
if outp.script_pubkey == expected_spk && outp.value.to_sat() == funding.get_value_satoshis() {
60646064
if output_index.is_some() {
60656065
return Err(AbortReason::DuplicateFundingOutput);
60666066
}
@@ -6566,14 +6566,6 @@ impl FundingNegotiationContext {
65666566
}
65676567
}
65686568

6569-
let funding_inputs = self
6570-
.our_funding_inputs
6571-
.into_iter()
6572-
.map(|FundingTxInput { utxo, sequence, prevtx }| {
6573-
(TxIn { previous_output: utxo.outpoint, sequence, ..Default::default() }, prevtx)
6574-
})
6575-
.collect();
6576-
65776569
let constructor_args = InteractiveTxConstructorArgs {
65786570
entropy_source,
65796571
holder_node_id,
@@ -6582,7 +6574,7 @@ impl FundingNegotiationContext {
65826574
feerate_sat_per_kw: self.funding_feerate_sat_per_1000_weight,
65836575
is_initiator: self.is_initiator,
65846576
funding_tx_locktime: self.funding_tx_locktime,
6585-
inputs_to_contribute: funding_inputs,
6577+
inputs_to_contribute: self.our_funding_inputs,
65866578
shared_funding_input: self.shared_funding_input,
65876579
shared_funding_output: SharedOwnedOutput::new(
65886580
shared_funding_output,
@@ -8617,7 +8609,7 @@ where
86178609
return Err(APIError::APIMisuseError { err });
86188610
};
86198611

8620-
let tx = signing_session.unsigned_tx().build_unsigned_tx();
8612+
let tx = signing_session.unsigned_tx().tx();
86218613
if funding_txid_signed != tx.compute_txid() {
86228614
return Err(APIError::APIMisuseError {
86238615
err: "Transaction was malleated prior to signing".to_owned(),
@@ -8629,7 +8621,7 @@ where
86298621
let sig = match &self.context.holder_signer {
86308622
ChannelSignerType::Ecdsa(signer) => signer.sign_splice_shared_input(
86318623
&self.funding.channel_transaction_parameters,
8632-
&tx,
8624+
tx,
86338625
splice_input_index as usize,
86348626
&self.context.secp_ctx,
86358627
),
@@ -13649,12 +13641,6 @@ where
1364913641
value: Amount::from_sat(funding.get_value_satoshis()),
1365013642
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
1365113643
};
13652-
let inputs_to_contribute = our_funding_inputs
13653-
.into_iter()
13654-
.map(|FundingTxInput { utxo, sequence, prevtx }| {
13655-
(TxIn { previous_output: utxo.outpoint, sequence, ..Default::default() }, prevtx)
13656-
})
13657-
.collect();
1365813644

1365913645
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1366013646
InteractiveTxConstructorArgs {
@@ -13665,7 +13651,7 @@ where
1366513651
feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
1366613652
funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
1366713653
is_initiator: false,
13668-
inputs_to_contribute,
13654+
inputs_to_contribute: our_funding_inputs,
1366913655
shared_funding_input: None,
1367013656
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
1367113657
outputs_to_contribute: funding_negotiation_context.our_funding_outputs.clone(),

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9338,7 +9338,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
93389338
{
93399339
if signing_session.has_local_contribution() {
93409340
let mut pending_events = self.pending_events.lock().unwrap();
9341-
let unsigned_transaction = signing_session.unsigned_tx().build_unsigned_tx();
9341+
let unsigned_transaction = signing_session.unsigned_tx().tx().clone();
93429342
let event_action = (
93439343
Event::FundingTransactionReadyForSigning {
93449344
unsigned_transaction,

lightning/src/ln/funding.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ impl FundingTxInput {
199199
FundingTxInput::new(prevtx, vout, witness_weight, Script::is_p2tr)
200200
}
201201

202+
#[cfg(test)]
203+
pub(crate) fn new_p2pkh(prevtx: Transaction, vout: u32) -> Result<Self, ()> {
204+
FundingTxInput::new(prevtx, vout, Weight::ZERO, Script::is_p2pkh)
205+
}
206+
202207
/// The sequence number to use in the [`TxIn`].
203208
///
204209
/// [`TxIn`]: bitcoin::TxIn

0 commit comments

Comments
 (0)