Browse Source

lnpeer: reduce log spam due to incompatible feature bits

master
SomberNight 6 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, LightningPeerConnectionClosed, HandshakeFailed, NotFoundChanAnnouncementForUpdate,
MINIMUM_MAX_HTLC_VALUE_IN_FLIGHT_ACCEPTED, MAXIMUM_HTLC_MINIMUM_MSAT_ACCEPTED, MINIMUM_MAX_HTLC_VALUE_IN_FLIGHT_ACCEPTED, MAXIMUM_HTLC_MINIMUM_MSAT_ACCEPTED,
MAXIMUM_REMOTE_TO_SELF_DELAY_ACCEPTED, RemoteMisbehaving, DEFAULT_TO_SELF_DELAY, 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 .lnutil import FeeUpdate
from .lntransport import LNTransport, LNTransportBase from .lntransport import LNTransport, LNTransportBase
from .lnmsg import encode_msg, decode_msg from .lnmsg import encode_msg, decode_msg
@ -193,9 +194,9 @@ class Peer(Logger):
their_localfeatures = int.from_bytes(payload['localfeatures'], byteorder="big") their_localfeatures = int.from_bytes(payload['localfeatures'], byteorder="big")
try: try:
self.localfeatures = ln_compare_features(self.localfeatures, their_localfeatures) self.localfeatures = ln_compare_features(self.localfeatures, their_localfeatures)
except ValueError as e: except IncompatibleLightningFeatures as e:
self.initialized.set_exception(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): if isinstance(self.transport, LNTransport):
self.channel_db.add_recent_peer(self.transport.peer_addr) self.channel_db.add_recent_peer(self.transport.peer_addr)
self._received_init = True self._received_init = True
@ -231,7 +232,7 @@ class Peer(Logger):
return await func(self, *args, **kwargs) return await func(self, *args, **kwargs)
except GracefulDisconnect as e: except GracefulDisconnect as e:
self.logger.log(e.log_level, f"Disconnecting: {repr(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)}") self.logger.info(f"Disconnecting: {repr(e)}")
finally: finally:
self.close_and_cleanup() self.close_and_cleanup()
@ -706,7 +707,6 @@ class Peer(Logger):
raise Exception(f'reserve too high: {remote_reserve_sat}, funding_sat: {funding_sat}') raise Exception(f'reserve too high: {remote_reserve_sat}, funding_sat: {funding_sat}')
return remote_reserve_sat return remote_reserve_sat
@log_exceptions
async def reestablish_channel(self, chan: Channel): async def reestablish_channel(self, chan: Channel):
await self.initialized await self.initialized
chan_id = chan.channel_id 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 # note that these are powers of two, not the bits themselves
LN_GLOBAL_FEATURES_KNOWN_SET = set(LnGlobalFeatures) LN_GLOBAL_FEATURES_KNOWN_SET = set(LnGlobalFeatures)
def ln_compare_features(our_features, their_features): class IncompatibleLightningFeatures(ValueError): pass
"""raises ValueError if incompatible"""
def ln_compare_features(our_features, their_features) -> int:
"""raises IncompatibleLightningFeatures if incompatible"""
our_flags = set(list_enabled_bits(our_features)) our_flags = set(list_enabled_bits(our_features))
their_flags = set(list_enabled_bits(their_features)) their_flags = set(list_enabled_bits(their_features))
for flag in our_flags: for flag in our_flags:
if flag not in their_flags and get_ln_flag_pair_of_bit(flag) not in their_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 :( # they don't have this feature we wanted :(
if flag % 2 == 0: # even flags are compulsory 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 our_features ^= 1 << flag # disable flag
else: else:
# They too have this flag. # They too have this flag.

Loading…
Cancel
Save