Skip to content

Return P2WSH script pubkey for keyed anchor prevouts#4669

Open
tnull wants to merge 1 commit into
lightningdevkit:mainfrom
tnull:2026-06-anchor-previous-utxo-p2wsh
Open

Return P2WSH script pubkey for keyed anchor prevouts#4669
tnull wants to merge 1 commit into
lightningdevkit:mainfrom
tnull:2026-06-anchor-previous-utxo-p2wsh

Conversation

@tnull

@tnull tnull commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

AnchorDescriptor::previous_utxo is used for coin selection and PSBT witness_utxo metadata. For keyed anchors it should describe the on-chain P2WSH anchor output instead of the witness script so wallets can validate and sign the package.

Co-Authored-By: HAL 9000

This finding was discovered by Project Loupe

AnchorDescriptor::previous_utxo is used for coin selection and PSBT witness_utxo metadata. For keyed anchors it should describe the on-chain P2WSH anchor output instead of the witness script so wallets can validate and sign the package.

Co-Authored-By: HAL 9000

This finding was discovered by Project Loupe
@ldk-reviews-bot

ldk-reviews-bot commented Jun 10, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @tankyleo as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-claude-review-bot

Copy link
Copy Markdown
Collaborator

I've reviewed the change. It's a focused bug fix: previous_utxo() for keyed anchors previously returned the bare redeemscript as the script_pubkey, but the actual on-chain anchor output is a P2WSH (confirmed at chan_utils.rs:2343 and onchaintx.rs:710). The .to_p2wsh() addition makes the witness_utxo metadata and coin-selection prevout match the real output being spent. The anchor signature is computed separately via tx_input_witness/sign_holder_keyed_anchor_input over the redeemscript, so this doesn't affect signing.

The test uses holder_pubkeys.funding_pubkey, which matches as_holder_broadcastable().broadcaster_pubkeys().funding_pubkey used internally, and follows existing test patterns.

No issues found.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants