-
Notifications
You must be signed in to change notification settings - Fork 421
Refactor interactive-tx construction and uses #4123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor interactive-tx construction and uses #4123
Conversation
An upcoming commit will include the contributed inputs and outputs in an error whenever ConstructedTransaction::new fails. In order to DRY up that logic, this commit updates the constructor to create the resulting object prior to performing any checks. This way a conversion method can be added that extracts the necessary input and output data.
Both NegotiationContext::validate_tx and ConstructedTransaction::new contain validity checks. Move the former into the latter in order to consolidate the checks in a single place. This will also allow for reusing error construction in an upcoming commit.
👋 Thanks for assigning @wpaulino as a reviewer! |
a7638af
to
59f7deb
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4123 +/- ##
==========================================
+ Coverage 88.50% 88.59% +0.08%
==========================================
Files 179 180 +1
Lines 134270 134977 +707
Branches 134270 134977 +707
==========================================
+ Hits 118837 119584 +747
+ Misses 12682 12631 -51
- Partials 2751 2762 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
lightning/src/ln/channel.rs
Outdated
None => Err(AbortReason::InternalError( | ||
"Received unexpected interactive transaction negotiation message", | ||
)), | ||
None => Err(NegotiationError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relevant for the follow-up PR: we should be careful to not emit a SpliceFailed
event here. We probably only should when pending_splice.is_some()
.
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
Instead of popping each input and output to contribute during an interactive tx session, clone the necessary parts and keep around the original inputs and outputs. This will let us reuse them later when constructing an error. The tradeoff is using additional memory to avoid more code complexity required to extract the sent input and outputs from NegotiationContext.
Currently, only the shared input index is stored in ConstructedTransaction. This will be used later to filter out the shared input when constructing an error during interactive tx negotiation. Store the shared output index as well so that the shared output can be filtered out as well.
The number of inputs allowed during an interactive-tx construction session is limited to 4096, so a u16 can be used instead of u32 when serializing ConstructedTransaction.
59f7deb
to
18d3bd7
Compare
InteractiveTxConstructor contains the users contributed inputs. When an interactive tx sessions is aborted, the user will need to be notified with an event indicating which inputs and outputs were contributed. This allows them to re-use inputs that are no longer in use. This commit ensures the InteractiveTxConstructor is only consumed after all error checking. That way, in the case of a failure, we're able to produce an event from its input data.
18d3bd7
to
0956efd
Compare
NegotiationError
for interactive-tx constructions
Interactive transaction construction currently fails with an
AbortReason
. However, in order to produceSpliceFailed
events in #4077, the contributed inputs and outputs need to be accessible. That is, they cannot be consumed if returning an error. This PR refactors interactive-tx construction code and uses to avoid consumingInteractiveTxConstruction
until all error checking has completed.