diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 753316c1e..e746162ff 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -544,6 +544,7 @@ connect_ok(struct command *cmd, json_tok_full_len(features_tok), json_tok_full(buf, features_tok)); + dest->state = MULTIFUNDCHANNEL_CONNECTED; return connect_done(dest); } static struct command_result * @@ -613,10 +614,10 @@ after_multiconnect(struct multifundchannel_command *mfc) dest = &mfc->destinations[i]; - assert(dest->state == MULTIFUNDCHANNEL_START_NOT_YET - || dest->state == MULTIFUNDCHANNEL_CONNECT_FAILED); + assert(dest->state == MULTIFUNDCHANNEL_CONNECTED + || dest->state == MULTIFUNDCHANNEL_FAILED); - if (dest->state != MULTIFUNDCHANNEL_CONNECT_FAILED) + if (dest->state != MULTIFUNDCHANNEL_FAILED) continue; /* One of them failed, oh no. */ @@ -1162,9 +1163,9 @@ after_fundchannel_start(struct multifundchannel_command *mfc) dest = &mfc->destinations[i]; assert(dest->state == MULTIFUNDCHANNEL_STARTED - || dest->state == MULTIFUNDCHANNEL_START_FAILED); + || dest->state == MULTIFUNDCHANNEL_FAILED); - if (dest->state != MULTIFUNDCHANNEL_START_FAILED) + if (dest->state != MULTIFUNDCHANNEL_FAILED) continue; /* One of them failed, oh no. */ @@ -1384,6 +1385,7 @@ fundchannel_complete_ok(struct command *cmd, json_tok_full(buf, result)); json_to_channel_id(buf, channel_id_tok, &dest->channel_id); + dest->state = MULTIFUNDCHANNEL_COMPLETED; return fundchannel_complete_done(dest); } static struct command_result * @@ -1454,10 +1456,10 @@ after_fundchannel_complete(struct multifundchannel_command *mfc) dest = &mfc->destinations[i]; - assert(dest->state == MULTIFUNDCHANNEL_STARTED - || dest->state == MULTIFUNDCHANNEL_COMPLETE_FAILED); + assert(dest->state == MULTIFUNDCHANNEL_COMPLETED + || dest->state == MULTIFUNDCHANNEL_FAILED); - if (dest->state != MULTIFUNDCHANNEL_COMPLETE_FAILED) + if (dest->state != MULTIFUNDCHANNEL_FAILED) continue; /* One of them failed, oh no. */ @@ -1694,23 +1696,7 @@ redo_multifundchannel(struct multifundchannel_command *mfc, /* Return true if this destination failed, false otherwise. */ static bool dest_failed(struct multifundchannel_destination *dest) { - switch (dest->state) { - case MULTIFUNDCHANNEL_START_NOT_YET: - case MULTIFUNDCHANNEL_STARTED: - case MULTIFUNDCHANNEL_DONE: - return false; - - case MULTIFUNDCHANNEL_CONNECT_FAILED: - case MULTIFUNDCHANNEL_START_FAILED: - case MULTIFUNDCHANNEL_COMPLETE_FAILED: - return true; - case MULTIFUNDCHANNEL_FAILED: - case MULTIFUNDCHANNEL_SECURED: - case MULTIFUNDCHANNEL_UPDATED: - case MULTIFUNDCHANNEL_SIGNED: - abort(); // FIXME, for openchannel - } - abort(); + return dest->state == MULTIFUNDCHANNEL_FAILED; } void fail_destination(struct multifundchannel_destination *dest, diff --git a/plugins/spender/multifundchannel.h b/plugins/spender/multifundchannel.h index 07d3005ad..f53a15293 100644 --- a/plugins/spender/multifundchannel.h +++ b/plugins/spender/multifundchannel.h @@ -20,21 +20,28 @@ enum channel_protocol { enum multifundchannel_state { /* We have not yet performed `fundchannel_start`. */ MULTIFUNDCHANNEL_START_NOT_YET = 0, - /* The `connect` command failed. `*/ - MULTIFUNDCHANNEL_CONNECT_FAILED, - /* The `fundchannel_start` command succeeded. */ + /* The `connect` command succeeded. `*/ + MULTIFUNDCHANNEL_CONNECTED, + + /* The `fundchannel_start` or `openchannel_init` command + * succeeded. */ MULTIFUNDCHANNEL_STARTED, - /* The `fundchannel_start` command failed. */ - MULTIFUNDCHANNEL_START_FAILED, - /* The `fundchannel_complete` command failed. */ - MULTIFUNDCHANNEL_COMPLETE_FAILED, - /* The transaction might now be broadcasted. */ - MULTIFUNDCHANNEL_DONE, - /* FIXME: clean up for interleaved handling */ + /* V1 states */ + /* The `fundchannel_complete` command succeeded. */ + MULTIFUNDCHANNEL_COMPLETED, + + /* V2 states */ + /* The `openchannel_update` command succeeded. */ MULTIFUNDCHANNEL_UPDATED, + /* The commitments for this destinations have been secured */ MULTIFUNDCHANNEL_SECURED, + /* We've recieved the peer sigs for this destination */ MULTIFUNDCHANNEL_SIGNED, + + /* The transaction might now be broadcasted. */ + MULTIFUNDCHANNEL_DONE, + /* Global fail state. Oops */ MULTIFUNDCHANNEL_FAILED, }; diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 8823d51ff..ec2f66618 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -926,9 +926,9 @@ after_openchannel_init(struct multifundchannel_command *mfc) dest = &mfc->destinations[i]; assert(dest->state == MULTIFUNDCHANNEL_STARTED - || dest->state == MULTIFUNDCHANNEL_START_FAILED); + || dest->state == MULTIFUNDCHANNEL_FAILED); - if (dest->state != MULTIFUNDCHANNEL_START_FAILED) + if (dest->state != MULTIFUNDCHANNEL_FAILED) continue; /* One of them failed, oh no. */