From fe1b2149cbadce8e9d4ad5e008e3ee60a0b3c1e4 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 28 Jan 2021 11:14:53 +0100 Subject: [PATCH] lnpeer: fix flen in INIT --- electrum/lnpeer.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index df4df5d11..85173c150 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -133,12 +133,16 @@ class Peer(Logger): async def initialize(self): if isinstance(self.transport, LNTransport): await self.transport.handshake() - # FIXME: "flen" hardcoded but actually it depends on "features"...: - self.send_message("init", gflen=0, flen=2, features=self.features.for_init_message(), - init_tlvs={ - 'networks': - {'chains': constants.net.rev_genesis_bytes()} - }) + features = self.features.for_init_message() + b = int.bit_length(features) + flen = b // 8 + int(bool(b % 8)) + self.send_message( + "init", gflen=0, flen=flen, + features=features, + init_tlvs={ + 'networks': + {'chains': constants.net.rev_genesis_bytes()} + }) self._sent_init = True self.maybe_set_initialized()