tests: add regression tests for withdraw returning unsigned tx#8942
tests: add regression tests for withdraw returning unsigned tx#8942vincenzopalazzo wants to merge 2 commits intoElementsProject:masterfrom
Conversation
Root Cause AnalysisThis is a regression introduced in commit 908f834 ("Update libwally to 0.8.8, support PSBTv2") from 2023-02-01. Before PSBTv2 (pre-
|
ca8ba06 to
5f9abea
Compare
|
@vincenzopalazzo can you resolve the conflicts and clear CI by the end of this week so we can add this to 26.06? Release candidate planned for Monday 11 May. |
5f9abea to
a7f9aae
Compare
|
The tests pass locally for me after the change has been added. The tests are failing on liquid because liquid doesn't support p2tr addresses. You could either change them to bech32 addresses, skip if the network isn't regtest or use the good_addrtype() function. @vincenzopalazzo could you please add this fix? I should be able to merge this after CI is cleared. |
| """ | ||
| Test that withdraw returns a fully signed transaction in the 'tx' field. | ||
|
|
||
| Regression test for https://github.com/ElementsProject/lightning/issues/8701 |
There was a problem hiding this comment.
Could we perhaps reword some of this comment? This comment is a bit verbose, also we don't really want github links through source/test code.
| """ | ||
| Test that withdraw correctly signs close outputs (anchor/P2WSH). | ||
|
|
||
| Regression test for https://github.com/ElementsProject/lightning/issues/8701 |
There was a problem hiding this comment.
If you could remove the github link from this comment as well, that would be great.
Adds two tests to reproduce issue ElementsProject#8701 where the withdraw command returns an unsigned raw transaction in the 'tx' response field: 1. test_withdraw_returns_signed_tx: verifies that withdraw's 'tx' field contains witness data for all inputs (basic wallet UTXOs). 2. test_withdraw_close_output_signed: verifies signing works when withdrawing funds that include channel close outputs (anchor/P2WSH with CSV locks), which was the exact scenario in the reported issue. The root cause is that psbt_txid() uses WALLY_PSBT_EXTRACT_NON_FINAL which strips signatures/witnesses, and the withdraw response returns this unsigned tx instead of the finalized one. Changelog-None Signed-off-by: Vincenzo Palazzo <vincenzopalazzo@member.fsf.org> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The withdraw command was returning an unsigned raw transaction in its 'tx' response field. This happened because signpsbt_done() used psbt_txid() to extract utx->tx, which internally calls wally_psbt_extract() with WALLY_PSBT_EXTRACT_NON_FINAL — stripping all signature and witness data. The broadcast itself succeeded because sendpsbt internally finalizes the PSBT via psbt_final_tx(), but the 'tx' field returned to the user had empty scriptSigs and no witness data. This is a regression from 908f834 ("Update libwally to 0.8.8, support PSBTv2") which rewrote psbt_txid() from manually copying final_scriptsig/redeem_script into the cloned tx, to using wally_psbt_extract(WALLY_PSBT_EXTRACT_NON_FINAL) which strips all signing data by design. Fix by finalizing the signed PSBT in signpsbt_done() and extracting the fully signed transaction via psbt_final_tx(). The txid verification still uses psbt_txid() (which is correct for txid computation since txids exclude witness data). Fixes: ElementsProject#8701 Changelog-Fixed: withdraw now returns a fully signed transaction in the `tx` response field. Signed-off-by: Vincenzo Palazzo <vincenzopalazzo@member.fsf.org> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rustyrussell
left a comment
There was a problem hiding this comment.
Modified to explicitly mark the tests xfail in the first commit (and I checked they do fail!).
a7f9aae to
a1c0613
Compare
Summary
withdrawreturns an unsigned raw transaction in thetxresponse fieldtest_withdraw_returns_signed_tx: verifies witness data exists for all inputs in the returnedtxtest_withdraw_close_output_signed: reproduces the exact scenario from the issue — withdrawing funds that include channel close outputs (anchor/P2WSH with CSV=1)Root Cause Analysis
The
withdrawcommand flow:finish_txprepare→signpsbt→signpsbt_done→sendpsbt→sendpsbt_donesignpsbt_done,psbt_txid()extractsutx->txusingWALLY_PSBT_EXTRACT_NON_FINAL, which strips all signatures/witnessessendpsbtinternally finalizes the PSBT viapsbt_final_tx()sendpsbt_donereturnsutx->tx(the unsigned version) in the responseThe
txfield in thewithdrawresponse is always unsigned. Thepsbtfield is correct.Test plan
test_withdraw_returns_signed_txshould fail on current master (confirming the bug)test_withdraw_close_output_signedshould fail on current master with anchor close outputssignpsbt_doneinplugins/txprepare.cFixes: #8701
🤖 Generated with Claude Code