Browse Source

mfc-df: once we've gotten the PSBT finalized, we wait for peer sigs

We need our peer's signatures to arrive before we sign/broadcast the
funding transaction (but only if there's v2 peers present)
fix-mocks
niftynei 4 years ago
committed by neil saitug
parent
commit
d7c06b5b0e
  1. 19
      plugins/spender/multifundchannel.c
  2. 8
      plugins/spender/openchannel.c
  3. 3
      plugins/spender/openchannel.h

19
plugins/spender/multifundchannel.c

@ -1340,10 +1340,12 @@ perform_fundchannel_complete(struct multifundchannel_command *mfc)
"mfc %"PRIu64": parallel fundchannel_complete.", "mfc %"PRIu64": parallel fundchannel_complete.",
mfc->id); mfc->id);
mfc->pending = tal_count(mfc->destinations); mfc->pending = dest_count(mfc, FUND_CHANNEL);
for (i = 0; i < tal_count(mfc->destinations); ++i) for (i = 0; i < tal_count(mfc->destinations); ++i) {
fundchannel_complete_dest(&mfc->destinations[i]); if (mfc->destinations[i].protocol == FUND_CHANNEL)
fundchannel_complete_dest(&mfc->destinations[i]);
}
assert(mfc->pending != 0); assert(mfc->pending != 0);
return command_still_pending(mfc->cmd); return command_still_pending(mfc->cmd);
@ -1466,7 +1468,7 @@ fundchannel_complete_done(struct multifundchannel_destination *dest)
} }
static struct command_result * static struct command_result *
perform_sendpsbt(struct multifundchannel_command *mfc); perform_signpsbt(struct multifundchannel_command *mfc);
static struct command_result * static struct command_result *
after_fundchannel_complete(struct multifundchannel_command *mfc) after_fundchannel_complete(struct multifundchannel_command *mfc)
@ -1482,6 +1484,8 @@ after_fundchannel_complete(struct multifundchannel_command *mfc)
struct multifundchannel_destination *dest; struct multifundchannel_destination *dest;
dest = &mfc->destinations[i]; dest = &mfc->destinations[i];
if (dest->protocol != FUND_CHANNEL)
continue;
assert(dest->state == MULTIFUNDCHANNEL_COMPLETED assert(dest->state == MULTIFUNDCHANNEL_COMPLETED
|| dest->state == MULTIFUNDCHANNEL_FAILED); || dest->state == MULTIFUNDCHANNEL_FAILED);
@ -1493,7 +1497,10 @@ after_fundchannel_complete(struct multifundchannel_command *mfc)
return redo_multifundchannel(mfc, "fundchannel_complete"); return redo_multifundchannel(mfc, "fundchannel_complete");
} }
return perform_sendpsbt(mfc); if (dest_count(mfc, OPEN_CHANNEL) > 0)
return check_sigs_ready(mfc);
return perform_signpsbt(mfc);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -1509,7 +1516,7 @@ after_signpsbt(struct command *cmd,
struct multifundchannel_command *mfc); struct multifundchannel_command *mfc);
static struct command_result * static struct command_result *
perform_sendpsbt(struct multifundchannel_command *mfc) perform_signpsbt(struct multifundchannel_command *mfc)
{ {
struct out_req *req; struct out_req *req;

8
plugins/spender/openchannel.c

@ -583,8 +583,8 @@ collect_sigs(struct multifundchannel_command *mfc)
return send_outreq(mfc->cmd->plugin, req); return send_outreq(mfc->cmd->plugin, req);
} }
static void struct command_result *
openchannel_dest_signed(struct multifundchannel_command *mfc) check_sigs_ready(struct multifundchannel_command *mfc)
{ {
bool ready = true; bool ready = true;
for (size_t i = 0; i < tal_count(mfc->destinations); i++) for (size_t i = 0; i < tal_count(mfc->destinations); i++)
@ -593,6 +593,8 @@ openchannel_dest_signed(struct multifundchannel_command *mfc)
if (ready) if (ready)
collect_sigs(mfc); collect_sigs(mfc);
return command_still_pending(mfc->cmd);
} }
static void json_peer_sigs(struct command *cmd, static void json_peer_sigs(struct command *cmd,
@ -667,7 +669,7 @@ static void json_peer_sigs(struct command *cmd,
tal_wally_end(dest->mfc->psbt); tal_wally_end(dest->mfc->psbt);
dest->state = MULTIFUNDCHANNEL_SIGNED; dest->state = MULTIFUNDCHANNEL_SIGNED;
openchannel_dest_signed(dest->mfc); check_sigs_ready(dest->mfc);
} }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

3
plugins/spender/openchannel.h

@ -21,4 +21,7 @@ void openchannel_init(struct plugin *p, const char *b,
struct command_result * struct command_result *
perform_openchannel_update(struct multifundchannel_command *mfc); perform_openchannel_update(struct multifundchannel_command *mfc);
struct command_result *
check_sigs_ready(struct multifundchannel_command *mfc);
#endif /* LIGHTNING_PLUGINS_SPENDER_OPENCHANNEL_H */ #endif /* LIGHTNING_PLUGINS_SPENDER_OPENCHANNEL_H */

Loading…
Cancel
Save