Skip to content

Commit 7829e26

Browse files
lightningd: don't disconnect when sending error for unknown channel_reestablish
When a peer sends WIRE_CHANNEL_REESTABLISH for a channel we don't know about (e.g. dual-funding where we deleted the unsaved channel on disconnect but the peer saved it in DUALOPEND_OPEN_COMMIT_READY), we send an error and disconnect. The disconnect races with the error delivery: the peer's dualopend may not receive the error before the connection drops, so the channel survives as a transient failure and the peer retries on every reconnect, creating an infinite loop. Fix this by sending the error without disconnecting for the WIRE_CHANNEL_REESTABLISH case, so the peer's dualopend reliably receives the error and cleans up the stale channel. Changelog-Fixed: dual-funding reconnect loop when peer doesn't know about a saved channel Fixes: #8822 Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent 9737ef5 commit 7829e26

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

lightningd/peer_control.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,21 @@ void handle_peer_spoke(struct lightningd *ld, const u8 *msg)
21372137
"Channel is closed and forgotten");
21382138
goto send_error;
21392139
}
2140+
/* Unknown channel: send error but don't disconnect.
2141+
* If we hang up, the peer's dualopend may not
2142+
* receive the error (it races with the disconnect),
2143+
* leaving the peer with a saved channel that we
2144+
* don't know about, causing an infinite reconnect
2145+
* loop. */
2146+
log_peer_unusual(ld->log, &peer->id,
2147+
"Unknown channel %s for %s",
2148+
fmt_channel_id(tmpctx,
2149+
&channel_id),
2150+
peer_wire_name(msgtype));
2151+
error = towire_errorfmt(tmpctx, &channel_id,
2152+
"Unknown channel for %s",
2153+
peer_wire_name(msgtype));
2154+
goto send_error_nohangup;
21402155
}
21412156

21422157
/* Weird message? Log and reply with error. */
@@ -2162,6 +2177,15 @@ void handle_peer_spoke(struct lightningd *ld, const u8 *msg)
21622177
peer->connectd_counter)));
21632178
return;
21642179

2180+
send_error_nohangup:
2181+
log_peer_debug(ld->log, &peer->id, "Telling connectd to send error %s",
2182+
tal_hex(tmpctx, error));
2183+
subd_send_msg(ld->connectd,
2184+
take(towire_connectd_peer_send_msg(NULL, &peer->id,
2185+
peer->connectd_counter,
2186+
error)));
2187+
return;
2188+
21652189
tell_connectd:
21662190
subd_send_msg(ld->connectd,
21672191
take(towire_connectd_peer_connect_subd(NULL, &id,

0 commit comments

Comments
 (0)