Skip to content

Commit

Permalink
channeld: send shutdown_complete even if reestablish_only.
Browse files Browse the repository at this point in the history
This lets us transition (with a few supporting changes) to closingd,
which will happily let them mutual close with us.

We already handle the case where this mutual close is redundant (for
packet loss), so this is easy.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: Protocol: We will now reestablish and negotiate mutual close on channels we've already closed (great if peer has lost their database).
  • Loading branch information
rustyrussell committed Jun 4, 2021
1 parent 7ed1aea commit cf328af
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
27 changes: 17 additions & 10 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,15 @@ static void maybe_send_shutdown(struct peer *peer)
billboard_update(peer);
}

static void send_shutdown_complete(struct peer *peer)
{
/* Now we can tell master shutdown is complete. */
wire_sync_write(MASTER_FD,
take(towire_channeld_shutdown_complete(NULL, peer->pps)));
per_peer_state_fdpass_send(MASTER_FD, peer->pps);
close(MASTER_FD);
}

/* This queues other traffic from the fd until we get reply. */
static u8 *master_wait_sync_reply(const tal_t *ctx,
struct peer *peer,
Expand Down Expand Up @@ -2744,10 +2753,17 @@ static void peer_reconnect(struct peer *peer,
maybe_send_shutdown(peer);

/* Now stop, we've been polite long enough. */
if (reestablish_only)
if (reestablish_only) {
/* If we were successfully closing, we still go to closingd. */
if (shutdown_complete(peer)) {
send_shutdown_complete(peer);
daemon_shutdown();
exit(0);
}
peer_failed_err(peer->pps,
&peer->channel_id,
"Channel is already closed");
}

/* Corner case: we didn't send shutdown before because update_add_htlc
* pending, but now they're cleared by restart, and we're actually
Expand Down Expand Up @@ -3405,15 +3421,6 @@ static void init_channel(struct peer *peer)
billboard_update(peer);
}

static void send_shutdown_complete(struct peer *peer)
{
/* Now we can tell master shutdown is complete. */
wire_sync_write(MASTER_FD,
take(towire_channeld_shutdown_complete(NULL, peer->pps)));
per_peer_state_fdpass_send(MASTER_FD, peer->pps);
close(MASTER_FD);
}

static void try_read_gossip_store(struct peer *peer)
{
u8 *msg = gossip_store_next(tmpctx, peer->pps);
Expand Down
3 changes: 2 additions & 1 deletion lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
peer_start_closingd(channel, pps);

/* We might have reconnected, so already be here. */
if (channel->state != CLOSINGD_SIGEXCHANGE)
if (!channel_closed(channel)
&& channel->state != CLOSINGD_SIGEXCHANGE)
channel_set_state(channel,
CHANNELD_SHUTTING_DOWN,
CLOSINGD_SIGEXCHANGE,
Expand Down
2 changes: 1 addition & 1 deletion lightningd/closing_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void peer_closing_complete(struct channel *channel, const u8 *msg)
channel_set_billboard(channel, false, NULL);

/* Retransmission only, ignore closing. */
if (channel->state == CLOSINGD_COMPLETE)
if (channel_closed(channel))
return;

/* Channel gets dropped to chain cooperatively. */
Expand Down
1 change: 0 additions & 1 deletion tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,6 @@ def test_htlc_rexmit_while_closing(node_factory, executor):
fut2.result(TIMEOUT)


@pytest.mark.xfail(strict=True)
@pytest.mark.openchannel('v1')
@pytest.mark.developer("needs dev_disconnect")
def test_you_forgot_closed_channel(node_factory, executor):
Expand Down

0 comments on commit cf328af

Please sign in to comment.