Browse Source

mfc-psbt: mark all of our inputs as "ours", then only sign those

we only want to sign the inputs that we've reserved via utxopsbt or
fundpsbt. we mark them with a flag (reusing the now defunct max-len
flag is fine), then look for inputs with that flag to pass to signonly
fix-mocks
niftynei 4 years ago
committed by neil saitug
parent
commit
29c3532856
  1. 17
      common/psbt_open.c
  2. 13
      common/psbt_open.h
  3. 15
      plugins/spender/multifundchannel.c

17
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); 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);
}

13
common/psbt_open.h

@ -38,7 +38,7 @@ struct psbt_changeset {
}; };
#define PSBT_TYPE_SERIAL_ID 0x01 #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 /* 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 * @role - the role we should use to select serial parity
*/ */
void psbt_add_serials(struct wally_psbt *psbt, enum tx_role role); 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 */ #endif /* LIGHTNING_COMMON_PSBT_OPEN_H */

15
plugins/spender/multifundchannel.c

@ -915,6 +915,11 @@ mfc_psbt_acquired(struct multifundchannel_command *mfc)
* for the life of the tx */ * for the life of the tx */
psbt_add_serials(mfc->psbt, TX_INITIATOR); 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); return perform_channel_start(mfc);
} }
@ -1522,13 +1527,21 @@ perform_signpsbt(struct multifundchannel_command *mfc)
plugin_log(mfc->cmd->plugin, LOG_DBG, plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": signpsbt.", mfc->id); "mfc %"PRIu64": signpsbt.", mfc->id);
/* FIXME: indicate our inputs with signonly */
req = jsonrpc_request_start(mfc->cmd->plugin, mfc->cmd, req = jsonrpc_request_start(mfc->cmd->plugin, mfc->cmd,
"signpsbt", "signpsbt",
&after_signpsbt, &after_signpsbt,
&mfc_forward_error, &mfc_forward_error,
mfc); mfc);
json_add_psbt(req->js, "psbt", mfc->psbt); 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); return send_outreq(mfc->cmd->plugin, req);
} }

Loading…
Cancel
Save