Skip to content

[Custom Transactions] Let TxBuilder set the HTLC dust limit #3921

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

tankyleo
Copy link
Contributor

@tankyleo tankyleo commented Jul 10, 2025

Let `TxBuilder` set the HTLC dust limit

Channel now sorts dust and nondust HTLCs according to the dust limit set
by `TxBuilder`.

We also let `TxBuilder` set the total endogenous fees spent on a set of
HTLC transactions via `htlc_txs_endogenous_fees_sat`.

Both of these changes abstract the weight of HTLC transactions away
from channel.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jul 10, 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 self-assigned this Jul 10, 2025
@tankyleo tankyleo moved this to Goal: Merge in Weekly Goals Jul 10, 2025
@tankyleo
Copy link
Contributor Author

tankyleo commented Jul 10, 2025

We discussed earlier passing the entire list of HTLCs to TxBuilder, and letting it do the dust-vs-non-dust sorting itself. There are nonetheless multiple places in channel that are interested in knowing the exact HTLC dust limit (see get_pending_{inbound, outbound}_htlc_details, get_available_balances_for_scope).

So we prefer to add a single method that surfaces this limit to channel, and then let channel sort HTLCs depending on whether their value sits above or below that amount.

As a result, builders of custom transactions will only have a say on where the dust limit sits, and won't be able to choose arbitrary subsets for dust and non-dust HTLCs.

@carlaKC carlaKC self-requested a review July 10, 2025 17:43
@carlaKC
Copy link
Contributor

carlaKC commented Jul 10, 2025

We discussed earlier passing the entire list of HTLCs to TxBuilder, and letting it do the dust-vs-non-dust sorting itself.

Is the main motivation for this to get all of the commitment-related logic out of channel.rs, or that we think that custom tx builders will want to specifically choose certain htlcs to be dust?

get_available_balances_for_scope

The key questions we're looking to answer seems to be "can I afford a commitment with this theoretical dust/nondust htlc"? This does seem to be something we could move into TxBuilder if we pass the full HTLC set and use a version of HTLCCandidate which just tells TxBuilder whether it is dust (we never actually use this amount other than the dust check).

Sadly here's no getting around needing to know the dust limit if we want to clamp our capacity to that value, so we'd still need to surface htlc_success_timeout_dust_limits.

get_pending_{inbound, outbound}_htlc_details

Tempting to suggest just adding an is_dust check to TxBuilder for these to make it slightly more abstract than surfacing the second stage fees, but given the above requirement to know the exact dust limit maybe we just want to leave as-is.

so tl;dr: I'd be interested in seeing what trying to pull more of the dust logic out into TxBuilder looks like, even if just gives us a clearer idea of where the trait line should be.


Meta note: This has got a lot of overlap with 3bb0586, so I think we should either:

  1. Rebase Update fee and dust handling for zero fee channels #3884 on this PR
  2. Pull the commit out into a common prefactor (I have a slight pref for this, but happy with either)

@tankyleo
Copy link
Contributor Author

Is the main motivation for this to #3775 (comment), or that we think that custom tx builders will want to specifically choose certain htlcs to be dust?

I would say we focus on the latter for this PR, and let the former be the overarching goal :)

so tl;dr: I'd be interested in seeing what trying to pull more of the dust logic out into TxBuilder looks like, even if just gives us a clearer idea of where the trait line should be.

Let me know what you think of this new direction here. Still have some clunkiness to resolve, but that's what it's looking like right now.

@tankyleo
Copy link
Contributor Author

Meta note: This has got a lot of overlap with 3bb0586

Definitely let me rebase on top of your PR, you've rebased once already :)

@tankyleo tankyleo force-pushed the dust-limit branch 2 times, most recently from 12fd6c3 to 067bfa0 Compare July 11, 2025 09:41
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @carlaKC! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@carlaKC
Copy link
Contributor

carlaKC commented Jul 15, 2025

Let me know what you think of this new direction here.

I like this approach! Definitely prefer being able to move a lot of the dust / second stage tx reasoning into the builder 👍

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @carlaKC! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@tankyleo tankyleo removed the request for review from carlaKC July 18, 2025 18:01
@tankyleo tankyleo changed the title [Custom Transactions] Abstract the weight of HTLC transactions away from channel [Custom Transactions] Abstract dust-vs-nondust HTLC sorting away from channel Jul 21, 2025
@tankyleo tankyleo marked this pull request as ready for review July 21, 2025 08:56
@tankyleo tankyleo requested a review from TheBlueMatt July 21, 2025 08:56
@tankyleo
Copy link
Contributor Author

I'm aware I still owe a follow-up PR from the previous PR in this project, will push that soon in a separate PR :)

Comment on lines 42 to 46
fn on_holder_tx_dust_exposure_msat(
&self, dust_buffer_feerate: u32, holder_dust_limit_satoshis: u64,
channel_type: &ChannelTypeFeatures, htlcs: &[HTLCAmountDirection],
) -> u64;
fn on_counterparty_tx_dust_exposure_msat(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really sure I understand the point of these two methods if we have htlc_success_timeout_dust_limit as a method - if the API includes a method to say "hey, for an HTLC of type X what is the threshold where its dust", why bother with a method to say "given these HTLCs, how many are dust?", it seems the second can be calculated from the first, no? The same applies for passing the HTLC list to commit_tx_fee_sat.

Alternatively, we could drop the htlc_success_timeout_dust_limits method (if we want to not require there be some strict threshold to indicate when an HTLC is dust, though I think its a fine assumption to bake into the API, I dunno why someone would want to have some HTLCs be dust and others at the same value not be) and have a more generic "is HTLC dust on the next counterparty/local commitment transaction" call, but even there it seems like we don't need all of these methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good yes I initially had a version of the API that matches what you describe. We wanted to see what it would look like if we moved more logic out of channel into TxBuilder, but I agree we only really need the dust limits.

I will clean up those methods, and add TxBuilder methods for 1) the dust limit 2) the htlc endogenous fees (to calculate counterparty dust exposure).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean don't get me wrong, I'd love to move more logic out of channel.rs into TxBuilder, that would be great, but we also don't want to have an overlapping API where we have two ways to do things over the API. Also, we want to eventually make TxBuilder public, so it would be nice to avoid adding too much complexity (in the form of a ton of different methods).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW the real blocker on the more ambitious / complex API was the get_available_balances method - at the moment this method requires an exact dust limit above which all HTLCs are non-dust.

I have some code written that moves most of get_available_balances behind TxBuilder, but the complexity is not worth it, especially if we can make the assumption you describe above about the strict dust-vs-nondust threshold.

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

Channel now sorts dust and nondust HTLCs according to the dust limit set
by `TxBuilder`.

We also let `TxBuilder` set the total endogenous fees spent on a set of
HTLC transactions via `htlc_txs_endogenous_fees_sat`.

Both of these changes abstract the weight of HTLC transactions away
from channel.
@tankyleo tankyleo changed the title [Custom Transactions] Abstract dust-vs-nondust HTLC sorting away from channel [Custom Transactions] Let TxBuilder set the HTLC dust limit Jul 22, 2025
@tankyleo tankyleo changed the title [Custom Transactions] Let TxBuilder set the HTLC dust limit [Custom Transactions] Let TxBuilder set the HTLC dust limit Jul 22, 2025
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.02%. Comparing base (eac01d0) to head (1eb1c9e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3921      +/-   ##
==========================================
- Coverage   89.02%   89.02%   -0.01%     
==========================================
  Files         167      167              
  Lines      121800   121763      -37     
  Branches   121800   121763      -37     
==========================================
- Hits       108434   108401      -33     
+ Misses      10953    10951       -2     
+ Partials     2413     2411       -2     
Flag Coverage Δ
fuzzing 22.68% <97.61%> (-0.05%) ⬇️
tests 88.85% <100.00%> (-0.01%) ⬇️

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.

Copy link
Contributor

@elnosh elnosh left a comment

Choose a reason for hiding this comment

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

for what it can be worth it I have reviewed 1eb1c9e and it looks correct to me.

As for my understanding on the reasoning for the change, motivation seems to be to move usage of second_stage_tx_fees_sat and htlc_tx_fees_sat to TxBuilder in order to abstract away usage of weight of htlc transactions away from channel.rs.

@tankyleo
Copy link
Contributor Author

for what it can be worth it I have reviewed 1eb1c9e and it looks correct to me.

As for my understanding on the reasoning for the change, motivation seems to be to move usage of second_stage_tx_fees_sat and htlc_tx_fees_sat to TxBuilder in order to abstract away usage of weight of htlc transactions away from channel.rs.

Thanks for reviewing ! I would go further and say we want to allow people to set arbitrary dust limits for HTLCs on commitment transactions.

@tankyleo tankyleo requested a review from TheBlueMatt July 22, 2025 17:22
@tankyleo
Copy link
Contributor Author

@TheBlueMatt did you have a chance to look at the latest commit here ? It has the API cleanup, thank you !

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.

Discussed it offline, but I'm somewhat skeptical of a design that adds too many more methods on TxBuilder. We should consider exploring options that keep TxBuilder much smaller with more logic in larger methods (that we're willing to call and throw away some of the result of, eg relying more on something like that looks like build_commitment_stats to figure out dust exposures and whether an htlc is acceptable).

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.

5 participants