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

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

Crypt-iQ
Copy link
Collaborator

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

Copy link
Contributor

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 Configuration 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 4 times, most recently from 0364eae to 8043864 Compare June 13, 2024 16:34
@Crypt-iQ Crypt-iQ marked this pull request as ready for review June 13, 2024 20:31
@Crypt-iQ Crypt-iQ force-pushed the precise_dust_limit branch from 8043864 to 6266d9d Compare June 20, 2024 00:10
@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 65 to 78
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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the commit fees here is the CommitFee field on the commitment struct which doesn't include dust. can update the comment to explicitly state that

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

Logic LGTM ✅
pending other reviewer comments :)

@Crypt-iQ Crypt-iQ force-pushed the precise_dust_limit branch from 6266d9d to 720f46f Compare July 12, 2024 01:58
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.

I think we should go further with the terminology changes. I also had some questions about whether certain values are already included in other ones.

Comment on lines 2850 to 2889
localDustSum += lnwire.NewMSatFromSatoshis(commitFee)
remoteDustSum += lnwire.NewMSatFromSatoshis(commitFee)

// Calculate the additional fee increase if this is a non-dust HTLC.
weight := lntypes.WeightUnit(input.HTLCWeight)
additional := lnwire.NewMSatFromSatoshis(
feeRate.FeeForWeight(weight),
)

if isLocalDust {
// If this is dust, it doesn't contribute to weight but does
// contribute to the overall dust sum.
localDustSum += lnwire.NewMSatFromSatoshis(amount)
} else {
// Account for the fee increase that comes with an increase in
// weight.
localDustSum += additional
}

if localDustSum > l.cfg.MaxFeeExposure {
// The max fee exposure was exceeded.
return true
}

if isRemoteDust {
// If this is dust, it doesn't contribute to weight but does
// contribute to the overall dust sum.
remoteDustSum += lnwire.NewMSatFromSatoshis(amount)
} else {
// Account for the fee increase that comes with an increase in
// weight.
remoteDustSum += additional
}

if remoteDustSum > l.cfg.MaxFeeExposure {
// The max fee exposure was exceeded.
return true
}

return false
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd recommend consolidating some of the branch execution logic in favor of something more expression oriented like this. Assigning variables once makes it easier for people to read the definition and not have to reason about operational semantics in order to understand what the code is doing.

	// localDustSum += lnwire.NewMSatFromSatoshis(commitFee) --> Delete
	// remoteDustSum += lnwire.NewMSatFromSatoshis(commitFee) --> Delete

	// Calculate the additional fee increase if this is a non-dust HTLC.
	weight := lntypes.WeightUnit(input.HTLCWeight)
	additional := lnwire.NewMSatFromSatoshis(
		feeRate.FeeForWeight(weight),
	)

        var addedLocalFees lnwire.MilliSatoshi
	if isLocalDust {
		// If this is dust, it doesn't contribute to weight but does
		// contribute to the overall dust sum.
		addedLocalFees = lnwire.NewMSatFromSatoshis(amount)
	} else {
		// Account for the fee increase that comes with an increase in
		// weight.
		addedLocalFees = additional
	}

        var addedRemoteFees lnwire.MilliSatoshi
	if isRemoteDust {
		// If this is dust, it doesn't contribute to weight but does
		// contribute to the overall dust sum.
		addedRemoteFees = lnwire.NewMSatFromSatoshis(amount)
	} else {
		// Account for the fee increase that comes with an increase in
		// weight.
		addedRemoteFees = additional
	}

        localFeeExposure := localDustSum + addedLocalFees + commitFee
        remoteFeeExposure := remoteDustSum + addedRemoteFees + commitFee

	return localFeeExposure > l.cfg.MaxFeeExposure ||
	        remoteFeeExposure > l.cfg.MaxFeeExposure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

don't see a problem with code as-is, it's pretty easy to understand what's going on imo

Copy link
Collaborator

@ProofOfKeags ProofOfKeags Jul 25, 2024

Choose a reason for hiding this comment

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

There are two main things I'm trying to discourage:

  1. += and other forms of variable reassignment make it harder to reason locally about code. It also means that whatever the variable is named is wrong for some portion of the lifetime of that variable. Either it starts correct and is wrong later when reassigned, or it starts wrong and ends correct later when it is reassigned. When reassignment is present it is also not obvious which of these two scenarios we are in.
  2. Early returns make it harder to grok the overall picture of what the expression is. In my offered solution we can see quite easily that if either the local or remote fee exposure blows the limit, then we are overexposed, and we can see the constituent components of the overall exposure.

This isn't a blocking comment, but I'm generally trying to reduce complexity and increase the comprehension ability of the codebase, and so I offered an alternative that solves both of these things.

@lightninglabs-deploy
Copy link

@Crypt-iQ, remember to re-request review from reviewers when ready

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.

Just two small-ish things at this point.

@Crypt-iQ Crypt-iQ force-pushed the precise_dust_limit branch from 50b9b1d to cc4a703 Compare July 26, 2024 14:59
@Crypt-iQ Crypt-iQ requested a review from ProofOfKeags July 26, 2024 14:59
@Crypt-iQ Crypt-iQ force-pushed the precise_dust_limit branch 2 times, most recently from c9fd46d to 6279406 Compare July 29, 2024 17:47
Crypt-iQ added 3 commits July 29, 2024 14:13
This commit expands the definition of the dust limit to take into
account commitment fees as well as dust HTLCs. The dust limit is now
known as a fee exposure threshold. 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 force-pushed the precise_dust_limit branch from 6279406 to 74636e9 Compare July 29, 2024 18:14
Comment on lines +4769 to +4773
// Here we override the view's fee-rate if a dry-run fee-rate was
// passed in.
if !updateState {
feePerKw = dryRunFee.UnwrapOr(feePerKw)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

🫡

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

Very nice & very clean ✅

@guggero guggero merged commit ac4ef28 into lightningnetwork:master Jul 31, 2024
30 of 34 checks passed
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.

6 participants