openingd: allow funding_failed to complete successfully

For the `fundchannel_cancel` we're going to want
to 'successfully' fail a funding channel operation. This allows
us to report it a failure back as an RPC success, instead of
automatically failing the RPC request.
This commit is contained in:
lisa neigut
2019-05-31 14:51:56 -07:00
committed by Rusty Russell
parent 1b2a593b05
commit 846bc9cbc4
3 changed files with 21 additions and 7 deletions

View File

@@ -573,8 +573,11 @@ static void opening_funder_failed(struct subd *openingd, const u8 *msg,
struct uncommitted_channel *uc)
{
char *desc;
bool is_err;
if (!fromwire_opening_funder_failed(msg, msg, &desc)) {
struct json_stream *response;
if (!fromwire_opening_funder_failed(msg, msg, &desc, &is_err)) {
log_broken(uc->log,
"bad OPENING_FUNDER_FAILED %s",
tal_hex(tmpctx, msg));
@@ -585,7 +588,15 @@ static void opening_funder_failed(struct subd *openingd, const u8 *msg,
return;
}
was_pending(command_fail(uc->fc->cmd, LIGHTNINGD, "%s", desc));
if (is_err)
was_pending(command_fail(uc->fc->cmd, LIGHTNINGD, "%s", desc));
else {
response = json_stream_success(uc->fc->cmd);
json_stream_append(response, "\"");
json_stream_append(response, desc);
json_stream_append(response, "\"");
was_pending(command_success(uc->fc->cmd, response));
}
/* Clear uc->fc, so we can try again, and so we don't fail twice
* if they close. */

View File

@@ -80,6 +80,7 @@ opening_funder_reply,,shutdown_scriptpubkey,shutdown_len*u8
# Openingd->master: we failed to negotiation channel
opening_funder_failed,6004
opening_funder_failed,,reason,wirestring
opening_funder_failed,,is_err,bool
# Openingd->master: they offered channel.
# This gives their txid and info, means we can send funding_signed: we're done.
1 #include <common/cryptomsg.h>
80 opening_fundee,6003 # This gives their txid and info, means we can send funding_signed: we're done.
81 opening_fundee,,their_config,struct channel_config opening_fundee,6003
82 opening_fundee,,first_commit,struct bitcoin_tx opening_fundee,,their_config,struct channel_config
83 opening_fundee,,first_commit,struct bitcoin_tx
84 opening_fundee,,first_commit_sig,struct bitcoin_signature
85 opening_fundee,,pps,struct per_peer_state
86 opening_fundee,,revocation_basepoint,struct pubkey

View File

@@ -116,7 +116,7 @@ static const u8 *dev_upfront_shutdown_script(const tal_t *ctx)
/*~ If we can't agree on parameters, we fail to open the channel. If we're
* the funder, we need to tell lightningd, otherwise it never really notices. */
static void negotiation_aborted(struct state *state, bool am_funder,
const char *why)
const char *why, bool is_err)
{
status_debug("aborted opening negotiation: %s", why);
/*~ The "billboard" (exposed as "status" in the JSON listpeers RPC
@@ -129,7 +129,7 @@ static void negotiation_aborted(struct state *state, bool am_funder,
/* If necessary, tell master that funding failed. */
if (am_funder) {
u8 *msg = towire_opening_funder_failed(NULL, why);
u8 *msg = towire_opening_funder_failed(NULL, why, is_err);
wire_sync_write(REQ_FD, take(msg));
}
@@ -155,7 +155,7 @@ static void negotiation_failed(struct state *state, bool am_funder,
"You gave bad parameters: %s", errmsg);
sync_crypto_write(state->pps, take(msg));
negotiation_aborted(state, am_funder, errmsg);
negotiation_aborted(state, am_funder, errmsg, true);
}
/*~ This is the key function that checks that their configuration is reasonable:
@@ -399,7 +399,8 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
if (all_channels) {
if (am_funder) {
msg = towire_opening_funder_failed(NULL,
err);
err,
true);
wire_sync_write(REQ_FD, take(msg));
}
peer_failed_received_errmsg(state->pps, err,
@@ -407,7 +408,8 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
}
negotiation_aborted(state, am_funder,
tal_fmt(tmpctx, "They sent error %s",
err));
err),
true);
/* Return NULL so caller knows to stop negotiating. */
return NULL;
}