From f155c61bdf598521bc23a4f15eecd2098dfab035 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Wed, 28 Aug 2019 15:54:59 -0500 Subject: [PATCH] fundchannel: cancel the fundchannel request if error If txprepare hits an error, we need to cancel the pending request with our peer. --- plugins/fundchannel.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/fundchannel.c b/plugins/fundchannel.c index 43f633ee4..0b3bac3ef 100644 --- a/plugins/fundchannel.c +++ b/plugins/fundchannel.c @@ -211,6 +211,27 @@ static struct command_result *tx_prepare_done(struct command *cmd, take(ret)); } +static struct command_result *cancel_start(struct command *cmd, + const char *buf, + const jsmntok_t *error, + struct funding_req *fr) +{ + struct json_out *ret; + + /* We stash the error so we can return it after we've cleaned up */ + fr->error = json_strdup(fr, buf, error); + + ret = json_out_new(NULL); + json_out_start(ret, NULL, '{'); + json_out_addstr(ret, "id", type_to_string(tmpctx, struct node_id, fr->id)); + json_out_end(ret, '}'); + + return send_outreq(cmd, "fundchannel_cancel", + send_prior, send_prior, + cast_const(struct funding_req *, fr), + take(ret)); +} + static struct command_result *fundchannel_start_done(struct command *cmd, const char *buf, const jsmntok_t *result, @@ -244,7 +265,7 @@ static struct command_result *fundchannel_start_done(struct command *cmd, json_out_end(ret, '}'); return send_outreq(cmd, "txprepare", - tx_prepare_done, forward_error, + tx_prepare_done, cancel_start, cast_const(struct funding_req *, fr), take(ret)); }