commit b55f9e9e6a2a578c9bd642baeef108e998bb379e
parent 30e942bead85cb7750fa6e669b7fa3313dc82317
Author: ThomasV <thomasv@electrum.org>
Date: Sat, 13 Jul 2019 08:46:17 +0200
Do not route through channels for which we did not receive
both updates, because this often means one of the nodes is
offline.
Diffstat:
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git 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
@@ -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
@@ -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