From fc0d7061ac58a73479efba9ebeaee78c4a5659c4 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Wed, 11 Oct 2023 17:27:48 -0700 Subject: [PATCH] Restore any missing psbt metadata that resource constrained signers strip Fixes ([#6764]) Changelog-Fixed: Restore any missing metadata that resource constrained signers stripped --- wallet/walletrpc.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 198bfb559344..c3af8545fdef 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -799,15 +799,32 @@ static struct command_result *json_signpsbt(struct command *cmd, "HSM gave bad sign_withdrawal_reply %s", tal_hex(tmpctx, msg)); - if (!psbt_set_version(signed_psbt, psbt_version)) { + /* Some signers (VLS) prune the input.utxo data as it's used + * because it is too large to store. We can restore this + * metadata by combining the signed psbt back into a clone of + * the original psbt. */ + struct wally_psbt *combined_psbt; + tal_wally_start(); + if (wally_psbt_clone_alloc(psbt, 0, &combined_psbt) != WALLY_OK) + abort(); + if (wally_psbt_combine(combined_psbt, signed_psbt) != WALLY_OK) { + tal_wally_end_onto(cmd, combined_psbt, struct wally_psbt); + return command_fail(cmd, LIGHTNINGD, + "Unable to combine signed psbt: %s", + type_to_string(tmpctx, struct wally_psbt, + signed_psbt)); + } + tal_wally_end_onto(cmd, combined_psbt, struct wally_psbt); + + if (!psbt_set_version(combined_psbt, psbt_version)) { return command_fail(cmd, LIGHTNINGD, "Signed PSBT unable to have version set: %s", type_to_string(tmpctx, struct wally_psbt, - psbt)); + combined_psbt)); } response = json_stream_success(cmd); - json_add_psbt(response, "signed_psbt", signed_psbt); + json_add_psbt(response, "signed_psbt", combined_psbt); return command_success(cmd, response); }