walletrpc+lncli: fix FinalizePsbt for multisig P2WSH, add psbt sign cmd#10584
walletrpc+lncli: fix FinalizePsbt for multisig P2WSH, add psbt sign cmd#10584
Conversation
Summary of ChangesHello @Roasbeef, I'm Gemini Code Assist1! 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 enhances the wallet's Partially Signed Bitcoin Transaction (PSBT) capabilities by addressing a critical bug in multisig P2WSH finalization and introducing a new command-line interface for signing PSBTs. The changes improve the robustness of multisig workflows and provide more granular control over the signing process, particularly for collaborative transaction construction. Highlights
🧠 New Feature in Public Preview: You can now enable Memory 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. Changelog
Activity
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔴 PR Severity: CRITICAL
🔴 Critical (1 file)
🟡 Medium (1 file)
⚪ Test files (1 file, excluded from classification)
AnalysisThis PR modifies critical wallet signing functionality in Why CRITICAL:
Review recommendations:
To override, add a |
FinalizePsbt delegates to the base btcwallet's FinalizePsbt which uses FetchInputInfo (UTXO DB lookup) to identify signable inputs. For multisig P2WSH outputs the wallet doesn't own the script address, so FetchInputInfo fails, the input is skipped, and finalization is attempted with insufficient partial signatures. Fix this by calling SignPsbt (which consults BIP32 derivation info) before delegating to the base wallet's FinalizePsbt. This ensures that any inputs with valid BIP32 derivation paths get signed regardless of whether the UTXO is in the wallet's database. Add a regression test that creates a 2-of-2 multisig P2WSH, adds an external cosigner's partial signature, and verifies that FinalizePsbt successfully signs and finalizes the transaction. Fixes #10575.
Add a new 'lncli wallet psbt sign' subcommand that exposes the existing SignPsbt RPC. This command signs PSBT inputs using BIP32 derivation information without finalizing the transaction, making it useful for multisig workflows where the user needs to add lnd's signature before passing the PSBT to another signer or to the finalize command. Previously, SignPsbt was only available via the gRPC/REST API and had no lncli equivalent. Users working with multisig PSBTs had to use the API directly as a workaround for the FinalizePsbt limitation fixed in the previous commit.
bf9e76f to
6302cf8
Compare
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue with FinalizePsbt for multisig P2WSH inputs by adding a preliminary call to SignPsbt. The change is well-reasoned and accompanied by a thorough regression test. The addition of the lncli wallet psbt sign command is a valuable feature for users performing multisig operations. The overall implementation is solid, with just one minor suggestion to improve adherence to the project's documentation style guide.
| Action: actionDecorator(signPsbt), | ||
| } | ||
|
|
||
| func signPsbt(ctx *cli.Context) error { |
There was a problem hiding this comment.
This function is missing a comment explaining its purpose. According to the LND Style Guide (lines 17-19), every function must be commented, with the comment starting with the function name and being a complete sentence.
| func signPsbt(ctx *cli.Context) error { | |
| // signPsbt is the action for the `lncli wallet psbt sign` command. It | |
| // parses the funded PSBT from the command line, calls the `SignPsbt` RPC, | |
| // and prints the result. | |
| func signPsbt(ctx *cli.Context) error { |
References
- The style guide requires every function to have a comment that starts with the function name and describes its purpose in complete sentences. (link)
Summary
FinalizePsbtto handle multisig P2WSH inputs by callingSignPsbt(which uses BIP32 derivation info) before delegating to the base wallet's finalize logic. Previously,FinalizePsbtrelied solely onFetchInputInfo(UTXO DB lookup) which would skip multisig inputs not owned by the wallet, leading to "Unsupported script type" errors.lncli wallet psbt signcommand that exposes the existingSignPsbtRPC, useful for multisig PSBT workflows where users need to add lnd's signature without finalizing.Fixes #10575.
Test plan
TestFinalize2of2Multisigunit test passes — creates a 2-of-2 multisig P2WSH, adds external cosigner's partial sig, verifiesFinalizePsbtsigns and finalizes successfully, then validates via script engine.TestSignPsbt,TestEstimateInputWeight,TestBip32DerivationFromAddress) continue to pass.lncli wallet psbt signagainst a running node.