electrum

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

commit fdf8d8609b632b6a3bf4202656e528bcf375ad2c
parent 014b92139353145b67dff467fb4bb4743a9688b0
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:
Melectrum/lnpeer.py | 10++++++++--
Melectrum/lnutil.py | 2+-
2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -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 :( @@ -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() diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -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