Skip to content

Commit

Permalink
dual-fund: update state before checking for 'doneness'
Browse files Browse the repository at this point in the history
If we only add a single input/output for the funding transaction,
 we'll only call openchannel_update once, which results in
a crash because the dest->state will never advance to
MULTIFUNDCHANNEL_UPDATED;

Instead, we update to UPDATED before we check for doneness.
  • Loading branch information
niftynei authored and rustyrussell committed Apr 16, 2021
1 parent ade10e7 commit 9c8ce92
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions plugins/spender/openchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,7 @@ openchannel_update_ok(struct command *cmd,
json_tok_full_len(result),
json_tok_full(buf, result));

/* Should we check that the channel id is correct? */

/* FIXME: check that the channel id is correct? */
done_tok = json_get_member(buf, result, "commitments_secured");
if (!done_tok)
plugin_err(cmd->plugin,
Expand All @@ -708,6 +707,13 @@ openchannel_update_ok(struct command *cmd,
json_tok_full_len(result),
json_tok_full(buf, result));

/* We loop through here several times. We may
* reach an intermediate state however,
* MULTIFUNDCHANNEL_SIGNED_NOT_SECURED, so we only update
* to UPDATED iff we're at the previous state (STARTED) */
if (dest->state == MULTIFUNDCHANNEL_STARTED)
dest->state = MULTIFUNDCHANNEL_UPDATED;

if (done) {
const jsmntok_t *outnum_tok, *close_to_tok;

Expand Down Expand Up @@ -739,12 +745,9 @@ openchannel_update_ok(struct command *cmd,
* state position */
if (dest->state == MULTIFUNDCHANNEL_SIGNED_NOT_SECURED)
dest->state = MULTIFUNDCHANNEL_SIGNED;
else {
assert(dest->state == MULTIFUNDCHANNEL_UPDATED);
else
dest->state = MULTIFUNDCHANNEL_SECURED;
}
} else
dest->state = MULTIFUNDCHANNEL_UPDATED;
}

return openchannel_update_returned(dest);
}
Expand Down

0 comments on commit 9c8ce92

Please sign in to comment.