From bec96a6c5bb1b46204fa6a39f4d85ef1fd5169a0 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 9 Mar 2021 15:14:08 -0600 Subject: [PATCH] df: add openchannel_abort command Allows us to clean up an in-progress open that we won't be completing Changelog-Added: EXPERIMENTAL JSON-RPC: Permit user-initiated aborting of in-progress opens. Only valid for not-yet-committed opens and RBF-attempts --- contrib/pyln-client/pyln/client/lightning.py | 7 +++ doc/Makefile | 1 + doc/index.rst | 4 ++ doc/lightning-fundchannel_cancel.7 | 6 +- doc/lightning-fundchannel_cancel.7.md | 4 +- doc/lightning-fundchannel_complete.7 | 5 +- doc/lightning-fundchannel_complete.7.md | 3 +- doc/lightning-fundchannel_start.7 | 7 ++- doc/lightning-fundchannel_start.7.md | 5 +- doc/lightning-openchannel_abort.7 | 56 +++++++++++++++++++ doc/lightning-openchannel_abort.7.md | 52 +++++++++++++++++ doc/lightning-openchannel_init.7 | 5 +- doc/lightning-openchannel_init.7.md | 3 +- doc/lightning-openchannel_signed.7 | 10 ++-- doc/lightning-openchannel_signed.7.md | 8 +-- doc/lightning-openchannel_update.7 | 9 +-- doc/lightning-openchannel_update.7.md | 7 ++- lightningd/channel.c | 21 ++++++- lightningd/channel.h | 1 + lightningd/dual_open_control.c | 59 ++++++++++++++++++++ tests/test_opening.py | 18 +++++- wallet/db_postgres_sqlgen.c | 2 +- wallet/db_sqlite3_sqlgen.c | 2 +- wallet/statements_gettextgen.po | 6 +- wallet/test/run-wallet.c | 5 ++ 25 files changed, 266 insertions(+), 40 deletions(-) create mode 100644 doc/lightning-openchannel_abort.7 create mode 100644 doc/lightning-openchannel_abort.7.md diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index c57aa2c9a..d8697b6d0 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -1101,6 +1101,13 @@ class LightningRpc(UnixDomainSocketRpc): } return self.call("openchannel_bump", payload) + def openchannel_abort(self, channel_id): + """ Abort a channel open """ + payload = { + "channel_id": channel_id, + } + return self.call("openchannel_abort", payload) + def paystatus(self, bolt11=None): """Detail status of attempts to pay {bolt11} or any.""" payload = { diff --git a/doc/Makefile b/doc/Makefile index 9bc887ea2..900aedaf3 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -49,6 +49,7 @@ MANPAGES := doc/lightning-cli.1 \ doc/lightning-notifications.7 \ doc/lightning-offer.7 \ doc/lightning-offerout.7 \ + doc/lightning-openchannel_abort.7 \ doc/lightning-openchannel_bump.7 \ doc/lightning-openchannel_init.7 \ doc/lightning-openchannel_signed.7 \ diff --git a/doc/index.rst b/doc/index.rst index 78d5d0351..b50e6f92f 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -29,6 +29,9 @@ c-lightning Documentation :maxdepth: 1 :caption: Manpages +<<<<<<< HEAD +======= +>>>>>>> df: add openchannel_abort command lightning-addgossip lightning-autocleaninvoice lightning-check @@ -78,6 +81,7 @@ c-lightning Documentation lightning-notifications lightning-offer lightning-offerout + lightning-openchannel_abort lightning-openchannel_bump lightning-openchannel_init lightning-openchannel_signed diff --git a/doc/lightning-fundchannel_cancel.7 b/doc/lightning-fundchannel_cancel.7 index 50f0cc211..e2c94a58d 100644 --- a/doc/lightning-fundchannel_cancel.7 +++ b/doc/lightning-fundchannel_cancel.7 @@ -51,11 +51,13 @@ Lisa Neigut \fI is mainly responsible\. .SH SEE ALSO -\fBlightning-connect\fR(7), \fBlightning-fundchannel\fR(7), +\fBlightning-connect\fR(7), \fBlightning-fundchannel\fR(7), \fBlightning-multifundchannel\fR(7), lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcomplete\fR(7) +lightning-openchannel_\fBinit\fR(7), lightning-openchannel_\fBupdate\fR(7), +lightning-openchannel_\fBsigned\fR(7), lightning-openchannel_\fBabort\fR(7) .SH RESOURCES Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:e29a875e9a7899adc15fb2f345c982b7cf75a714ae0e1b4367e6531839e7cd73 +\" SHA256STAMP:72ea44cf6efea20b369fb3ecfb61c8ede142800cbc8b427dbb9a26ec254452ce diff --git a/doc/lightning-fundchannel_cancel.7.md b/doc/lightning-fundchannel_cancel.7.md index 23d2a9248..8c2da4d26 100644 --- a/doc/lightning-fundchannel_cancel.7.md +++ b/doc/lightning-fundchannel_cancel.7.md @@ -46,8 +46,10 @@ Lisa Neigut <> is mainly responsible. SEE ALSO -------- -lightning-connect(7), lightning-fundchannel(7), +lightning-connect(7), lightning-fundchannel(7), lightning-multifundchannel(7), lightning-fundchannel\_start(7), lightning-fundchannel\_complete(7) +lightning-openchannel\_init(7), lightning-openchannel\_update(7), +lightning-openchannel\_signed(7), lightning-openchannel\_abort(7) RESOURCES --------- diff --git a/doc/lightning-fundchannel_complete.7 b/doc/lightning-fundchannel_complete.7 index 3372a2b72..7caaa6740 100644 --- a/doc/lightning-fundchannel_complete.7 +++ b/doc/lightning-fundchannel_complete.7 @@ -55,10 +55,11 @@ Lisa Neigut \fI is mainly responsible\. \fBlightning-connect\fR(7), \fBlightning-fundchannel\fR(7), \fBlightning-multifundchannel\fR(7), lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcancel\fR(7), lightning-openchannel_\fBinit\fR(7), lightning-openchannel_\fBupdate\fR(7), -lightning-openchannel_\fBsigned\fR(7), lightning-openchannel_\fBbump\fR(7) +lightning-openchannel_\fBsigned\fR(7), lightning-openchannel_\fBbump\fR(7), +lightning-openchannel_\fBabort\fR(7) .SH RESOURCES Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:eea98ffd2086403dd7257878427fa9f3cf4bc9983579d097ee3b65e77760a071 +\" SHA256STAMP:53e7f55055cdfb8cf66e89ba76a1cfa6fffaa5d6e72b441c44e7e6065707fc66 diff --git a/doc/lightning-fundchannel_complete.7.md b/doc/lightning-fundchannel_complete.7.md index c9ebe9643..7136d9e6e 100644 --- a/doc/lightning-fundchannel_complete.7.md +++ b/doc/lightning-fundchannel_complete.7.md @@ -49,7 +49,8 @@ SEE ALSO lightning-connect(7), lightning-fundchannel(7), lightning-multifundchannel(7), lightning-fundchannel\_start(7), lightning-fundchannel\_cancel(7), lightning-openchannel\_init(7), lightning-openchannel\_update(7), -lightning-openchannel\_signed(7), lightning-openchannel\_bump(7) +lightning-openchannel\_signed(7), lightning-openchannel\_bump(7), +lightning-openchannel\_abort(7) RESOURCES --------- diff --git a/doc/lightning-fundchannel_start.7 b/doc/lightning-fundchannel_start.7 index 786c3804c..256e0e0e3 100644 --- a/doc/lightning-fundchannel_start.7 +++ b/doc/lightning-fundchannel_start.7 @@ -76,13 +76,14 @@ Lisa Neigut \fI is mainly responsible\. .SH SEE ALSO -\fBlightning-connect\fR(7), \fBlightning-fundchannel\fR(7), +\fBlightning-connect\fR(7), \fBlightning-fundchannel\fR(7), \fBlightning-multifundchannel\fR(7), lightning-fundchannel_\fBcomplete\fR(7), lightning-fundchannel_\fBcancel\fR(7) lightning-openchannel_\fBinit\fR(7), lightning-openchannel_\fBupdate\fR(7), -lightning-openchannel_\fBsigned\fR(7), lightning-openchannel_\fBbump\fR(7) +lightning-openchannel_\fBsigned\fR(7), lightning-openchannel_\fBbump\fR(7), +lightning-openchannel_\fBabort\fR(7) .SH RESOURCES Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:6bb2a0765fba65c7c7cac11d34221c6c2ed28fe812f058268cd150cd81719977 +\" SHA256STAMP:6dd30561d6b00b1f2d5595cfe199e09576eb4ba2afea7ba52e8f38546720c76c diff --git a/doc/lightning-fundchannel_start.7.md b/doc/lightning-fundchannel_start.7.md index 999f81844..ff1d8b046 100644 --- a/doc/lightning-fundchannel_start.7.md +++ b/doc/lightning-fundchannel_start.7.md @@ -64,10 +64,11 @@ Lisa Neigut <> is mainly responsible. SEE ALSO -------- -lightning-connect(7), lightning-fundchannel(7), +lightning-connect(7), lightning-fundchannel(7), lightning-multifundchannel(7), lightning-fundchannel\_complete(7), lightning-fundchannel\_cancel(7) lightning-openchannel\_init(7), lightning-openchannel\_update(7), -lightning-openchannel\_signed(7), lightning-openchannel\_bump(7) +lightning-openchannel\_signed(7), lightning-openchannel\_bump(7), +lightning-openchannel\_abort(7) RESOURCES --------- diff --git a/doc/lightning-openchannel_abort.7 b/doc/lightning-openchannel_abort.7 new file mode 100644 index 000000000..7dd3d105a --- /dev/null +++ b/doc/lightning-openchannel_abort.7 @@ -0,0 +1,56 @@ +.TH "LIGHTNING-OPENCHANNEL_ABORT" "7" "" "" "lightning-openchannel_abort" +.SH NAME +lightning-openchannel_abort - Command to abort a channel to a peer +.SH SYNOPSIS + +\fBopenchannel_abort\fR \fIchannel_id\fR + +.SH DESCRIPTION + +\fBopenchannel_init\fR is a low level RPC command which initiates a channel +open with a specified peer\. It uses the openchannel protocol +which allows for interactive transaction construction\. + + +\fIchannel_id\fR is id of this channel\. + +.SH RETURN VALUE + +On success, returns the \fIchannel_id\fR for this channel; an boolean indicating +if the channel has been successfully canceled, \fIchannel_canceled\fR; +a reason for the cancellation, \fIreason\fR\. + + +On error the returned object will contain \fBcode\fR and \fBmessage\fR properties, +with \fBcode\fR being one of the following: + +.RS +.IP \[bu] +-32602: If the given parameters are wrong\. +.IP \[bu] +-1: Catchall nonspecific error\. +.IP \[bu] +305: Peer is not connected\. +.IP \[bu] +311: Unknown channel id\. +.IP \[bu] +312: Channel in an invalid state + +.RE +.SH SEE ALSO + +lightning-openchannel_\fBinit\fR(7), lightning-openchannel_\fBupdate\fR(7), +lightning-openchannel_\fBsigned\fR(7), lightning-openchannel_\fBbump\fR(7), +lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcomplete\fR(7), +\fBlightning-fundchannel\fR(7), \fBlightning-fundpsbt\fR(7), \fBlightning-utxopsbt\fR(7), +\fBlightning-multifundchannel\fR(7) + +.SH AUTHOR + +@niftynei \fI is mainly responsible\. + +.SH RESOURCES + +Main web site: \fIhttps://github.com/ElementsProject/lightning\fR + +\" SHA256STAMP:3c6aa3f2359134f7468facf69f3f6b925334117079a46ada88ec9b6b8cdd3f0a diff --git a/doc/lightning-openchannel_abort.7.md b/doc/lightning-openchannel_abort.7.md new file mode 100644 index 000000000..cbca56165 --- /dev/null +++ b/doc/lightning-openchannel_abort.7.md @@ -0,0 +1,52 @@ +lightning-openchannel\_abort -- Command to abort a channel to a peer +===================================================================== + +SYNOPSIS +-------- + +**openchannel_abort** *channel_id* + +DESCRIPTION +----------- + +`openchannel_init` is a low level RPC command which initiates a channel +open with a specified peer. It uses the openchannel protocol +which allows for interactive transaction construction. + +*channel_id* is id of this channel. + + +RETURN VALUE +------------ + +On success, returns the *channel_id* for this channel; an boolean indicating +if the channel has been successfully canceled, *channel_canceled*; +a reason for the cancellation, *reason*. + +On error the returned object will contain `code` and `message` properties, +with `code` being one of the following: + +- -32602: If the given parameters are wrong. +- -1: Catchall nonspecific error. +- 305: Peer is not connected. +- 311: Unknown channel id. +- 312: Channel in an invalid state + +SEE ALSO +-------- + +lightning-openchannel\_init(7), lightning-openchannel\_update(7), +lightning-openchannel\_signed(7), lightning-openchannel\_bump(7), +lightning-fundchannel\_start(7), lightning-fundchannel\_complete(7), +lightning-fundchannel(7), lightning-fundpsbt(7), lightning-utxopsbt(7), +lightning-multifundchannel(7) + +AUTHOR +------ + +@niftynei <> is mainly responsible. + +RESOURCES +--------- + +Main web site: diff --git a/doc/lightning-openchannel_init.7 b/doc/lightning-openchannel_init.7 index 905c2f4bd..a92edbb7b 100644 --- a/doc/lightning-openchannel_init.7 +++ b/doc/lightning-openchannel_init.7 @@ -86,7 +86,8 @@ with \fBcode\fR being one of the following: .SH SEE ALSO lightning-openchannel_\fBupdate\fR(7), lightning-openchannel_\fBsigned\fR(7), -lightning-openchannel_\fBbump\fR(7) lightning-fundchannel_\fBstart\fR(7), +lightning-openchannel_\fBabort\fR(7), lightning-openchannel_\fBbump\fR(7), +lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcomplete\fR(7), \fBlightning-fundchannel\fR(7), \fBlightning-fundpsbt\fR(7), \fBlightning-utxopsbt\fR(7), \fBlightning-multifundchannel\fR(7) @@ -98,4 +99,4 @@ lightning-fundchannel_\fBcomplete\fR(7), \fBlightning-fundchannel\fR(7), Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:0db7db257671eb7ea20ee3fafd43ba75902cde08942815e0bb99703114b121e7 +\" SHA256STAMP:8e37cb8813751e06f59b108e8a335b5b5269e5764c346838a6ddf79138ccea6e diff --git a/doc/lightning-openchannel_init.7.md b/doc/lightning-openchannel_init.7.md index 237d52747..0385e1acb 100644 --- a/doc/lightning-openchannel_init.7.md +++ b/doc/lightning-openchannel_init.7.md @@ -70,7 +70,8 @@ SEE ALSO -------- lightning-openchannel\_update(7), lightning-openchannel\_signed(7), -lightning-openchannel\_bump(7) lightning-fundchannel\_start(7), +lightning-openchannel\_abort(7), lightning-openchannel\_bump(7), +lightning-fundchannel\_start(7), lightning-fundchannel\_complete(7), lightning-fundchannel(7), lightning-fundpsbt(7), lightning-utxopsbt(7), lightning-multifundchannel(7) diff --git a/doc/lightning-openchannel_signed.7 b/doc/lightning-openchannel_signed.7 index 532062ed1..d32063dfa 100644 --- a/doc/lightning-openchannel_signed.7 +++ b/doc/lightning-openchannel_signed.7 @@ -56,11 +56,11 @@ with \fBcode\fR being one of the following: .RE .SH SEE ALSO -======= lightning-openchannel_\fBinit\fR(7), lightning-openchannel_\fBupdate\fR(7), -lightning-openchannel_\fBbump\fR(7), lightning-fundchannel_\fBstart\fR(7), -lightning-fundchannel_\fBcomplete\fR(7), \fBlightning-fundchannel\fR(7), -\fBlightning-fundpsbt\fR(7), \fBlightning-utxopsbt\fR(7), \fBlightning-multifundchannel\fR(7) +lightning-openchannel_\fBabort\fR(7), lightning-openchannel_\fBbump\fR(7), +lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcomplete\fR(7), +\fBlightning-fundchannel\fR(7), \fBlightning-fundpsbt\fR(7), +\fBlightning-utxopsbt\fR(7), \fBlightning-multifundchannel\fR(7) .SH AUTHOR @@ -70,4 +70,4 @@ lightning-fundchannel_\fBcomplete\fR(7), \fBlightning-fundchannel\fR(7), Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:3004ce5963d892d4828b11d3e5daedb59f780f98485098eba0e46b3e835e759d +\" SHA256STAMP:bd874415c73718a0a16c37c9d8cf6fec2944a491b05f2632b1ea2ff35c7a50ae diff --git a/doc/lightning-openchannel_signed.7.md b/doc/lightning-openchannel_signed.7.md index d64a4bd59..d16ba2318 100644 --- a/doc/lightning-openchannel_signed.7.md +++ b/doc/lightning-openchannel_signed.7.md @@ -46,11 +46,11 @@ with `code` being one of the following: SEE ALSO -------- -======= lightning-openchannel\_init(7), lightning-openchannel\_update(7), -lightning-openchannel\_bump(7), lightning-fundchannel\_start(7), -lightning-fundchannel\_complete(7), lightning-fundchannel(7), -lightning-fundpsbt(7), lightning-utxopsbt(7), lightning-multifundchannel(7) +lightning-openchannel\_abort(7), lightning-openchannel\_bump(7), +lightning-fundchannel\_start(7), lightning-fundchannel\_complete(7), +lightning-fundchannel(7), lightning-fundpsbt(7), +lightning-utxopsbt(7), lightning-multifundchannel(7) AUTHOR ------ diff --git a/doc/lightning-openchannel_update.7 b/doc/lightning-openchannel_update.7 index 9f9fdeb69..7e702ec7f 100644 --- a/doc/lightning-openchannel_update.7 +++ b/doc/lightning-openchannel_update.7 @@ -67,9 +67,10 @@ in the funding transaction\. .SH SEE ALSO lightning-openchannel_\fBinit\fR(7), lightning-openchannel_\fBsigned\fR(7), -lightning-openchannel_\fBbump\fR(7), lightning-fundchannel_\fBstart\fR(7), -lightning-fundchannel_\fBcomplete\fR(7), \fBlightning-fundchannel\fR(7), -\fBlightning-fundpsbt\fR(7), \fBlightning-utxopsbt\fR(7), \fBlightning-multifundchannel\fR(7) +lightning-openchannel_\fBbump\fR(7), lightning-openchannel_\fBabort\fR(7), +lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcomplete\fR(7), +\fBlightning-fundchannel\fR(7), \fBlightning-fundpsbt\fR(7), \fBlightning-utxopsbt\fR(7), +\fBlightning-multifundchannel\fR(7) .SH AUTHOR @@ -79,4 +80,4 @@ lightning-fundchannel_\fBcomplete\fR(7), \fBlightning-fundchannel\fR(7), Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:93c15eb807f3ee413ebc1eae0cb10970f23fd63ecdae4d31a2f3dce90b5c0b1a +\" SHA256STAMP:bc76c4c09f0c4c9c9f1e6b78f9ca495042076abac00c06309a94957646f07974 diff --git a/doc/lightning-openchannel_update.7.md b/doc/lightning-openchannel_update.7.md index da2a8db50..db52d3964 100644 --- a/doc/lightning-openchannel_update.7.md +++ b/doc/lightning-openchannel_update.7.md @@ -53,9 +53,10 @@ SEE ALSO -------- lightning-openchannel\_init(7), lightning-openchannel\_signed(7), -lightning-openchannel\_bump(7), lightning-fundchannel\_start(7), -lightning-fundchannel\_complete(7), lightning-fundchannel(7), -lightning-fundpsbt(7), lightning-utxopsbt(7), lightning-multifundchannel(7) +lightning-openchannel\_bump(7), lightning-openchannel\_abort(7), +lightning-fundchannel\_start(7), lightning-fundchannel\_complete(7), +lightning-fundchannel(7), lightning-fundpsbt(7), lightning-utxopsbt(7), +lightning-multifundchannel(7) AUTHOR ------ diff --git a/lightningd/channel.c b/lightningd/channel.c index 2b0a5205a..fd46d71aa 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -194,6 +195,7 @@ struct open_attempt *new_channel_open_attempt(struct channel *channel) oa->role = channel->opener == LOCAL ? TX_INITIATOR : TX_ACCEPTER; oa->our_upfront_shutdown_script = NULL; oa->cmd = NULL; + oa->aborted = false; return oa; } @@ -742,9 +744,22 @@ void channel_cleanup_commands(struct channel *channel, const char *why) { if (channel->open_attempt) { struct open_attempt *oa = channel->open_attempt; - if (oa->cmd) - was_pending(command_fail(oa->cmd, LIGHTNINGD, - "%s", why)); + if (oa->cmd) { + /* If we requested this be aborted, it's a success */ + if (oa->aborted) { + struct json_stream *response; + response = json_stream_success(oa->cmd); + json_add_channel_id(response, + "channel_id", + &channel->cid); + json_add_bool(response, "channel_canceled", + list_empty(&channel->inflights)); + json_add_string(response, "reason", why); + was_pending(command_success(oa->cmd, response)); + } else + was_pending(command_fail(oa->cmd, LIGHTNINGD, + "%s", why)); + } notify_channel_open_failed(channel->peer->ld, &channel->cid); channel->open_attempt = tal_free(channel->open_attempt); } diff --git a/lightningd/channel.h b/lightningd/channel.h index eec3d2e99..e764c5564 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -51,6 +51,7 @@ struct open_attempt { struct channel *channel; struct channel_config our_config; enum tx_role role; + bool aborted; /* On funding_channel struct */ struct command *cmd; diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index ac49c20f1..cf0ac86c0 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -1874,6 +1874,57 @@ send_msg: subd_send_msg(channel->owner, take(msg)); } +static struct command_result * +json_openchannel_abort(struct command *cmd, + const char *buffer, + const jsmntok_t *obj UNNEEDED, + const jsmntok_t *params) +{ + struct channel_id *cid; + struct channel *channel; + u8 *msg; + + if (!param(cmd, buffer, params, + p_req("channel_id", param_channel_id, &cid), + NULL)) + return command_param_failed(); + + channel = channel_by_cid(cmd->ld, cid); + if (!channel) + return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, + "Unknown channel %s", + type_to_string(tmpctx, struct channel_id, + cid)); + + if (!channel->owner) + return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, + "Peer not connected"); + + if (!channel->open_attempt) + return command_fail(cmd, FUNDING_STATE_INVALID, + "Channel open not in progress"); + + if (channel->open_attempt->cmd) + return command_fail(cmd, FUNDING_STATE_INVALID, + "Another openchannel command" + " is in progress"); + + if (channel->openchannel_signed_cmd) + return command_fail(cmd, FUNDING_STATE_INVALID, + "Already sent sigs, waiting for peer's"); + + /* Mark it as aborted so when we clean-up, we send the + * correct response */ + channel->open_attempt->aborted = true; + channel->open_attempt->cmd = cmd; + + /* Tell dualopend to fail this channel */ + msg = towire_dualopend_fail(NULL, "Abort requested"); + subd_send_msg(channel->owner, take(msg)); + + return command_still_pending(cmd); +} + static struct command_result * json_openchannel_bump(struct command *cmd, const char *buffer, @@ -2701,11 +2752,19 @@ static const struct json_command openchannel_bump_command = { "Attempt to bump the fee on {channel_id}'s funding transaction." }; +static const struct json_command openchannel_abort_command = { + "openchannel_abort", + "channels", + json_openchannel_abort, + "Abort {channel_id}'s open. Usable while `commitment_signed=false`." +}; + #if EXPERIMENTAL_FEATURES AUTODATA(json_command, &openchannel_init_command); AUTODATA(json_command, &openchannel_update_command); AUTODATA(json_command, &openchannel_signed_command); AUTODATA(json_command, &openchannel_bump_command); +AUTODATA(json_command, &openchannel_abort_command); #endif /* EXPERIMENTAL_FEATURES */ static void start_fresh_dualopend(struct peer *peer, diff --git a/tests/test_opening.py b/tests/test_opening.py index 8bcd715fa..d1341494f 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -96,8 +96,9 @@ def test_v2_rbf(node_factory, bitcoind, chainparams): @unittest.skipIf(not EXPERIMENTAL_FEATURES, "dual-funding is experimental only") def test_v2_rbf_multi(node_factory, bitcoind, chainparams): l1, l2 = node_factory.get_nodes(2, - opts=[{'dev-force-features': '+223'}, - {'dev-force-features': '+223'}]) + opts={'dev-force-features': '+223', + 'may_reconnect': True, + 'allow_warning': True}) l1.rpc.connect(l2.info['id'], 'localhost', l2.port) amount = 2**24 @@ -116,6 +117,11 @@ def test_v2_rbf_multi(node_factory, bitcoind, chainparams): # Check that we're waiting for lockin l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN') + # Attempt to do abort, should fail since we've + # already gotten an inflight + with pytest.raises(RpcError): + l1.rpc.openchannel_abort(chan_id) + next_feerate = find_next_feerate(l1, l2) # Initiate an RBF @@ -128,6 +134,14 @@ def test_v2_rbf_multi(node_factory, bitcoind, chainparams): # Do the bump bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt']) + # Abort this open attempt! We will re-try + aborted = l1.rpc.openchannel_abort(chan_id) + assert not aborted['channel_canceled'] + + # Do the bump, again + l1.rpc.connect(l2.info['id'], 'localhost', l2.port) + bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt']) + update = l1.rpc.openchannel_update(chan_id, bump['psbt']) assert update['commitments_secured'] diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index d0e1bca81..63380cf60 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1876,4 +1876,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:69650ac9a0c2d7651aa410d07ae250ff6309660f95ceb157e698b82163003779 +// SHA256STAMP:e3f864d654fc2c6ea7d527a0ceab875e3d01c4a9884c0810dc5981b8ace7df19 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 194771fbe..0a1fb1afd 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1876,4 +1876,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:69650ac9a0c2d7651aa410d07ae250ff6309660f95ceb157e698b82163003779 +// SHA256STAMP:e3f864d654fc2c6ea7d527a0ceab875e3d01c4a9884c0810dc5981b8ace7df19 diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 0bae2217a..c389878bf 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1230,11 +1230,11 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1429 +#: wallet/test/run-wallet.c:1434 msgid "SELECT COUNT(1) FROM channel_funding_inflights WHERE channel_id = ?;" msgstr "" -#: wallet/test/run-wallet.c:1627 +#: wallet/test/run-wallet.c:1632 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:a651af64f490359ef2b22638d51be94e8ece9500ebc8efe16dc2c73bb8a473c9 +# SHA256STAMP:1fc9393bed969dc69c684eb5d842785d2386df6ac5418404d36a0e2a5657e974 diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index b7c0433cc..00cf006c4 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -282,6 +282,11 @@ void json_add_amount_sat_only(struct json_stream *result UNNEEDED, void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, bool value UNNEEDED) { fprintf(stderr, "json_add_bool called!\n"); abort(); } +/* Generated stub for json_add_channel_id */ +void json_add_channel_id(struct json_stream *response UNNEEDED, + const char *fieldname UNNEEDED, + const struct channel_id *cid UNNEEDED) +{ fprintf(stderr, "json_add_channel_id called!\n"); abort(); } /* Generated stub for json_add_hex */ void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)