Skip to content

Commit

Permalink
fundchannel: cancel channel on transaction broadcast error
Browse files Browse the repository at this point in the history
Changelog-Added: fundchannel will now cancel ongoing channel creation when transaction broadcast fails.

Signed-off-by: Antoine Poinsot <[email protected]>
  • Loading branch information
darosior committed Aug 6, 2020
1 parent 06372e1 commit 3c06d42
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions plugins/fundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ static struct command_result *tx_abort(struct command *cmd,
{
struct out_req *req;

/* We stash the error so we can return it after we've cleaned up */
fr->error = json_strdup(fr, buf, error);
/* We stash the error so we can return it after we've cleaned up.
* If one already occured upstream, we keep it instead. */
if (!fr->error)
fr->error = json_strdup(fr, buf, error);

req = jsonrpc_request_start(cmd->plugin, cmd, "txdiscard",
send_prior, send_prior, fr);
Expand All @@ -73,6 +75,24 @@ static struct command_result *tx_abort(struct command *cmd,
return send_outreq(cmd->plugin, req);
}

static struct command_result *channel_abort(struct command *cmd,
const char *buf,
const jsmntok_t *error,
struct funding_req *fr)
{
struct out_req *req;

fr->error = json_strdup(fr, buf, error);

/* After we cancel the channel we need to unreserve the coin reserved with
* `txprepare`. */
req = jsonrpc_request_start(cmd->plugin, cmd, "fundchannel_cancel",
channel_abort, channel_abort, fr);
json_add_string(req->js, "id", node_id_to_hexstr(tmpctx, fr->id));

return send_outreq(cmd->plugin, req);
}

/* We're basically done, we just need to format the output to match
* what the original `fundchannel` returned */
static struct command_result *finish(struct command *cmd,
Expand Down

0 comments on commit 3c06d42

Please sign in to comment.