tsimplify lnrouter API - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit d5c360a958f3666ad137443f812e7923c039ab52 DIR parent 805c5a2120bdc9861cf2cb8d4fee47e1dc31f1dc HTML Author: ThomasV <thomasv@electrum.org> Date: Sun, 10 Jan 2021 18:41:22 +0100 simplify lnrouter API Diffstat: M electrum/lnrouter.py | 7 +++++++ M electrum/lnworker.py | 28 ++++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-) --- DIR diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py t@@ -310,3 +310,10 @@ class LNPathFinder(Logger): node_info=node_info)) prev_node_id = node_id return route + + def find_route(self, nodeA: bytes, nodeB: bytes, invoice_amount_msat: int, *, + path = None, my_channels: Dict[ShortChannelID, 'Channel'] = None) -> Optional[LNPaymentRoute]: + if not path: + path = self.find_path_for_payment(nodeA, nodeB, invoice_amount_msat, my_channels=my_channels) + if path: + return self.create_route_from_path(path, nodeA, my_channels=my_channels) DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -1140,17 +1140,15 @@ class LNWallet(LNWorker): path = full_path[:-len(private_route)] else: # find path now on public graph, to border node - path = self.network.path_finder.find_path_for_payment( - self.node_keypair.pubkey, border_node_pubkey, amount_msat, - my_channels=scid_to_my_channels) - if not path: - continue + path = None try: - route = self.network.path_finder.create_route_from_path( - path, self.node_keypair.pubkey, - my_channels=scid_to_my_channels) + route = self.network.path_finder.find_route( + self.node_keypair.pubkey, border_node_pubkey, amount_msat, + path=path, my_channels=scid_to_my_channels) except NoChannelPolicy: continue + if not route: + continue # we need to shift the node pubkey by one towards the destination: private_route_nodes = [edge[0] for edge in private_route][1:] + [invoice_pubkey] private_route_rest = [edge[1:] for edge in private_route] t@@ -1186,17 +1184,11 @@ class LNWallet(LNWorker): break # if could not find route using any hint; try without hint now if route is None: - if full_path: # user pre-selected path - path = full_path - else: # find path now - path = self.network.path_finder.find_path_for_payment( - self.node_keypair.pubkey, invoice_pubkey, amount_msat, - my_channels=scid_to_my_channels) - if not path: + route = self.network.path_finder.find_route( + self.node_keypair.pubkey, invoice_pubkey, amount_msat, + path=full_path, my_channels=scid_to_my_channels) + if not route: raise NoPathFound() - route = self.network.path_finder.create_route_from_path( - path, self.node_keypair.pubkey, - my_channels=scid_to_my_channels) if not is_route_sane_to_use(route, amount_msat, decoded_invoice.get_min_final_cltv_expiry()): self.logger.info(f"rejecting insane route {route}") raise NoPathFound()