Skip to content

Workaround for LND to cause a force-close on our channel #8213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,32 @@ static void connect_activate_subd(struct lightningd *ld, struct channel *channel
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,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2974,6 +2974,7 @@ def test_emergencyrecoverpenaltytxn(node_factory, bitcoind):
stubs = l1.rpc.emergencyrecover()["stubs"]
assert len(stubs) == 1
assert stubs[0] == _["channel_id"]
l1.daemon.wait_for_log('Sending a bogus channel_reestablish message to make the peer unilaterally close the channel.')
l1.daemon.wait_for_log('peer_out WIRE_ERROR')

# Restarting so that L1
Expand Down Expand Up @@ -3021,7 +3022,10 @@ def test_emergencyrecover(node_factory, bitcoind):
listfunds = l1.rpc.listfunds()["channels"][0]
assert listfunds["short_channel_id"] == "1x1x1"

l1.daemon.wait_for_log('Sending a bogus channel_reestablish message to make the peer unilaterally close the channel.')
l1.daemon.wait_for_log('peer_out WIRE_ERROR')

l2.daemon.wait_for_log('bad reestablish commitment_number: 0')
l2.daemon.wait_for_log('State changed from CHANNELD_NORMAL to AWAITING_UNILATERAL')

bitcoind.generate_block(5, wait_for_mempool=1)
Expand Down Expand Up @@ -3140,7 +3144,10 @@ def test_restorefrompeer(node_factory, bitcoind):

assert l1.rpc.restorefrompeer()['stubs'][0] == _['channel_id']

l1.daemon.wait_for_log('Sending a bogus channel_reestablish message to make the peer unilaterally close the channel.')
l1.daemon.wait_for_log('peer_out WIRE_ERROR')

l2.daemon.wait_for_log('bad reestablish commitment_number: 0')
l2.daemon.wait_for_log('State changed from CHANNELD_NORMAL to AWAITING_UNILATERAL')

bitcoind.generate_block(5, wait_for_mempool=1)
Expand Down
Loading