tlnpeer: make feature-bit testing easier - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit fdf8d8609b632b6a3bf4202656e528bcf375ad2c DIR parent 014b92139353145b67dff467fb4bb4743a9688b0 HTML Author: SomberNight <somber.night@protonmail.com> Date: Fri, 2 Aug 2019 17:58:45 +0200 lnpeer: make feature-bit testing easier so that we can always test like: self.localfeatures & FEATURE_BIT_OPT Diffstat: M electrum/lnpeer.py | 10 ++++++++-- M electrum/lnutil.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) --- DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py t@@ -176,9 +176,9 @@ class Peer(Logger): return # if they required some even flag we don't have, they will close themselves # but if we require an even flag they don't have, we close - self.their_localfeatures = int.from_bytes(payload['localfeatures'], byteorder="big") + their_localfeatures = int.from_bytes(payload['localfeatures'], byteorder="big") our_flags = set(list_enabled_bits(self.localfeatures)) - their_flags = set(list_enabled_bits(self.their_localfeatures)) + their_flags = set(list_enabled_bits(their_localfeatures)) for flag in our_flags: if flag not in their_flags and get_ln_flag_pair_of_bit(flag) not in their_flags: # they don't have this feature we wanted :( t@@ -186,6 +186,12 @@ class Peer(Logger): raise GracefulDisconnect("remote does not have even flag {}" .format(str(LnLocalFeatures(1 << flag)))) self.localfeatures ^= 1 << flag # disable flag + else: + # They too have this flag. + # For easier feature-bit-testing, if this is an even flag, we also + # set the corresponding odd flag now. + if flag % 2 == 0 and self.localfeatures & (1 << flag): + self.localfeatures |= 1 << get_ln_flag_pair_of_bit(flag) if isinstance(self.transport, LNTransport): self.channel_db.add_recent_peer(self.transport.peer_addr) self.initialized.set() DIR diff --git a/electrum/lnutil.py b/electrum/lnutil.py t@@ -563,7 +563,7 @@ class LnLocalFeatures(IntFlag): LN_LOCAL_FEATURES_KNOWN_SET = set(LnLocalFeatures) -def get_ln_flag_pair_of_bit(flag_bit: int): +def get_ln_flag_pair_of_bit(flag_bit: int) -> int: """Ln Feature flags are assigned in pairs, one even, one odd. See BOLT-09. Return the other flag from the pair. e.g. 6 -> 7