From d882a38619ea38f3f9b60869e6bb0eb3947a1d9c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 29 Jun 2023 09:44:09 +0930 Subject: [PATCH] plugin: make sure multifundchannel / fundchannel unreserve correctly on failure. We were marking our inputs very late, which means any early failure would not know to unreserve them. This becomes particularly bad when we start enforcing emergency reserves. Signed-off-by: Rusty Russell --- plugins/spender/multifundchannel.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index e054f5b57..d8a9d60d5 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -1203,11 +1203,6 @@ 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); } @@ -1372,6 +1367,10 @@ after_fundpsbt(struct command *cmd, if (!psbt_set_version(mfc->psbt, 2)) goto fail; + /* Mark our inputs now, so we unreserve correctly on failure! */ + for (size_t i = 0; i < mfc->psbt->num_inputs; i++) + psbt_input_mark_ours(mfc->psbt, &mfc->psbt->inputs[i]); + field = json_get_member(buf, result, "feerate_per_kw"); if (!field || !json_to_u32(buf, field, &mfc->feerate_per_kw)) goto fail;