URI: 
       tlnpeer: reduce log spam due to incompatible feature bits - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 6161853941399b4746312aed7ffc6f0020ad027a
   DIR parent e54c69b861c2990adf9cf618b68c6f1c7dd3ebea
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Wed, 26 Feb 2020 21:10:33 +0100
       
       lnpeer: reduce log spam due to incompatible feature bits
       
       Diffstat:
         M electrum/lnpeer.py                  |      10 +++++-----
         M electrum/lnutil.py                  |       8 +++++---
       
       2 files changed, 10 insertions(+), 8 deletions(-)
       ---
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -42,7 +42,8 @@ from .lnutil import (Outpoint, LocalConfig, RECEIVED, UpdateAddHtlc,
                             LightningPeerConnectionClosed, HandshakeFailed, NotFoundChanAnnouncementForUpdate,
                             MINIMUM_MAX_HTLC_VALUE_IN_FLIGHT_ACCEPTED, MAXIMUM_HTLC_MINIMUM_MSAT_ACCEPTED,
                             MAXIMUM_REMOTE_TO_SELF_DELAY_ACCEPTED, RemoteMisbehaving, DEFAULT_TO_SELF_DELAY,
       -                     NBLOCK_OUR_CLTV_EXPIRY_DELTA, format_short_channel_id, ShortChannelID)
       +                     NBLOCK_OUR_CLTV_EXPIRY_DELTA, format_short_channel_id, ShortChannelID,
       +                     IncompatibleLightningFeatures)
        from .lnutil import FeeUpdate
        from .lntransport import LNTransport, LNTransportBase
        from .lnmsg import encode_msg, decode_msg
       t@@ -193,9 +194,9 @@ class Peer(Logger):
                their_localfeatures = int.from_bytes(payload['localfeatures'], byteorder="big")
                try:
                    self.localfeatures = ln_compare_features(self.localfeatures, their_localfeatures)
       -        except ValueError as e:
       +        except IncompatibleLightningFeatures as e:
                    self.initialized.set_exception(e)
       -            raise GracefulDisconnect(f"remote does not support {str(e)}")
       +            raise GracefulDisconnect(f"{str(e)}")
                if isinstance(self.transport, LNTransport):
                    self.channel_db.add_recent_peer(self.transport.peer_addr)
                self._received_init = True
       t@@ -231,7 +232,7 @@ class Peer(Logger):
                        return await func(self, *args, **kwargs)
                    except GracefulDisconnect as e:
                        self.logger.log(e.log_level, f"Disconnecting: {repr(e)}")
       -            except LightningPeerConnectionClosed as e:
       +            except (LightningPeerConnectionClosed, IncompatibleLightningFeatures) as e:
                        self.logger.info(f"Disconnecting: {repr(e)}")
                    finally:
                        self.close_and_cleanup()
       t@@ -706,7 +707,6 @@ class Peer(Logger):
                    raise Exception(f'reserve too high: {remote_reserve_sat}, funding_sat: {funding_sat}')
                return remote_reserve_sat
        
       -    @log_exceptions
            async def reestablish_channel(self, chan: Channel):
                await self.initialized
                chan_id = chan.channel_id
   DIR diff --git a/electrum/lnutil.py b/electrum/lnutil.py
       t@@ -656,15 +656,17 @@ class LnGlobalFeatures(IntFlag):
        # note that these are powers of two, not the bits themselves
        LN_GLOBAL_FEATURES_KNOWN_SET = set(LnGlobalFeatures)
        
       -def ln_compare_features(our_features, their_features):
       -    """raises ValueError if incompatible"""
       +class IncompatibleLightningFeatures(ValueError): pass
       +
       +def ln_compare_features(our_features, their_features) -> int:
       +    """raises IncompatibleLightningFeatures if incompatible"""
            our_flags = set(list_enabled_bits(our_features))
            their_flags = set(list_enabled_bits(their_features))
            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 :(
                    if flag % 2 == 0:  # even flags are compulsory
       -                raise ValueError(LnLocalFeatures(1 << flag))
       +                raise IncompatibleLightningFeatures(f"remote does not support {LnLocalFeatures(1 << flag)!r}")
                    our_features ^= 1 << flag  # disable flag
                else:
                    # They too have this flag.