From d7c06b5b0e888a30d0b448418bc1473fe1805705 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 22 Oct 2020 14:23:45 -0500 Subject: [PATCH] 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) --- plugins/spender/multifundchannel.c | 19 +++++++++++++------ plugins/spender/openchannel.c | 8 +++++--- plugins/spender/openchannel.h | 3 +++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 88eb7be09..3d58ac789 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -1340,10 +1340,12 @@ perform_fundchannel_complete(struct multifundchannel_command *mfc) "mfc %"PRIu64": parallel fundchannel_complete.", mfc->id); - mfc->pending = tal_count(mfc->destinations); + mfc->pending = dest_count(mfc, FUND_CHANNEL); - for (i = 0; i < tal_count(mfc->destinations); ++i) - fundchannel_complete_dest(&mfc->destinations[i]); + for (i = 0; i < tal_count(mfc->destinations); ++i) { + if (mfc->destinations[i].protocol == FUND_CHANNEL) + fundchannel_complete_dest(&mfc->destinations[i]); + } assert(mfc->pending != 0); return command_still_pending(mfc->cmd); @@ -1466,7 +1468,7 @@ fundchannel_complete_done(struct multifundchannel_destination *dest) } static struct command_result * -perform_sendpsbt(struct multifundchannel_command *mfc); +perform_signpsbt(struct multifundchannel_command *mfc); static struct command_result * after_fundchannel_complete(struct multifundchannel_command *mfc) @@ -1482,6 +1484,8 @@ after_fundchannel_complete(struct multifundchannel_command *mfc) struct multifundchannel_destination *dest; dest = &mfc->destinations[i]; + if (dest->protocol != FUND_CHANNEL) + continue; assert(dest->state == MULTIFUNDCHANNEL_COMPLETED || dest->state == MULTIFUNDCHANNEL_FAILED); @@ -1493,7 +1497,10 @@ after_fundchannel_complete(struct multifundchannel_command *mfc) 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); static struct command_result * -perform_sendpsbt(struct multifundchannel_command *mfc) +perform_signpsbt(struct multifundchannel_command *mfc) { struct out_req *req; diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 0397ef116..fa7d6f067 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -583,8 +583,8 @@ collect_sigs(struct multifundchannel_command *mfc) return send_outreq(mfc->cmd->plugin, req); } -static void -openchannel_dest_signed(struct multifundchannel_command *mfc) +struct command_result * +check_sigs_ready(struct multifundchannel_command *mfc) { bool ready = true; for (size_t i = 0; i < tal_count(mfc->destinations); i++) @@ -593,6 +593,8 @@ openchannel_dest_signed(struct multifundchannel_command *mfc) if (ready) collect_sigs(mfc); + + return command_still_pending(mfc->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); dest->state = MULTIFUNDCHANNEL_SIGNED; - openchannel_dest_signed(dest->mfc); + check_sigs_ready(dest->mfc); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* diff --git a/plugins/spender/openchannel.h b/plugins/spender/openchannel.h index 756589d19..a6191ff33 100644 --- a/plugins/spender/openchannel.h +++ b/plugins/spender/openchannel.h @@ -21,4 +21,7 @@ void openchannel_init(struct plugin *p, const char *b, struct command_result * perform_openchannel_update(struct multifundchannel_command *mfc); +struct command_result * +check_sigs_ready(struct multifundchannel_command *mfc); + #endif /* LIGHTNING_PLUGINS_SPENDER_OPENCHANNEL_H */