lnd icon indicating copy to clipboard operation
lnd copied to clipboard

[feature]: add specific change address for send coin RPCs #10271

Open murraystewart96 opened this issue 6 months ago • 6 comments

Change Description

https://github.com/lightningnetwork/lnd/issues/10271

Adds a change_address field to SendCoins, SendMany, and WalletKit.SendOutputs, allowing callers to pin the change output to a specific address rather than a wallet-derived one.

The field is mutually exclusive with send_all on SendCoins and the --sweepall flag on sendcoins.

Depends on btcwallet changes to support a custom change address at the transaction creation layer:

Issue: https://github.com/btcsuite/btcwallet/issues/1234 PR: https://github.com/btcsuite/btcwallet/pull/1235

Steps to Test

go test ./lnwallet/test/btcd/ -v -run "TestLightningWallet/btcwallet/btcd:create_simple_tx_change_addr"

NOTE: This will fail until the btcwallet PR has been merged and the new version has been brought into this repo

Pull Request Checklist

Testing

  • [ ] Your PR passes all CI checks.
  • [ ] Tests covering the positive and negative (error paths) are included.
  • [ ] Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

murraystewart96 avatar May 17 '26 09:05 murraystewart96

Summary of Changes

Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the ability to pin the change output of on-chain transactions to a specific address. By extending the RPC and internal wallet interfaces, callers can now explicitly define where change UTXOs should be sent. This feature includes robust validation to prevent invalid or dangerous address usage and ensures compatibility with existing wallet logic, such as the reserve requirement mechanism.

Highlights

  • Custom Change Address Support: Added a 'change_address' field to SendCoins, SendMany, and WalletKit.SendOutputs, allowing users to specify a destination for change UTXOs instead of using a wallet-derived address.
  • Validation and Safety: Implemented strict validation for the custom change address, including network compatibility checks and prevention of sending to raw public keys. Added mutual exclusivity checks to ensure 'change_address' cannot be used alongside 'sweepall' or 'send_all'.
  • Interface Updates: Updated the internal WalletController interface and its implementations (BtcWallet, RPCKeyRing, and mocks) to propagate the optional change address through the transaction creation pipeline.
  • Testing: Added a new integration test 'testCreateSimpleTxChangeAddr' to verify that transactions correctly route change to the user-provided address.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist avatar May 17 '26 09:05 gemini-code-assist

🔴 PR Severity: CRITICAL

Automated classification | 11 files (non-generated, non-test) | ~275 lines changed

🔴 Critical (5 files)
  • lnwallet/btcwallet/btcwallet.go - wallet operations implementation in lnwallet/*
  • lnwallet/interface.go - wallet interface definition in lnwallet/*
  • lnwallet/mock.go - wallet mock in lnwallet/* package
  • lnwallet/rpcwallet/rpcwallet.go - remote signer wallet implementation in lnwallet/*
  • rpcserver.go - core server coordination
🟠 High (2 files)
  • lnrpc/walletrpc/walletkit_server.go - wallet RPC server implementation
  • lnrpc/lightning.swagger.json - API surface changes
🟡 Medium (3 files)
  • cmd/commands/commands.go - CLI client commands
  • lnrpc/lightning.proto - Lightning RPC API definition
  • lnrpc/walletrpc/walletkit.proto - Wallet RPC API definition
⚪ Excluded from counting (3 files)
  • lnrpc/lightning.pb.go - auto-generated (*.pb.go)
  • lnrpc/walletrpc/walletkit.pb.go - auto-generated (*.pb.go)
  • lntest/mock/walletcontroller.go - test file (lntest/*)

Analysis

This PR is classified as CRITICAL because it touches multiple files in lnwallet/* (wallet operations, channel funding, signing, commitment transactions) and rpcserver.go (core server coordination) — both of which are in the highest severity tier.

The changes appear to modify wallet interface signatures and their implementations across lnwallet/interface.go, lnwallet/btcwallet/btcwallet.go, and lnwallet/rpcwallet/rpcwallet.go, with corresponding updates propagated to the RPC layer (lnrpc/) and wired into the main rpcserver.go. Changes to wallet interface contracts and the core RPC server require expert review to ensure correctness of fund management, signing logic, and API compatibility.

No severity bump thresholds were triggered (11 non-generated/non-test files, ~275 lines changed — both below the bump thresholds of 20 files / 500 lines).


To override, add a severity-override-{critical,high,medium,low} label. <!-- pr-severity-bot -->

github-actions[bot] avatar May 17 '26 09:05 github-actions[bot]

LGTM!

Great implementation and solid test coverage. Love the defense-in-depth handling of the mutual exclusion rules across the CLI and RPC layers. Clean work!

One small piece of feedback on the Git history: It would be awesome if you could squash or clean up some of these commits before merging. Grouping related changes together or amending the original commits instead of adding small follow-up fix commits makes it a lot easier for reviewers to follow the pipeline.

TechLateef avatar May 24 '26 08:05 TechLateef

@TechLateef Thank you for the feedback! I have tidied up the git history.

The only thing is I don't think we will be able to merge this until this feature is added:

Issue: https://github.com/btcsuite/btcwallet/issues/1234 PR: https://github.com/btcsuite/btcwallet/pull/1235

Hopefully I can get some traction on it soon.

murraystewart96 avatar Jun 01 '26 16:06 murraystewart96

I should be able to merge the blocking PR - https://github.com/btcsuite/btcwallet/pull/1235 When the btcwallet refactor is complete.

They are aiming for July 1st https://github.com/btcsuite/btcwallet/milestone/3

murraystewart96 avatar Jun 06 '26 13:06 murraystewart96

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

litbot-9000 avatar Jun 29 '26 02:06 litbot-9000