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

Dual-funding: handle failures #4424

Merged
merged 6 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,13 @@ def openchannel_bump(self, channel_id, amount, initialpsbt):
}
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 = {
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 4 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ c-lightning Documentation
:maxdepth: 1
:caption: Manpages

<<<<<<< HEAD
=======
>>>>>>> df: add openchannel_abort command
lightning-addgossip <lightning-addgossip.7.md>
lightning-autocleaninvoice <lightning-autocleaninvoice.7.md>
lightning-check <lightning-check.7.md>
Expand Down Expand Up @@ -78,6 +81,7 @@ c-lightning Documentation
lightning-notifications <lightning-notifications.7.md>
lightning-offer <lightning-offer.7.md>
lightning-offerout <lightning-offerout.7.md>
lightning-openchannel_abort <lightning-openchannel_abort.7.md>
lightning-openchannel_bump <lightning-openchannel_bump.7.md>
lightning-openchannel_init <lightning-openchannel_init.7.md>
lightning-openchannel_signed <lightning-openchannel_signed.7.md>
Expand Down
6 changes: 4 additions & 2 deletions doc/lightning-fundchannel_cancel.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion doc/lightning-fundchannel_cancel.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ Lisa Neigut <<[email protected]>> 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
---------
Expand Down
5 changes: 3 additions & 2 deletions doc/lightning-fundchannel_complete.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion doc/lightning-fundchannel_complete.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
7 changes: 4 additions & 3 deletions doc/lightning-fundchannel_start.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions doc/lightning-fundchannel_start.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ Lisa Neigut <<[email protected]>> 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
---------
Expand Down
56 changes: 56 additions & 0 deletions doc/lightning-openchannel_abort.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions doc/lightning-openchannel_abort.7.md
Original file line number Diff line number Diff line change
@@ -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 <<[email protected]>> is mainly responsible.

RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>
5 changes: 3 additions & 2 deletions doc/lightning-openchannel_init.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion doc/lightning-openchannel_init.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions doc/lightning-openchannel_signed.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions doc/lightning-openchannel_signed.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
9 changes: 5 additions & 4 deletions doc/lightning-openchannel_update.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions doc/lightning-openchannel_update.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
21 changes: 18 additions & 3 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <common/closing_fee.h>
#include <common/fee_states.h>
#include <common/json_command.h>
#include <common/json_helpers.h>
#include <common/jsonrpc_errors.h>
#include <common/utils.h>
#include <common/wire_error.h>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading