Browse Source

lnpeer: reduce log spam due to incompatible feature bits

hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
6161853941
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 10
      electrum/lnpeer.py
  2. 8
      electrum/lnutil.py

10
electrum/lnpeer.py

@ -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
@ -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
@ -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()
@ -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

8
electrum/lnutil.py

@ -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.

Loading…
Cancel
Save