-
Notifications
You must be signed in to change notification settings - Fork 390
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
[Custom Transactions] Commitment Transaction & Channel Refactors #3606
Conversation
Do you also wanna add the cfg-gate to the CI testing configs? |
81b0ecb
to
647d42e
Compare
Thank you done |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3606 +/- ##
==========================================
+ Coverage 89.18% 89.25% +0.06%
==========================================
Files 155 155
Lines 119274 119206 -68
Branches 119274 119206 -68
==========================================
+ Hits 106379 106393 +14
+ Misses 10290 10223 -67
+ Partials 2605 2590 -15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
647d42e
to
beec57f
Compare
ChannelParameters
, TxBuilder
traitsTxBuilder
trait
Rebase:
|
beec57f
to
0c96878
Compare
Notes:
|
0c96878
to
11f6b5f
Compare
11f6b5f
to
2f705d1
Compare
Note that this PR now breaks the public API of |
035e35f
to
42d5a79
Compare
d9c7ba9
to
9a1997a
Compare
@wpaulino just chatted with @TheBlueMatt offline some takeaways:
|
Rebase: switch from saturating subs to checked subs, update comments, delete broken test vector. |
b27b9ee
to
fe0f94c
Compare
The `DirectedChannelTransactionParameters` argument of the `CommitmentTransaction` constructor already contains the broadcaster, and the countersignatory public keys, which include the respective funding keys. It is therefore not necessary to ask for these funding keys in additional arguments.
Instead of asking callers to generate the `TxCreationKeys` on every new commitment before constructing a `CommitmentTransaction`, this commit lets `CommitmentTransaction` derive the `TxCreationKeys` it will use to build the raw commitment transaction. This allows a tighter coupling between the per-commitment keys, and the corresponding commitment transaction. As new states are generated, callers now only have to derive new commitment points; `CommitmentTransaction` takes care of deriving the per-commitment keys. This commit also serves to limit the objects in LDK that derive per-commitment keys according to the LN Specification in preparation for enabling custom derivations in the future.
Channel objects should not impose a particular per-commitment derivation scheme on the builders of commitment transactions. This will make it easier to enable custom derivations in the future. Instead of building `TxCreationKeys` explicitly, the function `TrustedCommitmentTransaction::keys` should be used when the keys of the commitment transaction are needed. We do that in this commit.
The logging for loop in `send_commitment_no_state_update` only iterates over the non-dust HTLCs. Thus we do not need to create a `Vec<HTLCOutputInCommitment>` that includes both dust and non-dust HTLCs, we can grab the `Vec<HTLCOutputInCommitment>` that holds only non-dust HTLCs directly from `CommitmentTransaction`.
fe0f94c
to
ee8b846
Compare
Instead of converting operands to `i64` and checking if the subtractions overflowed by checking if the `i64` is smaller than zero, we instead choose to do checked and saturating subtractions on the original unsigned integers.
There is no need for an if statement if it will always be true.
The fields `feerate_per_kw` and `num_nondust_htlcs` of `CommitmentStats` can both be accessed directly from the `tx: CommitmentTransaction` field. We also take this opportunity to rename the balance fields to make it extra clear what they refer to.
We choose to include in `CommitmentStats` only fields that will be calculated or constructed by transaction builders. The other fields are created by channel, and placed in a new struct we call `CommitmentData`.
The saturating subtractions used in `ChannelContext::build_commitment_transaction` are there for a reason; when the remote party updates the fees, we build the new commitment transaction before checking whether the remote party has enough balance to cover the new fee, so we cannot guarantee that the remote party's balance will be greater than or equal to the sum of the fee and the anchors.
ee8b846
to
ff259ba
Compare
value_to_self_msat_offset -= htlc.amount_msat as i64; | ||
}, | ||
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) | | ||
OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) | |
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.
AwaitingRemovedRemoteRevoke
isn't a tautology because it is always !include
even if generated_by_local
.
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.
I don't think I make any changes to that variant ? As before, always subtract from the offset.
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 I'm off on the vocabulary, the tautology to me is the !generated_by_local
expression below.
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.
Sheesh I was more tired than I thought :(
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.
no problem
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.
Otherwise lgtm
if msg.htlc_signatures.len() != commitment_stats.num_nondust_htlcs { | ||
return Err(ChannelError::close(format!("Got wrong number of HTLC signatures ({}) from remote. It must be {}", msg.htlc_signatures.len(), commitment_stats.num_nondust_htlcs))); | ||
if msg.htlc_signatures.len() != commitment_data.stats.tx.htlcs().len() { | ||
return Err(ChannelError::close(format!("Got wrong number of HTLC signatures ({}) from remote. It must be {}", msg.htlc_signatures.len(), commitment_data.stats.tx.htlcs().len()))); |
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.
In a followup can we rename htlcs
to nondust_htlcs
or so? Would add a lot of clarity in a few places.
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.
100%
Miscellaneous refactors of
CommitmentTranscation
and channel in preparation for the upcomingTxBuilder
trait. See the commit messages.