From 39a2893688cc505f5c4f419671a10c4ed6b7bc06 Mon Sep 17 00:00:00 2001 From: Aditya Sharma Date: Sat, 5 Apr 2025 14:26:25 +0530 Subject: [PATCH] Workaround for LND to cause a force-close on our channel Unfortunately LND does not force close the channels on receiving an error, they blame us for this behaviour (https://github.com/lightningnetwork/lnd/blob/abb1e3463f3a83bbb843d5c399869dbe930ad94f/htlcswitch/link.go#L2119) To fix this we will send them a Bogus Channel Reestablish with 0 commitment_number and invalid last_per_commit_secret. Key Changes: - In connect_activate_subd, if we detect a stub channel, we serialize and send a bogus channel_reestablish message. Changelog-Fixed: Fixing LND's non responsive behaviour on receiving an error. --- lightningd/peer_control.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 56ea80828..129bd8cdf 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1377,6 +1377,32 @@ tell_connectd: send_error: log_debug(channel->log, "Telling connectd to send error %s", tal_hex(tmpctx, error)); + + /* LND does not respond to errors with a unilateral close + * (https://github.com/lightningnetwork/lnd/blob/abb1e3463f3a83bbb843d5c399869dbe930ad94f/htlcswitch/link.go#L2119). + * We fix this by sending a `ChannelReestablish` msg with `0` commitment numbers and an + * invalid `your_last_per_commitment_secret`. */ + if (is_stub_scid(*channel->scid)) { + struct secret your_last_per_commit_secret; + memset(&your_last_per_commit_secret, 1, + sizeof(your_last_per_commit_secret)); + + const u8 *msg = towire_channel_reestablish(tmpctx, &channel->cid, + 0, + 0, + &your_last_per_commit_secret, + &channel->channel_info.remote_per_commit, + NULL); + + log_debug(channel->log, "Sending a bogus channel_reestablish message to make the peer " + "unilaterally close the channel."); + + subd_send_msg(ld->connectd, + take(towire_connectd_peer_send_msg(NULL, &channel->peer->id, + channel->peer->connectd_counter, + msg))); + } + /* Get connectd to send error and close. */ subd_send_msg(ld->connectd, take(towire_connectd_peer_send_msg(NULL, &channel->peer->id,