Skip to content

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Sep 19, 2025

ConstructedTransaction tracks the result of the InteractiveTxConstruction and is used during an InteractiveTxSigningSession. This PR refactors it such that it holds an actual Transaction rather than the contributed parts, though some metadata in the form of NegotiatedTxInput and NegotiatedTxOutput need to be maintained.

This allows us to re-use the weight calculation provided by Transaction. It also facilitates reconstructing contributed inputs and outputs to produce a SpliceFailed event in #4077.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Sep 19, 2025

👋 Thanks for assigning @wpaulino as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@jkczyz jkczyz requested a review from wpaulino September 19, 2025 19:26
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 96.26866% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.61%. Comparing base (3564646) to head (9eeaf52).
⚠️ Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 66.66% 2 Missing ⚠️
lightning/src/ln/interactivetxs.rs 98.38% 2 Missing ⚠️
lightning/src/ln/channelmanager.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4097      +/-   ##
==========================================
+ Coverage   87.81%   88.61%   +0.79%     
==========================================
  Files         176      176              
  Lines      131770   132071     +301     
  Branches   131770   132071     +301     
==========================================
+ Hits       115719   117037    +1318     
+ Misses      13416    12356    -1060     
- Partials     2635     2678      +43     
Flag Coverage Δ
fuzzing 21.56% <0.00%> (-0.04%) ⬇️
tests 88.45% <96.26%> (+0.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 350 to 378
fn add_local_witnesses(&mut self, witnesses: Vec<Witness>) {
self.inputs
self.tx
.input
.iter_mut()
.zip(self.inputs.iter())
.enumerate()
.filter(|(_, input)| input.is_local(self.holder_is_initiator))
.filter(|(_, (_, input))| input.is_local(self.holder_is_initiator))
.filter(|(index, _)| {
self.shared_input_index
.map(|shared_index| *index != shared_index as usize)
.unwrap_or(true)
})
.map(|(_, input)| &mut input.txin)
.map(|(_, (txin, _))| txin)
.zip(witnesses)
.for_each(|(input, witness)| input.witness = witness);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should have InteractiveTxSigningSession store both local and remote signatures until finalize_funding_tx is called. That way, ConstructedTransaction would always contain an unsigned transaction instead of one that may be partially signed.

InteractiveTxConstructor::new converts inputs given in channel.rs to
InputOwned. Instead of converting FundingTxInput in channel.rs to the
type needed by that constructor, pass in FundingTxInput and have it
converted directly to InputOwned there. This saves one conversion and
Vec allocation. It also lets us use the satisfaction_weight in an
upcoming refactor.
Instead of estimating the input weight, track the satisfaction_weight in
InteractiveTxInput. This then can be used compute the transaction weight
without storing individual weights in NegotiatedTxInput in an upcoming
commit.
The weight is no longer needed once a ConstructedTransaction is created,
so it doesn't need to be persisted.
Instead of defining a custom function for calculating a transaction's
weight, have ConstructedTransaction hold a Transaction so that its
weight method can be re-used. As a result NegotiatedTxInput no longer
needs to store the transaction inputs.
Now that ConstructedTransaction holds the actual Transaction, there's no
need to keep track of and persist the outputs separately. However, the
serial IDs are still needed to later reconstruct which outputs were
contributed.
@jkczyz jkczyz force-pushed the 2025-09-interactive-tx-refactor branch from f96f304 to 9eeaf52 Compare September 19, 2025 20:05
@jkczyz
Copy link
Contributor Author

jkczyz commented Sep 19, 2025

Pushed rustfmt fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants