Skip to content

Separate auxiliary HTLC data from holder commitment transaction #3774

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wpaulino
Copy link
Contributor

We shouldn't track our HTLCSources within our
HolderCommitmentTransactions duplicatively for each FundingScope. With splicing, we may have alternative holder commitment transactions, but they must all have the same set of non-dust and dust HTLCs as the pre-spliced commitment transaction. Different sets of HTLCs are only possible with a change to the dust limit on commitment transactions, which the splicing protocol does not currently support.

This commit moves the nondust_htlc_sources and dust_htlcs fields out from each FundingScope into the ChannelMonitor, such that they can be reused for each FundingScope. This remains as a backwards compatible change, the underlying stored data is not changed, but where it lives in memory is.

We shouldn't track our `HTLCSource`s within our
`HolderCommitmentTransaction`s duplicatively for each `FundingScope`.
With splicing, we may have alternative holder commitment transactions,
but they must all have the same set of non-dust and dust HTLCs as the
pre-spliced commitment transaction. Different sets of HTLCs are only
possible with a change to the dust limit on commitment transactions,
which the splicing protocol does not currently support.

This commit moves the `nondust_htlc_sources` and `dust_htlcs` fields
out from each `FundingScope` into the `ChannelMonitor`, such that they
can be reused for each `FundingScope`. This remains as a backwards
compatible change, the underlying stored data is not changed, but where
it lives in memory is.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 12, 2025

👋 Thanks for assigning @TheBlueMatt 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.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Basically LGTM, a few minor questions and one comment about unnecessary clones.

struct HolderCommitment {
tx: HolderCommitmentTransaction,
#[derive(Clone, Default, PartialEq)]
struct HolderCommitmentHTLCData {
// These must be sorted in increasing output index order to match the expected order of the
// HTLCs in the `CommitmentTransaction`.
nondust_htlc_sources: Vec<HTLCSource>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we want to go ahead and assume that dust/non-dust are universal concepts, but do we want to also assume that HTLC ordering is fixed across splices? I know it is in non-custom-commitments, but we'd be assuming it in custom commitments which is yet another footgun in the API there. Also not sure how big a difference it would be to avoid the assumption, presumably some nontrivial work. CC @tankyleo.

@@ -1612,6 +1640,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
balances_empty_height: None,

failed_back_htlc_ids: new_hash_set(),

current_holder_htlc_data: HolderCommitmentHTLCData::default(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I really hate default for stuff like this. Its much less clear to the reader compared to something like empty.

@@ -938,15 +940,15 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
let dust_htlcs = holder_signed_tx.htlc_outputs.iter().filter_map(|(htlc, _, source)| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This and the extra clones aren't necessary - we can pass HolderSignedTx by value and skip them in the deserialization logic.

@ldk-reviews-bot
Copy link

👋 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.

Copy link

codecov bot commented May 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (16307f6) to head (7fefc6a).
Report is 39 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #3774       +/-   ##
==========================================
- Coverage   89.15%       0   -89.16%     
==========================================
  Files         157       0      -157     
  Lines      124109       0   -124109     
  Branches   124109       0   -124109     
==========================================
- Hits       110646       0   -110646     
+ Misses      10788       0    -10788     
+ Partials     2675       0     -2675     

☔ 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.

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.

3 participants