diff --git a/electrum/lntransport.py b/electrum/lntransport.py index f3c111112..72a5f172c 100644 --- a/electrum/lntransport.py +++ b/electrum/lntransport.py @@ -105,19 +105,19 @@ class LNTransportBase: self.writer.write(lc+c) async def read_messages(self): - read_buffer = b'' + buffer = bytearray() while True: rn_l, rk_l = self.rn() rn_m, rk_m = self.rn() while True: - if len(read_buffer) >= 18: - lc = read_buffer[:18] + if len(buffer) >= 18: + lc = bytes(buffer[:18]) l = aead_decrypt(rk_l, rn_l, b'', lc) length = int.from_bytes(l, 'big') offset = 18 + length + 16 - if len(read_buffer) >= offset: - c = read_buffer[18:offset] - read_buffer = read_buffer[offset:] + if len(buffer) >= offset: + c = bytes(buffer[18:offset]) + del buffer[:offset] # much faster than: buffer=buffer[offset:] msg = aead_decrypt(rk_m, rn_m, b'', c) yield msg break @@ -129,7 +129,7 @@ class LNTransportBase: s = None if not s: raise LightningPeerConnectionClosed() - read_buffer += s + buffer += s def rn(self): o = self._rn, self.rk