Skip to content

Commit c0ce96a

Browse files
committed
WIP: relax psbt_has_required_fields, psbt debugging
1 parent 9b63958 commit c0ce96a

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

common/psbt_open.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,33 +379,54 @@ u64 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role)
379379
return serial_id;
380380
}
381381

382+
#include <stdio.h>
383+
#include <common/type_to_string.h>
384+
382385
bool psbt_has_required_fields(struct wally_psbt *psbt)
383386
{
387+
psbt_set_version(psbt, 0);
388+
fprintf(stderr, "wally_psbt: %s\n", type_to_string(tmpctx, struct wally_psbt, psbt));
389+
psbt_set_version(psbt, 2);
390+
384391
u64 serial_id;
385392
for (size_t i = 0; i < psbt->num_inputs; i++) {
386393
const struct wally_map_item *redeem_script;
387394
struct wally_psbt_input *input = &psbt->inputs[i];
388395

389-
if (!psbt_get_serial_id(&input->unknowns, &serial_id))
396+
if (!psbt_get_serial_id(&input->unknowns, &serial_id)) {
397+
fprintf(stderr, "in[%ld]: missing serial id\n", i);
390398
return false;
399+
}
391400

392401
/* Required because we send the full tx over the wire now */
393-
if (!input->utxo)
402+
/* Only insist on PSBT_IN_NON_WITNESS_UTXO (.utxo) if
403+
* PSBT_IN_WITNESS_UTXO (.witness_utxo) is not present
404+
* because PSBT_IN_NON_WITNESS_UTXO uses a lot of
405+
* memory */
406+
if (!input->witness_utxo && !input->utxo) {
407+
fprintf(stderr, "in[%ld]: missing both utxo\n", i);
394408
return false;
409+
}
395410

396-
/* If is P2SH, redeemscript must be present */
397-
assert(psbt->inputs[i].index < input->utxo->num_outputs);
398-
const u8 *outscript =
399-
wally_tx_output_get_script(tmpctx,
400-
&input->utxo->outputs[psbt->inputs[i].index]);
401-
redeem_script = wally_map_get_integer(&psbt->inputs[i].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04);
402-
if (is_p2sh(outscript, NULL) && (!redeem_script || redeem_script->value_len == 0))
403-
return false;
411+
if (input->utxo) {
412+
/* If is P2SH, redeemscript must be present */
413+
assert(psbt->inputs[i].index < input->utxo->num_outputs);
414+
const u8 *outscript =
415+
wally_tx_output_get_script(tmpctx,
416+
&input->utxo->outputs[psbt->inputs[i].index]);
417+
redeem_script = wally_map_get_integer(&psbt->inputs[i].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04);
418+
if (is_p2sh(outscript, NULL) && (!redeem_script || redeem_script->value_len == 0)) {
419+
fprintf(stderr, "in[%ld]: missing redeemscript\n", i);
420+
return false;
421+
}
422+
}
404423
}
405424

406425
for (size_t i = 0; i < psbt->num_outputs; i++) {
407-
if (!psbt_get_serial_id(&psbt->outputs[i].unknowns, &serial_id))
426+
if (!psbt_get_serial_id(&psbt->outputs[i].unknowns, &serial_id)) {
427+
fprintf(stderr, "out[%ld]: missing serial id\n", i);
408428
return false;
429+
}
409430
}
410431

411432
return true;

wallet/walletrpc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static struct command_result *param_input_numbers(struct command *cmd,
734734
return NULL;
735735
}
736736

737+
#include<stdio.h>
738+
737739
static struct command_result *json_signpsbt(struct command *cmd,
738740
const char *buffer,
739741
const jsmntok_t *obj UNNEEDED,
@@ -801,6 +803,7 @@ static struct command_result *json_signpsbt(struct command *cmd,
801803
"HSM gave bad sign_withdrawal_reply %s",
802804
tal_hex(tmpctx, msg));
803805

806+
fprintf(stderr, "json_signpsbt: psbt_set_version %d\n", psbt_version);
804807
if (!psbt_set_version(signed_psbt, psbt_version)) {
805808
return command_fail(cmd, LIGHTNINGD,
806809
"Signed PSBT unable to have version set: %s",

0 commit comments

Comments
 (0)