Skip to content

Commit

Permalink
dual-open: use tx-abort instead of warning/errors
Browse files Browse the repository at this point in the history
When a channel open fails, we use tx-abort instead of warning/error.

This means that the peer won't disconnect! And instead when a new
message arrives, we'll need to rebuild the dualopend subd (if missing).

Makes opens a bit easer to retry (no reconnect needed), as well as keeps
the connection alive for other channels we may have with that peer.

Changelog-Changed: Experimental-Dual-Fund: open failures don't disconnect, but instead fail the opening process
  • Loading branch information
niftynei committed Jan 30, 2023
1 parent 0b0ce79 commit 5db6a44
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 223 deletions.
2 changes: 1 addition & 1 deletion common/peer_failed.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <common/wire_error.h>

/* Fatal error here, return peer control to lightningd */
static void NORETURN
void NORETURN
peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps)
{
int reason = fromwire_peektype(msg);
Expand Down
3 changes: 3 additions & 0 deletions common/peer_failed.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
struct channel_id;
struct per_peer_state;

/* peer_fatal_continue - Send a message to master, we've failed */
void NORETURN peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps);

/**
* peer_failed_warn - Send a warning msg and close the connection.
* @pps: the per-peer state.
Expand Down
2 changes: 2 additions & 0 deletions common/wire_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
warning = false;
else if (fromwire_warning(ctx, errmsg, channel_id, &data))
warning = true;
else if (fromwire_tx_abort(ctx, errmsg, channel_id, &data))
warning = false;
else
return tal_fmt(ctx, "Invalid ERROR message '%s'",
tal_hex(ctx, errmsg));
Expand Down
30 changes: 27 additions & 3 deletions lightningd/dual_open_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -2379,9 +2379,33 @@ json_openchannel_bump(struct command *cmd,
type_to_string(tmpctx, struct amount_sat,
&chainparams->max_funding));

if (!channel->owner)
return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED,
"Peer not connected.");
/* It's possible that the last open failed/was aborted.
* So now we restart the attempt! */
if (!channel->owner) {
int fds[2];
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
log_broken(channel->log,
"Failed to create socketpair: %s",
strerror(errno));
return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED,
"Unable to create socket: %s",
strerror(errno));
}

if (!peer_restart_dualopend(channel->peer,
new_peer_fd(tmpctx, fds[0]),
channel)) {
close(fds[1]);
return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED,
"Peer not connected.");
}
subd_send_msg(cmd->ld->connectd,
take(towire_connectd_peer_connect_subd(NULL,
&channel->peer->id,
channel->peer->connectd_counter,
&channel->cid)));
subd_send_fd(cmd->ld->connectd, fds[1]);
}

if (channel->open_attempt)
return command_fail(cmd, FUNDING_STATE_INVALID,
Expand Down
22 changes: 20 additions & 2 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void channel_errmsg(struct channel *channel,

if (channel_unsaved(channel)) {
log_info(channel->log, "%s", "Unsaved peer failed."
" Disconnecting and deleting channel.");
" Deleting channel.");
delete_channel(channel);
return;
}
Expand Down Expand Up @@ -1485,8 +1485,26 @@ void peer_spoke(struct lightningd *ld, const u8 *msg)

/* If channel is active, we raced, so ignore this:
* subd will get it soon. */
if (channel_active(channel))
if (channel_active(channel)) {
log_debug(channel->log,
"channel already active");
if (!channel->owner) {
assert(channel->state == DUALOPEND_AWAITING_LOCKIN);
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
log_broken(ld->log,
"Failed to create socketpair: %s",
strerror(errno));
error = towire_warningfmt(tmpctx, &channel_id,
"Trouble in paradise?");
goto send_error;
}
if (peer_restart_dualopend(peer, new_peer_fd(tmpctx, fds[0]), channel))
goto tell_connectd;
/* FIXME: Send informative error? */
close(fds[1]);
}
return;
}

if (msgtype == WIRE_CHANNEL_REESTABLISH) {
log_debug(channel->log,
Expand Down
Loading

0 comments on commit 5db6a44

Please sign in to comment.