Uh oh!
There was an error while loading. Please reload this page.
Remove exclusive reference and generic from CommitmentTransaction API - #3689
Conversation
👋 Thanks for assigning @wpaulino as a reviewer! |
CommitmentTransaction APICommitmentTransaction APICommitmentTransaction APICommitmentTransaction APICommitmentTransaction APIc8a753e to
b04cc76CompareCommitmentTransaction APICommitmentTransaction APIf4a3cc3 to
acad6d8CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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:
|
TheBlueMatt
left a comment
There was a problem hiding this comment.
One last real comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
1d7a1d8 to
262351cCompare
TheBlueMatt
left a comment
There was a problem hiding this comment.
New commit basically LTGM.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
TheBlueMatt
left a comment
There was a problem hiding this comment.
Basically LGTM, Probably needs another look from @wpaulino otherwise I'm happy.
| /// | ||
| /// 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.
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.
Heh, TIL, but it also makes the source unreadable :)
Uh oh!
There was an error while loading. Please reload this page.
8bc75b9 to
5252437CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
b82a9d5 to
b44f272Compare2f7567d to
5e67a1cCompare
TheBlueMatt
left a comment
There was a problem hiding this comment.
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.
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.
Should I get this done now ?
There was a problem hiding this comment.
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.
Ah looks like this upsets the validation APIs of the signer that take a &CommitmentTransaction
There was a problem hiding this comment.
Maybe we make it return a Result? Can happen in a followup but up to you if you want to do it now.
There was a problem hiding this comment.
Meaning rebuild_transaction returns an Err if the HTLCs are not sorted ? Yes
TheBlueMatt
commented
Apr 16, 2025
Oops, sorry lol, didn't mean for the nit on docs to be blocking. |
tankyleo
commented
Apr 16, 2025
Ah all good I do agree with the aesthetics. |
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. Finally, we add test coverage to assert that `CommitmentTransaction::verify` actually checks that the HTLCs in the `nondust_htlcs` member are actually sorted.
tankyleo
commented
Apr 16, 2025
@wpaulino I previously mistakenly started trusting the order of HTLCs in the |

Uh oh!
There was an error while loading. Please reload this page.