-
Notifications
You must be signed in to change notification settings - Fork 401
Remove exclusive reference and generic from CommitmentTransaction
API
#3689
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
base: main
Are you sure you want to change the base?
Conversation
tankyleo
commented
Mar 29, 2025
•
edited
Loading
edited
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
1cc3c50
to
fd57c35
Compare
CommitmentTransaction
API
fd57c35
to
ecc7dcf
Compare
CommitmentTransaction
APICommitmentTransaction
API
CommitmentTransaction
APICommitmentTransaction
API
c8a753e
to
b04cc76
Compare
CommitmentTransaction
APICommitmentTransaction
API
f4a3cc3
to
acad6d8
Compare
acad6d8
to
c86b528
Compare
c86b528
to
fcdacc9
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3689 +/- ##
==========================================
+ Coverage 89.07% 89.21% +0.13%
==========================================
Files 156 156
Lines 123507 124130 +623
Branches 123507 124130 +623
==========================================
+ Hits 110017 110742 +725
+ Misses 10801 10724 -77
+ Partials 2689 2664 -25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
One last real comment
fcdacc9
to
7e3a4e1
Compare
1d7a1d8
to
262351c
Compare
262351c
to
6ba5280
Compare
🔔 1st Reminder Hey @TheBlueMatt @wpaulino! This PR has been waiting for your review. |
1 similar comment
🔔 1st Reminder Hey @TheBlueMatt @wpaulino! This PR has been waiting for your review. |
@TheBlueMatt In this last commit here I delete the |
f021734
to
1621c12
Compare
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.
New commit basically LTGM.
1621c12
to
258b277
Compare
258b277
to
ee42e2a
Compare
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.
Basically LGTM, Probably needs another look from @wpaulino otherwise I'm happy.
lightning/src/ln/chan_utils.rs
Outdated
/// | ||
/// This is not exported to bindings users due to the generic though we likely should expose a version without | ||
pub fn new_with_auxiliary_htlc_data<T>(commitment_number: u64, per_commitment_point: &PublicKey, to_broadcaster_value_sat: u64, to_countersignatory_value_sat: u64, feerate_per_kw: u32, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, channel_parameters: &DirectedChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>) -> CommitmentTransaction { | ||
/// All HTLCs MUST be above the dust limit for the channel.\ |
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.
stray , I think? note that if you dont leave an extra line between paragraphs, rustdoc assumes you meant for them to be in the same paragraph and ignores newlines in the source.
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.
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.
Heh, TIL, but it also makes the source unreadable :)
8bc75b9
to
5252437
Compare
b82a9d5
to
b44f272
Compare
2f7567d
to
5e67a1c
Compare
This commit reworks how channel is told about which HTLCs were assigned which index upon the build of a `CommitmentTransaction`. Previously, `CommitmentTransaction` was given an exclusive reference to channel's HTLC-source table, and `CommitmentTransaction` populated the transaction output indices in that table via this exclusive reference. As a result, the public API of `CommitmentTransaction` included a generic parameter, and an exclusive reference. We remove both of these in preparation for the upcoming `TxBuilder` trait. This cleans up the API, and makes it more bindings-friendly. Henceforth, channel populates the HTLC-source table via a brute-force search of each htlc in `CommitmentTransaction`. This is an O(n^2) operation, but n is small enough that we ignore the performance hit. We also take this opportunity to cleanup how we build and sort the commitment transaction outputs together with the htlc output data in `CommitmentTransaction`. The goal is to keep the number of vector allocations to a minimum; we now only allocate a single vector to hold the transaction outputs, and do all the sorting in-place.
5e67a1c
to
75f81b5
Compare
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.
Probably worth adding the sort in the rebuild case, but gonna go ahead and land it.
let (obscured_commitment_transaction_number, txins) = Self::build_inputs(self.commitment_number, channel_parameters); | ||
|
||
// First rebuild the htlc outputs, note that these are already sorted | ||
let mut outputs = Self::build_htlc_outputs(keys, &self.nondust_htlcs, channel_parameters.channel_type_features()); |
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.
It would be nice to resort the HTLCs here before we return. The point of rebuild_transaction
is to avoid trusting the pre-built commitment transaction entirely and build it from the HTLC list.
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.
Should I get this done now ?
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.
Can we have fn verify
take a &mut self
? To highlight that this call will resort the HTLCs if necessary. Then fn rebuild_transaction
can call build_outputs_and_htlcs
just like fn new
without any new memory allocations.
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.
Ah looks like this upsets the validation APIs of the signer that take a &CommitmentTransaction
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.
Maybe we make it return a Result? Can happen in a followup but up to you if you want to do it now.
Oops, sorry lol, didn't mean for the nit on docs to be blocking. |
Ah all good I do agree with the aesthetics. |