From 2696e357c35c29eecfdd7b1b82f15d55e20bdf58 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 15 Jan 2024 21:23:53 +0000 Subject: [PATCH] lnpeer: add comment to on_channel_reestablish re blocking In particular, lnd sends both chan_reest and then an error ("sync error"). It is critical we process the chan_reest and transition to WE_ARE_TOXIC before processing the error (which would trigger us to force-close). see spec https://github.com/lightning/bolts/blame/8a64c6a1cef979b3f0cecb00ba7a48c2d28b3588/02-peer-protocol.md#L1504-L1506 : > - upon reconnection: > [...] > - MUST transmit channel_reestablish for each channel. > - MUST wait to receive the other node's channel_reestablish message before sending any other messages for that channel. --- electrum/lnpeer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index d7c3a7202..537eb292c 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1148,6 +1148,10 @@ class Peer(Logger): f"but close option is not allowed. {chan.get_state()=!r}") def on_channel_reestablish(self, chan: Channel, msg): + # Note: it is critical for this message handler to block processing of further messages, + # until this msg is processed. If we are behind (lost state), and send chan_reest to the remote, + # when the remote realizes we are behind, they might send an "error" message - but the spec mandates + # they send chan_reest first. If we processed the error first, we might force-close and lose money! their_next_local_ctn = msg["next_commitment_number"] their_oldest_unrevoked_remote_ctn = msg["next_revocation_number"] their_local_pcp = msg.get("my_current_per_commitment_point")