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

Add maxFeeRatio parameter to sanityCheckFee in psbt coin selection #8600

Merged

Conversation

GeorgeTsagk
Copy link
Collaborator

@GeorgeTsagk GeorgeTsagk commented Mar 28, 2024

Description

With the introduction of new template options for WalletKit.FundPsbt (see related PR) we made use of chanfunding.CoinSelect which introduces a slight change in behavior compared to the other template options, it performs a "fee sanity check" which will error out if the total fees exceed the 20% of the total outputs amount.

While this makes sense for channel funding, it may be a limitation the user won't always desire when manually funding PSBTs via the RPC.

Solution [Updated]

This PR simply adds a float parameter to the chanfunding.CoinSelect named maxFeeRatio which controls the maximum allowed fee to total output amt ratio. Any other path other than the WalletKit.FundPsbt rpc uses the default ratio of 0.2 (20% of total output amount). When calling this function from the RPC we use the value provided by the RPC, or the default if it wasn't set.

References

  • Tapd PR that exposed this behavior

@GeorgeTsagk GeorgeTsagk self-assigned this Mar 28, 2024
Copy link
Contributor

coderabbitai bot commented Mar 28, 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Change makes sense. Didn't think about very small amounts when adding the fee sanity check.

@@ -1546,7 +1546,7 @@ func (w *WalletKit) fundPsbtCoinSelect(account string, changeIndex int32,

changeAmt, needMore, err := chanfunding.CalculateChangeAmount(
inputSum, outputSum, packetFeeNoChange,
packetFeeWithChange, changeDustLimit, changeType,
packetFeeWithChange, changeDustLimit, changeType, true,
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 adding this flag makes sense, as you might want to be able to craft a 1-in-1-out transaction that pays more than 20% fees when it's a small input amount. But I think we should also expose this to the RPC and not just set this to true statically here.
So a new bool RPC parameter, for example allow_high_fees which by default is false.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, very happy to see that you agree with this approach.

I didn't expose this on RPC only because of "bloating" concerns, as I didn't want this extra flag to reach the user-facing params.
But I also think a psbt related call is the place to be specific and have fine control, on the other hand. So will change it as per your suggestion 👌

@dstadulis
Copy link
Collaborator

!lightninglabs-deploy mute 720h30m

@lightninglabs-deploy
Copy link

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

@guggero
Copy link
Collaborator

guggero commented Jul 8, 2024

!lightninglabs-deploy mute

@dstadulis
Copy link
Collaborator

dstadulis commented Sep 18, 2024

There's renewed interest in shipping these features.

Will unmute to try to merge the code. If alerts are bothersome for a long time, we can remute

!lightninglabs-deploy unmute

@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from 129145c to 1f32b5f Compare September 19, 2024 14:21
@GeorgeTsagk GeorgeTsagk changed the title Omit fee sanity check on chanfunding.CoinSelect when coming from RPC FundPsbt Add maxFeeRatio parameter to sanityCheckFee in psbt coin selection Sep 19, 2024
@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from 1f32b5f to 155d1a0 Compare September 19, 2024 15:02
@GeorgeTsagk GeorgeTsagk requested a review from guggero September 19, 2024 15:03
@ziggie1984
Copy link
Collaborator

hmm, I think rather than adding a ratio, what about skipping the sanity_fee check, because I think the ratio idea is basically the same as skipping it, at least that's how I envision it will be used.

instead of a ratio, just add maybe a flag to skip the fee-check

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Needs some commit massaging, otherwise looks pretty good.

lnrpc/walletrpc/walletkit_server.go Show resolved Hide resolved
lnrpc/walletrpc/walletkit.proto Outdated Show resolved Hide resolved
@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from 155d1a0 to 0e487e4 Compare October 15, 2024 16:23
@GeorgeTsagk
Copy link
Collaborator Author

@guggero all commits can compile now

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Linter and commit check still fails.
Other than that looks good to me.

Helper command to make sure each commit compiles individually:

git rebase -i origin/master --exec "make unit pkg=... case=_NONE_"

lnwallet/chanfunding/coin_select.go Outdated Show resolved Hide resolved
lnwallet/chanfunding/coin_select.go Show resolved Hide resolved
@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from 0e487e4 to 5eda335 Compare October 28, 2024 17:55
@GeorgeTsagk
Copy link
Collaborator Author

Linter and commit check still fails. Other than that looks good to me.

Helper command to make sure each commit compiles individually:

git rebase -i origin/master --exec "make unit pkg=... case=_NONE_"

Ah yes, the first commit that updates the func didn't have the unit tests calling the funcs with all args, used dummy values just for the commit to compile, should be good now

@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch 2 times, most recently from 909891c to e138fa7 Compare November 4, 2024 10:16
@GeorgeTsagk GeorgeTsagk requested a review from guggero November 4, 2024 13:03
@GeorgeTsagk
Copy link
Collaborator Author

Forgot to update the cmd command, doing now

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Just nits, otherwise LGTM 🎉

lnwallet/chanfunding/coin_select.go Outdated Show resolved Hide resolved
docs/release-notes/release-notes-0.19.0.md Outdated Show resolved Hide resolved
@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch 2 times, most recently from ca72f74 to 582fe81 Compare November 5, 2024 09:24
@ziggie1984 ziggie1984 self-requested a review November 5, 2024 10:58
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

Still not convinced about the ratio approach but i am open to hear your side of the argument why we should not just instead go with a boolean here ?

I think the use-case will look like this:

  1. User funds psbt, and gets the error that the fee exceeds 20%
  2. Probably we currently also return the acutaly ratio with would be needed
  3. User just selects this ratio, however because we use a > maxFee, he will probably do it twice

So I would favour just a skipFee boolean, which imo does exactly the right thing.

docs/release-notes/release-notes-0.19.0.md Show resolved Hide resolved
lnwallet/chanfunding/coin_select.go Outdated Show resolved Hide resolved
lnrpc/walletrpc/walletkit.proto Outdated Show resolved Hide resolved
lnrpc/walletrpc/walletkit_server_test.go Outdated Show resolved Hide resolved
lnwallet/chanfunding/coin_select_test.go Outdated Show resolved Hide resolved
cmd/commands/walletrpc_active.go Outdated Show resolved Hide resolved
lnrpc/walletrpc/walletkit_server.go Outdated Show resolved Hide resolved
@GeorgeTsagk
Copy link
Collaborator Author

Still not convinced about the ratio approach but i am open to hear your side of the argument why we should not just instead go with a boolean here ?

I think the use-case will look like this:

  1. User funds psbt, and gets the error that the fee exceeds 20%
  2. Probably we currently also return the acutaly ratio with would be needed
  3. User just selects this ratio, however because we use a > maxFee, he will probably do it twice

So I would favour just a skipFee boolean, which imo does exactly the right thing.

Yeah I agree that a skipFee bool could be simpler for a manual user-driven story

Although this is also meant for external automated software that uses lnd for the funding of psbts

Could have a protocol/wallet that needs to craft PSBTs, and depending on what the application is I might want to select a certain ratio across all my calls to FundPsbt. One application may want to pick a protective ratio, another one maybe a more aggressive/relaxed ratio.

If we had the skipFee version here we would force all the external software to do the fee check on their end, while now they can rely on LND's internal fee calculations by exposing max_fee_ratio

I don't really have better arguments than this, and that I'd rather have a bit more expressiveness by default

@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch 2 times, most recently from 51d09d5 to 33320ba Compare November 5, 2024 14:41
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

Ok agree, the ratio idea can make sense for external software 👍

Had some final comments.

lnwallet/chanfunding/coin_select.go Show resolved Hide resolved
@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from 33320ba to b19fac1 Compare November 5, 2024 15:03
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGTM

@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from b19fac1 to 6116039 Compare November 5, 2024 15:21
@GeorgeTsagk
Copy link
Collaborator Author

Fixed some more unit tests which expected the old err format, waiting for CI

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Some last minute changes made it into the wrong commit.

lnwallet/chanfunding/coin_select.go Outdated Show resolved Hide resolved
lnwallet/chanfunding/coin_select.go Show resolved Hide resolved
lnrpc/walletrpc/walletkit_server.go Outdated Show resolved Hide resolved
@GeorgeTsagk GeorgeTsagk force-pushed the chanfunding-coinselect-nofeecheck branch from 6116039 to c1f5908 Compare November 5, 2024 18:56
@GeorgeTsagk GeorgeTsagk requested a review from guggero November 5, 2024 18:57
@GeorgeTsagk
Copy link
Collaborator Author

Thanks for the last second nits @guggero 💪

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice, LGTM 🎉

@guggero guggero merged commit e3cc4d7 into lightningnetwork:master Nov 5, 2024
25 of 27 checks passed
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.

5 participants