From 3e19b6c8f55620f125477e6b855b90a681efd042 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 22 Oct 2020 14:31:35 -0500 Subject: [PATCH] mfc-df: after psbt signed, send to openchannel_signed if v2s If there's an v2 destinations, they'll broadcast the tx for us --- plugins/spender/multifundchannel.c | 20 ++++++++++++++++++++ plugins/spender/openchannel.c | 21 +++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 079517ab6..f3c6b7490 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -1566,6 +1566,13 @@ after_signpsbt(struct command *cmd, json_tok_full_len(field), json_tok_full(buf, field)); + if (!psbt_finalize(psbt)) + plugin_err(mfc->cmd->plugin, + "mfc %"PRIu64": Signed PSBT won't finalize" + "%s", mfc->id, + type_to_string(tmpctx, struct wally_psbt, psbt)); + + /* Replace the PSBT. */ tal_free(mfc->psbt); mfc->psbt = tal_steal(mfc, psbt); @@ -1599,10 +1606,23 @@ after_signpsbt(struct command *cmd, */ for (size_t i = 0; i < tal_count(mfc->destinations); ++i) { struct multifundchannel_destination *dest; + enum multifundchannel_state expected_state; + dest = &mfc->destinations[i]; + + /* Check that every dest is in the right state */ + expected_state = dest->protocol == OPEN_CHANNEL ? + MULTIFUNDCHANNEL_SIGNED : MULTIFUNDCHANNEL_COMPLETED; + assert(dest->state == expected_state); + dest->state = MULTIFUNDCHANNEL_DONE; } + /* If there's any v2's, we send the tx via `openchannel_signed` */ + if (dest_count(mfc, OPEN_CHANNEL) > 0) { + return perform_openchannel_signed(mfc); + } + plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64": sendpsbt.", mfc->id); diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 9c287b97d..0e834732d 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -484,25 +484,10 @@ perform_openchannel_signed(struct multifundchannel_command *mfc) "mfc %"PRIu64": parallel `openchannel_signed`.", mfc->id); - /* Check that every dest is in the right state */ - for (size_t i = 0; i < tal_count(mfc->destinations); i++) { - struct multifundchannel_destination *dest; - dest = &mfc->destinations[i]; - if (dest->state != MULTIFUNDCHANNEL_SIGNED) { - // FIXME: these channels are all borked. - redo_multifundchannel(mfc, "openchannel_signed"); - } - } - - if (!psbt_finalize(mfc->psbt)) - plugin_err(mfc->cmd->plugin, - "mfc %"PRIu64": Unable to finalize parent PSBT " - "%s", - type_to_string(tmpctx, struct wally_psbt, - mfc->psbt)); - - mfc->pending = tal_count(mfc->destinations); + mfc->pending = dest_count(mfc, OPEN_CHANNEL); for (size_t i = 0; i < tal_count(mfc->destinations); i++) { + if (mfc->destinations[i].protocol == FUND_CHANNEL) + continue; /* We need to 'port' all of the sigs down to the * destination PSBTs */ update_node_psbt(mfc, mfc->psbt,