Skip to content

Commit ca0358f

Browse files
committed
channeld: send shutdown_complete even if reestablish_only.
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).
1 parent 44829d1 commit ca0358f

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

channeld/channeld.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ static void maybe_send_shutdown(struct peer *peer)
918918
billboard_update(peer);
919919
}
920920

921+
static void send_shutdown_complete(struct peer *peer)
922+
{
923+
/* Now we can tell master shutdown is complete. */
924+
wire_sync_write(MASTER_FD,
925+
take(towire_channeld_shutdown_complete(NULL, peer->pps)));
926+
per_peer_state_fdpass_send(MASTER_FD, peer->pps);
927+
close(MASTER_FD);
928+
}
929+
921930
/* This queues other traffic from the fd until we get reply. */
922931
static u8 *master_wait_sync_reply(const tal_t *ctx,
923932
struct peer *peer,
@@ -2929,10 +2938,17 @@ static void peer_reconnect(struct peer *peer,
29292938
#endif /* EXPERIMENTAL_FEATURES */
29302939

29312940
/* Now stop, we've been polite long enough. */
2932-
if (reestablish_only)
2941+
if (reestablish_only) {
2942+
/* If we were successfully closing, we still go to closingd. */
2943+
if (shutdown_complete(peer)) {
2944+
send_shutdown_complete(peer);
2945+
daemon_shutdown();
2946+
exit(0);
2947+
}
29332948
peer_failed_err(peer->pps,
29342949
&peer->channel_id,
29352950
"Channel is already closed");
2951+
}
29362952

29372953
/* Corner case: we didn't send shutdown before because update_add_htlc
29382954
* pending, but now they're cleared by restart, and we're actually
@@ -3594,15 +3610,6 @@ static void init_channel(struct peer *peer)
35943610
billboard_update(peer);
35953611
}
35963612

3597-
static void send_shutdown_complete(struct peer *peer)
3598-
{
3599-
/* Now we can tell master shutdown is complete. */
3600-
wire_sync_write(MASTER_FD,
3601-
take(towire_channeld_shutdown_complete(NULL, peer->pps)));
3602-
per_peer_state_fdpass_send(MASTER_FD, peer->pps);
3603-
close(MASTER_FD);
3604-
}
3605-
36063613
static void try_read_gossip_store(struct peer *peer)
36073614
{
36083615
u8 *msg = gossip_store_next(tmpctx, peer->pps);

lightningd/channel_control.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
318318
peer_start_closingd(channel, pps);
319319

320320
/* We might have reconnected, so already be here. */
321-
if (channel->state != CLOSINGD_SIGEXCHANGE)
321+
if (!channel_closed(channel)
322+
&& channel->state != CLOSINGD_SIGEXCHANGE)
322323
channel_set_state(channel,
323324
CHANNELD_SHUTTING_DOWN,
324325
CLOSINGD_SIGEXCHANGE,

lightningd/closing_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void peer_closing_complete(struct channel *channel, const u8 *msg)
145145
channel_set_billboard(channel, false, NULL);
146146

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

151151
/* Channel gets dropped to chain cooperatively. */

tests/test_closing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,6 @@ def test_htlc_rexmit_while_closing(node_factory, executor):
27862786
fut2.result(TIMEOUT)
27872787

27882788

2789-
@pytest.mark.xfail(strict=True)
27902789
@pytest.mark.openchannel('v1')
27912790
@pytest.mark.developer("needs dev_disconnect")
27922791
def test_you_forgot_closed_channel(node_factory, executor):

0 commit comments

Comments
 (0)