lnd icon indicating copy to clipboard operation
lnd copied to clipboard

walletrpc: unify coin selection, allow coin selection for PSBT with pre-defined inputs

Open guggero opened this issue 1 year ago • 6 comments

Depends on https://github.com/btcsuite/btcwallet/pull/900.

This PR first adds the coin selection strategy to the channel funding coin selection algorithm. Then we prepare the coin selection algorithm in the chanfunding package to be re-used by other packages by generalizing some of the assumptions made regarding weights and change output sizes.

Finally we add a new, third, mode for funding a PSBT where we allow inputs to be pre-defined while still performing coin selection (previously users could only either specify no inputs at all to trigger coin selection, or, if inputs were specified, no new ones would be selected and only fee estimation would be performed).

Summary by CodeRabbit

  • New Features

    • Added CoinSelectionStrategy to wallet configuration options.
  • Enhancements

    • Enhanced address properties to include derivation path index.
  • Refactor

    • Updated coin selection logic and types used in chanfunding.
  • Bug Fixes

    • Corrected the weight estimation of PSBT inputs.
  • Documentation

    • Updated release notes to reflect new features and improvements.

guggero avatar Jan 12 '24 17:01 guggero

[!NOTE]

Reviews Paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The Lightning Network wallet's configuration has been expanded with a new CoinSelectionStrategy field. Changes across multiple files reflect updates to the coin selection logic, additional struct fields, and the implementation of new functions and methods.

Changes

Files Change Summary
lnwallet/config.go, lnwallet/wallet.go, lnwallet/test/test_interface.go, lnwallet/subrpcserver_config.go Added CoinSelectionStrategy field to Config struct and used wallet.Coin type instead of chanfunding.Coin.
lnwallet/interface.go, lnwallet/mock.go Extended AddressProperty struct and WalletController interface, added DecorateInputs method.
lnwallet/mock.go, lnwallet/wallet.go Updated mockWalletController to include DecorateInputs method, modified FinalizePsbt method to return nil.
lnwallet/test/test_interface.go Added wallet package import, introduced CoinSelectionStrategy field in chanfunding.WalletConfig struct.
lnwallet/wallet.go Updated import statement, modified handleFundingReserveRequest and ListCoins functions, updated CoinFromOutPoint function.

Poem

Amidst the code's dance, where changes brew,
A rabbit hopped by, with a strategy anew.
Coins selected, with logic refined,
Lightning strikes, a wallet's design. ⚡

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

coderabbitai[bot] avatar Jan 18 '24 15:01 coderabbitai[bot]

Fixed up a bunch of things and added unit and integration tests. Ready for full review now, thought I might still add more test cases to the PR later on.

guggero avatar Jan 18 '24 15:01 guggero

@coderabbitai review

dstadulis avatar Jan 18 '24 21:01 dstadulis

@coderabbitai pause

guggero avatar Jan 31 '24 14:01 guggero

Rebased and added a new lncli subcommand: lncli wallet psbt fundtemplate that hooks into the new funding option (was easier to create a new command than having multiple flags that are only valid in certain combinations.

guggero avatar Feb 06 '24 11:02 guggero

@roasbeef: review reminder @morehouse: review reminder @guggero, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar Feb 20 '24 11:02 lightninglabs-deploy

Needs a rebase!

Also will double check that comment I made fee estimation being wrong for P2TR channels, as it is (?) assuming P2WSH is used for the funding output.

Roasbeef avatar Feb 23 '24 01:02 Roasbeef

@Roasbeef I rebased and addressed your comments. The address list now returns the full derivation path and public key for each address.

guggero avatar Feb 23 '24 10:02 guggero