diff --git a/common/psbt_open.c b/common/psbt_open.c index 181e2b683..c8b83cce9 100644 --- a/common/psbt_open.c +++ b/common/psbt_open.c @@ -464,3 +464,20 @@ void psbt_add_serials(struct wally_psbt *psbt, enum tx_role role) psbt_output_set_serial_id(psbt, &psbt->outputs[i], serial_id); } } + +void psbt_input_mark_ours(const tal_t *ctx, + struct wally_psbt_input *input) +{ + u8 *key = psbt_make_key(tmpctx, PSBT_TYPE_INPUT_MARKER, NULL); + beint16_t bev = cpu_to_be16(1); + + psbt_input_set_unknown(ctx, input, key, &bev, sizeof(bev)); +} + +bool psbt_input_is_ours(const struct wally_psbt_input *input) +{ + size_t unused; + void *result = psbt_get_lightning(&input->unknowns, + PSBT_TYPE_INPUT_MARKER, &unused); + return !(!result); +} diff --git a/common/psbt_open.h b/common/psbt_open.h index fc25a3073..f6bc07eb3 100644 --- a/common/psbt_open.h +++ b/common/psbt_open.h @@ -38,7 +38,7 @@ struct psbt_changeset { }; #define PSBT_TYPE_SERIAL_ID 0x01 -#define PSBT_TYPE_MAX_WITNESS_LEN 0x02 +#define PSBT_TYPE_INPUT_MARKER 0x02 /* psbt_get_serial_id - Returns the serial_id from an unknowns map * @@ -163,4 +163,15 @@ bool psbt_side_finalized(const struct wally_psbt *psbt, * @role - the role we should use to select serial parity */ void psbt_add_serials(struct wally_psbt *psbt, enum tx_role role); + +/* psbt_input_mark_ours - Sets the PSBT_TYPE_INPUT_MARKER on this input + */ +void psbt_input_mark_ours(const tal_t *ctx, + struct wally_psbt_input *input); + +/* psbt_input_is_ours - Returns true if this psbt input has + * the PSBT_TYPE_INPUT_MARKER set on it. + */ +bool psbt_input_is_ours(const struct wally_psbt_input *input); + #endif /* LIGHTNING_COMMON_PSBT_OPEN_H */ diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 0a76b52ff..ea0bacf23 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -915,6 +915,11 @@ mfc_psbt_acquired(struct multifundchannel_command *mfc) * for the life of the tx */ psbt_add_serials(mfc->psbt, TX_INITIATOR); + /* We also mark all of our inputs as *ours*, so we + * can easily identify them for `signpsbt`, later */ + for (size_t i = 0; i < mfc->psbt->num_inputs; i++) + psbt_input_mark_ours(mfc->psbt, &mfc->psbt->inputs[i]); + return perform_channel_start(mfc); } @@ -1522,13 +1527,21 @@ perform_signpsbt(struct multifundchannel_command *mfc) plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64": signpsbt.", mfc->id); - /* FIXME: indicate our inputs with signonly */ req = jsonrpc_request_start(mfc->cmd->plugin, mfc->cmd, "signpsbt", &after_signpsbt, &mfc_forward_error, mfc); json_add_psbt(req->js, "psbt", mfc->psbt); + + /* Use input markers to identify which inputs + * are ours, only sign those */ + json_array_start(req->js, "signonly"); + for (size_t i = 0; i < mfc->psbt->num_inputs; i++) { + if (psbt_input_is_ours(&mfc->psbt->inputs[i])) + json_add_num(req->js, NULL, i); + } + json_array_end(req->js); return send_outreq(mfc->cmd->plugin, req); }