Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fundchannel: cancel channel on transaction broadcast error #3910

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 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",
tx_abort, tx_abort, fr);
json_add_string(req->js, "id", node_id_to_hexstr(tmpctx, fr->id));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json_add_string(req->js, "id", node_id_to_hexstr(tmpctx, fr->id));
json_add_node_id(req->js, "id", 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 Expand Up @@ -113,7 +133,7 @@ static struct command_result *send_tx(struct command *cmd,
fr->chanstr = json_strdup(fr, buf, tok);

req = jsonrpc_request_start(cmd->plugin, cmd, "txsend",
finish, tx_abort, fr);
finish, channel_abort, fr);
json_add_string(req->js, "txid",
type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id));

Expand Down Expand Up @@ -409,6 +429,7 @@ static struct command_result *json_fundchannel(struct command *cmd,
return command_param_failed();

fr->funding_all = streq(fr->funding_str, "all");
fr->error = NULL;

return connect_to_peer(cmd, fr);
}
Expand Down