Skip to content

Commit 46ff44a

Browse files
committed
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.
1 parent 7e831ad commit 46ff44a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lightningd/peer_control.c

+26
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,32 @@ static void connect_activate_subd(struct lightningd *ld, struct channel *channel
13831383
send_error:
13841384
log_debug(channel->log, "Telling connectd to send error %s",
13851385
tal_hex(tmpctx, error));
1386+
1387+
/* LND does not respond to errors with a unilateral close
1388+
* (https://github.com/lightningnetwork/lnd/blob/abb1e3463f3a83bbb843d5c399869dbe930ad94f/htlcswitch/link.go#L2119).
1389+
* We fix this by sending a `ChannelReestablish` msg with `0` commitment numbers and an
1390+
* invalid `your_last_per_commitment_secret`. */
1391+
if (is_stub_scid(*channel->scid)) {
1392+
struct secret your_last_per_commit_secret;
1393+
memset(&your_last_per_commit_secret, 1,
1394+
sizeof(your_last_per_commit_secret));
1395+
1396+
const u8 *msg = towire_channel_reestablish(tmpctx, &channel->cid,
1397+
0,
1398+
0,
1399+
&your_last_per_commit_secret,
1400+
&channel->channel_info.remote_per_commit,
1401+
NULL);
1402+
1403+
log_debug(channel->log, "Sending a bogus channel_reestablish message to make the peer "
1404+
"unilaterally close the channel.");
1405+
1406+
subd_send_msg(ld->connectd,
1407+
take(towire_connectd_peer_send_msg(NULL, &channel->peer->id,
1408+
channel->peer->connectd_counter,
1409+
msg)));
1410+
}
1411+
13861412
/* Get connectd to send error and close. */
13871413
subd_send_msg(ld->connectd,
13881414
take(towire_connectd_peer_send_msg(NULL, &channel->peer->id,

0 commit comments

Comments
 (0)