From b55f9e9e6a2a578c9bd642baeef108e998bb379e Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 13 Jul 2019 08:46:17 +0200 Subject: [PATCH] Do not route through channels for which we did not receive both updates, because this often means one of the nodes is offline. --- electrum/channel_db.py | 10 ++++++++++ electrum/lnpeer.py | 3 +-- electrum/lnrouter.py | 10 +++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/electrum/channel_db.py b/electrum/channel_db.py index fef988454..79aa9a159 100644 --- a/electrum/channel_db.py +++ b/electrum/channel_db.py @@ -527,6 +527,16 @@ class ChannelDB(SqlDB): self._channels_for_node[channel_info.node2_id].add(channel_info.short_channel_id) self.logger.info(f'load data {len(self._channels)} {len(self._policies)} {len(self._channels_for_node)}') self.update_counts() + self.count_incomplete_channels() + + def count_incomplete_channels(self): + out = set() + for short_channel_id, ci in self._channels.items(): + p1 = self.get_policy_for_node(short_channel_id, ci.node1_id) + p2 = self.get_policy_for_node(short_channel_id, ci.node2_id) + if p1 is None or p2 is not None: + out.add(short_channel_id) + self.logger.info(f'semi-orphaned: {len(out)}') def get_policy_for_node(self, short_channel_id: bytes, node_id: bytes) -> Optional['Policy']: return self._policies.get((node_id, short_channel_id)) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 9ddbd9492..04b2c398a 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1019,8 +1019,7 @@ class Peer(Logger): except IndexError: self.logger.info("payment destination reported error") else: - self.logger.info(f'blacklisting channel {bh2u(short_chan_id)}') - self.network.path_finder.blacklist.add(short_chan_id) + self.network.path_finder.add_to_blacklist(short_chan_id) def maybe_send_commitment(self, chan: Channel): ctn_to_sign = chan.get_current_ctn(REMOTE) + 1 diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py index 4a8354746..7fe67e354 100644 --- a/electrum/lnrouter.py +++ b/electrum/lnrouter.py @@ -129,6 +129,10 @@ class LNPathFinder(Logger): self.channel_db = channel_db self.blacklist = set() + def add_to_blacklist(self, short_channel_id): + self.logger.info(f'blacklisting channel {bh2u(short_channel_id)}') + self.blacklist.add(short_channel_id) + def _edge_cost(self, short_channel_id: bytes, start_node: bytes, end_node: bytes, payment_amt_msat: int, ignore_costs=False) -> Tuple[float, int]: """Heuristic cost of going through a channel. @@ -140,7 +144,11 @@ class LNPathFinder(Logger): channel_policy = self.channel_db.get_policy_for_node(short_channel_id, start_node) if channel_policy is None: return float('inf'), 0 - if channel_policy.is_disabled(): return float('inf'), 0 + # channels that did not publish both policies often return temporary channel failure + if self.channel_db.get_policy_for_node(short_channel_id, end_node) is None: + return float('inf'), 0 + if channel_policy.is_disabled(): + return float('inf'), 0 route_edge = RouteEdge.from_channel_policy(channel_policy, short_channel_id, end_node) if payment_amt_msat < channel_policy.htlc_minimum_msat: return float('inf'), 0 # payment amount too little