commit 1139720b58034a4e8dd190faade7fc68665e05bd
parent b3b87555dcaae777486c5f8c36f9451682f03a7e
Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 1 Mar 2021 21:26:05 +0100
lnworker: fix handle_error_code_from_failed_htlc for private channels
if the last (private) edge of the route errors, we need to try other route hints (if any)
Diffstat:
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/electrum/channel_db.py b/electrum/channel_db.py
@@ -610,12 +610,20 @@ class ChannelDB(SqlDB):
self.update_counts()
self.logger.info(f'Deleting {len(orphaned_chans)} orphaned channels')
- def add_channel_update_for_private_channel(self, msg_payload: dict, start_node_id: bytes):
+ def add_channel_update_for_private_channel(self, msg_payload: dict, start_node_id: bytes) -> bool:
+ """Returns True iff the channel update was successfully added and it was different than
+ what we had before (if any).
+ """
if not verify_sig_for_channel_update(msg_payload, start_node_id):
- return # ignore
+ return False # ignore
short_channel_id = ShortChannelID(msg_payload['short_channel_id'])
msg_payload['start_node'] = start_node_id
- self._channel_updates_for_private_channels[(start_node_id, short_channel_id)] = msg_payload
+ key = (start_node_id, short_channel_id)
+ prev_chanupd = self._channel_updates_for_private_channels.get(key)
+ if prev_chanupd == msg_payload:
+ return False
+ self._channel_updates_for_private_channels[key] = msg_payload
+ return True
def remove_channel(self, short_channel_id: ShortChannelID):
# FIXME what about rm-ing policies?
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -1224,8 +1224,8 @@ class LNWallet(LNWorker):
# maybe it is a private channel (and data in invoice was outdated)
self.logger.info(f"Could not find {short_channel_id}. maybe update is for private channel?")
start_node_id = route[sender_idx].node_id
- self.channel_db.add_channel_update_for_private_channel(payload, start_node_id)
- #update = True # FIXME: we need to check if we actually updated something
+ update = self.channel_db.add_channel_update_for_private_channel(payload, start_node_id)
+ blacklist = not update
elif r == UpdateStatus.EXPIRED:
blacklist = True
elif r == UpdateStatus.DEPRECATED:
@@ -1568,6 +1568,8 @@ class LNWallet(LNWorker):
if [edge.short_channel_id for edge in full_path[-len(private_path):]] != [edge[1] for edge in private_path]:
continue
path = full_path[:-len(private_path)]
+ if any(edge.short_channel_id in blacklist for edge in private_route):
+ continue
try:
route = self.network.path_finder.find_route(
self.node_keypair.pubkey, border_node_pubkey, amount_for_node,