Skip to content

Conversation

tankyleo
Copy link
Contributor

See commit messages

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 28, 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.

@tankyleo tankyleo requested a review from TheBlueMatt August 28, 2025 08:42
We now do not require that `channel_value_satoshis * 1000` is greater
than or equal to `value_to_holder_msat`; this allows
`get_next_commitment_stats` to be used to validate funding
contributions when negotiating a splice.
While these HTLCs may currently be unknown to our counterparty, they can
end up in commitments soon. Moreover, we are considering failing a
single HTLC here, not the entire channel, so we opt to be conservative
in what we accept to forward.

We still expect all balances to remain above 0 after subtracting this
bigger set of HTLCs plus any anchors (ie not including tx fee and
reserve).
While these fee updates may currently be unknown to our counterparty,
they can end up in commitments soon. Moreover, we are considering
failing a single HTLC here, not the entire channel, so we opt to be
conservative in what we accept to forward.
We sometimes do not have easy access to the
`dust_exposure_limiting_feerate`, yet we are still interested in basic
stats on commitments like balances and transaction fees. So we relax
the requirement that the `dust_exposure_limiting_feerate` is always set
when `feerate_per_kw` is not 0.
@tankyleo tankyleo force-pushed the 2025-08-fallible-stats branch from 3142f12 to ff95850 Compare August 28, 2025 09:14
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

❌ Patch coverage is 89.36170% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.69%. Comparing base (2772bfd) to head (5db254a).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 89.15% 8 Missing and 1 partial ⚠️
lightning/src/sign/tx_builder.rs 89.65% 1 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4032      +/-   ##
==========================================
- Coverage   88.75%   88.69%   -0.06%     
==========================================
  Files         176      176              
  Lines      128817   128859      +42     
  Branches   128817   128859      +42     
==========================================
- Hits       114327   114294      -33     
- Misses      11893    11958      +65     
- Partials     2597     2607      +10     
Flag Coverage Δ
fuzzing 21.89% <60.99%> (-0.04%) ⬇️
tests 88.52% <89.36%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

msg.feerate_per_kw,
dust_exposure_limiting_feerate,
)
.expect("Updating the fee should never exhaust the balance after HTLCs and anchors");
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO the tx builder should fail these - if the commitment transaction cannot be built because its nonsense, it shouldn't return stats, it should fail. Also, generally, we shouldn't be expecting these calls at all IMO - if a different tx builder has different logic for deciding when something is bogus, we should let it decide that and fail rather than declaring that it must always accept.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO the tx builder should fail these - if the commitment transaction cannot be built because its nonsense, it shouldn't return stats, it should fail.

Not sure I understand, isn't that what's happening already ?

Also, generally, we shouldn't be expecting these calls at all IMO - if a different tx builder has different logic for deciding when something is bogus, we should let it decide that and fail rather than declaring that it must always accept.

Done, see commit below

Copy link
Contributor Author

@tankyleo tankyleo Aug 28, 2025

Choose a reason for hiding this comment

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

IMO the tx builder should fail these - if the commitment transaction cannot be built because its nonsense, it shouldn't return stats, it should fail.

Not sure I understand, isn't that what's happening already ?

Ah do you mean that it should also fail if the tx fee exhausts the balance ? Right now we fail such cases on commitment_signed; we would now fail these on receiving update_fee.

We can leave this for after 0.2 I'm thinking ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah do you mean that it should also fail if the tx fee exhausts the balance ? Right now we fail such cases on commitment_signed; we would now fail these on receiving update_fee.

Hmm, good point. Can you remind me why we validate anything at all in validate_update_fee? When we actually get a commitment_signed we'll validate what we need there (well, we should, not sure if we do), and I'm not entirely sure why we started validating it in the update_fee handler. I recall something about fee updates causing us to send counterparty commitment sigs that overflowed things, but that shouldn't matter - we won't include the new fee in counterparty commitment transactions until the peer sends their cs anyway.

We can leave this for after 0.2 I'm thinking ?

We could, but it seems like an easy change that would further reduce the code complexity in channel.rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TheBlueMatt Some guessing below, will be digging further:

  • Right now we validate dust exposure in validate_update_fee and "can you afford the new fee" in validate_commitment_signed
  • Previously only the build_commitment_transaction call would allow us to determine if counterparty can afford the fee.
  • We now have these commitment_stats methods, so we could totally move this "can you afford proposed fee" check from validate_commitment_signed to validate_update_fee.
  • validate_update_fee does validate dust exposure because dust exposure stats are easily provided by get_pending_htlc_stats without building a full commitment transaction.

I will attempt to clean all this up now thank you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, so I think we should remove validate_update_fee entirely and just validate in validate_commitment_signed. The spec says we have to allow an update_fee that overdraws the balance as long as they claim an HTLC before they call commitment_signed, and I don't see a reason why we shouldn't just do it all there.

Copy link
Contributor Author

@tankyleo tankyleo Aug 29, 2025

Choose a reason for hiding this comment

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

@TheBlueMatt one more thing: the spec says we should check dust exposure on receiving update_fee not on receiving commitment_signed:

image

Should we move dust exposure checks to validate_commitment_signed too ?

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

@tankyleo tankyleo self-assigned this Aug 28, 2025
@tankyleo tankyleo moved this to Goal: Merge in Weekly Goals Aug 28, 2025
@tankyleo tankyleo requested a review from TheBlueMatt August 28, 2025 18:39
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.

Responded to the pending comment but ultimately this is gonna need rebase on #4011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Goal: Merge
Development

Successfully merging this pull request may close these issues.

3 participants