electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c010aa327e34273280abd0951e2a3ecb558c8b63
parent a81b0ecc591babb684e908c37c4e5e62145701c6
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 24 Sep 2020 01:52:35 +0200

lnworker: (fix) a listening node would busy-loop if remote DC-ed early

StreamReader.read() returns b'' on EOF, resulting in a busy loop

Diffstat:
Melectrum/lntransport.py | 10++++++++--
Melectrum/lnworker.py | 4++--
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/electrum/lntransport.py b/electrum/lntransport.py @@ -172,7 +172,10 @@ class LNResponderTransport(LNTransportBase): hs = HandshakeState(privkey_to_pubkey(self.privkey)) act1 = b'' while len(act1) < 50: - act1 += await self.reader.read(50 - len(act1)) + buf = await self.reader.read(50 - len(act1)) + if not buf: + raise HandshakeFailed('responder disconnected') + act1 += buf if len(act1) != 50: raise HandshakeFailed('responder: short act 1 read, length is ' + str(len(act1))) if bytes([act1[0]]) != HandshakeState.handshake_version: @@ -200,7 +203,10 @@ class LNResponderTransport(LNTransportBase): # act 3 act3 = b'' while len(act3) < 66: - act3 += await self.reader.read(66 - len(act3)) + buf = await self.reader.read(66 - len(act3)) + if not buf: + raise HandshakeFailed('responder disconnected') + act3 += buf if len(act3) != 66: raise HandshakeFailed('responder: short act 3 read, length is ' + str(len(act3))) if bytes([act3[0]]) != HandshakeState.handshake_version: diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -193,8 +193,8 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]): transport = LNResponderTransport(self.node_keypair.privkey, reader, writer) try: node_id = await transport.handshake() - except: - self.logger.info('handshake failure from incoming connection') + except Exception as e: + self.logger.info(f'handshake failure from incoming connection: {e!r}') return peer = Peer(self, node_id, transport) with self.lock: