mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-05 23:24:21 +01:00
df: finalize redeemscript at the same time as witness stack
libwally has a quirk where the finalize method will fail to 'completely' finalize an input's parts if either the final_scriptsig or final_redeemscript fields are set since we manually set the final_witness stack here, we also need to fully finalize the redeemscript -> final_scriptsig here as well.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
#include "common/psbt_internal.h"
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/ccan/tal/tal.h>
|
||||
#include <common/psbt_open.h>
|
||||
#include <wally_psbt.h>
|
||||
#include <wire/peer_wire.h>
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
void psbt_input_set_final_witness_stack(const tal_t *ctx,
|
||||
struct wally_psbt_input *in,
|
||||
const struct witness_element **elements)
|
||||
static void
|
||||
psbt_input_set_final_witness_stack(const tal_t *ctx,
|
||||
struct wally_psbt_input *in,
|
||||
const struct witness_element **elements)
|
||||
{
|
||||
tal_wally_start();
|
||||
wally_tx_witness_stack_init_alloc(tal_count(elements),
|
||||
@@ -19,6 +22,34 @@ void psbt_input_set_final_witness_stack(const tal_t *ctx,
|
||||
tal_wally_end(ctx);
|
||||
}
|
||||
|
||||
void psbt_finalize_input(const tal_t *ctx,
|
||||
struct wally_psbt_input *in,
|
||||
const struct witness_element **elements)
|
||||
{
|
||||
psbt_input_set_final_witness_stack(ctx, in, elements);
|
||||
|
||||
/* There's this horrible edgecase where we set the final_witnesses
|
||||
* directly onto the PSBT, but the input is a P2SH-wrapped input
|
||||
* (which has redeemscripts that belong in the scriptsig). Because
|
||||
* of how the internal libwally stuff works calling 'finalize'
|
||||
* on these just .. ignores it!? Murder. Anyway, here we do a final
|
||||
* scriptsig check -- if there's a redeemscript field still around we
|
||||
* just go ahead and mush it into the final_scriptsig field. */
|
||||
if (in->redeem_script) {
|
||||
u8 *redeemscript = tal_dup_arr(NULL, u8,
|
||||
in->redeem_script,
|
||||
in->redeem_script_len, 0);
|
||||
in->final_scriptsig =
|
||||
bitcoin_scriptsig_redeem(NULL,
|
||||
take(redeemscript));
|
||||
in->final_scriptsig_len =
|
||||
tal_bytelen(in->final_scriptsig);
|
||||
|
||||
in->redeem_script = tal_free(in->redeem_script);
|
||||
in->redeem_script_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const struct witness_stack **
|
||||
psbt_to_witness_stacks(const tal_t *ctx,
|
||||
const struct wally_psbt *psbt,
|
||||
|
||||
Reference in New Issue
Block a user