Skip to content
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

multi: include commitment fees in dust calculation #8824

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Crypt-iQ
Copy link
Collaborator

Small-ish change to the link to include commitment fees in dust calculation.

Copy link

coderabbitai bot commented Jun 10, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@saubyk saubyk added this to the v0.18.1 milestone Jun 10, 2024
@Crypt-iQ Crypt-iQ force-pushed the precise_dust_limit branch 3 times, most recently from 454be5c to 0364eae Compare June 13, 2024 16:20
This commit expands the definition of the dust limit to take into
account commitment fees as well as dust HTLCs. Dust HTLCs are fees
anyways so it makes sense to account for commitment fees as well.
The link has been modified slightly to calculate dust. In the future,
the switch dust calculations can be removed.
@Crypt-iQ Crypt-iQ marked this pull request as ready for review June 13, 2024 20:31
@saubyk saubyk added the P1 MUST be fixed or reviewed label Jun 25, 2024
Copy link
Collaborator

@ProofOfKeags ProofOfKeags left a comment

Choose a reason for hiding this comment

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

My main feedback here is around terminology. I think we should avoid stretching the definition of "dust" since this conveys a certain understanding that spans more than just LND/Lightning and is an industry wide term.

I would recommend using terminology like "fee exposure" since that is both more accurate in what it is measuring and also accurate with respect to how we are letting the value influence our decisionmaking.

The implementation is fine but I'd like to see the optional parameter made required. I anticipate there may be hiccups here as it would require you to be able to supply the current state at the callsite. I don't think that computing that will be too onerous, but let me know if you think otherwise.

Comment on lines +283 to +285
// DustThreshold is the threshold in milli-satoshis after which we'll
// restrict the flow of HTLCs and fee updates.
DustThreshold lnwire.MilliSatoshi
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should consider renaming this to something like max fee exposure given the expanded role. Intuitively it feels that the name "dust threshold" means the threshold at which something becomes dust. The role this value is playing is the maximum fee exposure we want to have.

Comment on lines +8489 to +8492
// DryRunUpdateFee applies a proposed feerate to the channel and returns the
// commitment fee with this new feerate. It does not modify the underlying
// LightningChannel.
func (lc *LightningChannel) DryRunUpdateFee(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should rename this for CommitFeeTotalAt or something like that. This is essentially a pure function and so calling it a "dry run update" doesn't make a lot of sense.

Comment on lines +384 to +386
// DustThreshold limits the number of outstanding fees in a channel.
// This value will be passed to created links.
DustThreshold lnwire.MilliSatoshi
Copy link
Collaborator

Choose a reason for hiding this comment

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

same rec here about renaming.

Comment on lines +4736 to +4738
updateState bool, dryRunFee fn.Option[chainfee.SatPerKWeight]) (
lnwire.MilliSatoshi, lnwire.MilliSatoshi, lntypes.WeightUnit,
*htlcView, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking maybe we don't take the parameter optionally and just requiring you to pass it in. Then at the callsite we can just grab the current fee rate and pass it in?

Comment on lines +65 to +77
getDustSum(remote bool,
fee fn.Option[chainfee.SatPerKWeight]) lnwire.MilliSatoshi

// getFeeRate returns the current channel feerate.
getFeeRate() chainfee.SatPerKWeight

// getDustClosure returns a closure that can evaluate whether a passed
// HTLC is dust.
getDustClosure() dustClosure

// getCommitFee returns the commitment fee in satoshis from either the
// local or remote commitment.
getCommitFee(remote bool) btcutil.Amount
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the main question I have at this point is what the formal distinction is between the commit fees and the dust. It seems like starting with this commit, you want to redefine dust to be the commitment fees themselves.

Comment on lines +2773 to +2784
// isDustWithFee returns whether or not the new proposed fee-rate increases the
// total dust and fees within the channel past the configured dust threshold.
// It first calculates the dust sum over every update in the update log with
// the proposed fee-rate and taking into account both the local and remote dust
// limits. It uses every update in the update log instead of what is actually
// on the local and remote commitments because it is assumed that in a
// worst-case scenario, every update in the update log could theoretically be
// on either commitment transaction and this needs to be accounted for with
// this fee-rate. It then calculates the local and remote commitment fees given
// the proposed fee-rate. Finally, it tallies the results and determines if the
// dust threshold has been exceeded.
func (l *channelLink) isDustWithFee(feePerKw chainfee.SatPerKWeight) (bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I think redefining this to just be exceedsFeeExposureLimit or something to that effect would make more sense.

Comment on lines +2801 to +2815
// Finally, check whether the dust threshold was exceeded on either
// future commitment transaction with the fee-rate.
totalLocalDust := localDustSum + lnwire.NewMSatFromSatoshis(localFee)
if totalLocalDust > l.cfg.DustThreshold {
return true, nil
}

totalRemoteDust := remoteDustSum + lnwire.NewMSatFromSatoshis(
remoteFee,
)
if totalRemoteDust > l.cfg.DustThreshold {
return true, nil
}

return false, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be combined into a single expression rather than the procedural fallthrough.

// fail so amounts below 800sats will breach the dust threshold.
// Alice will send 354 HTLC's of 700sats. Bob will also send 354 HTLC's
// of 700sats.
numHTLCs := 354
Copy link
Collaborator

Choose a reason for hiding this comment

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

does the change in the magic number result in anything significant?

@@ -504,7 +504,7 @@ func testBidirectionalAsyncPayments(ht *lntest.HarnessTest) {
args := []string{
// Increase the dust threshold to avoid the payments fail due
// to threshold limit reached.
"--dust-threshold=5000000",
"--dust-threshold=10000000",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this due to the expanded definition of dust?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 MUST be fixed or reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants