Browse Source

simplify lnrouter API

patch-4
ThomasV 4 years ago
parent
commit
d5c360a958
  1. 7
      electrum/lnrouter.py
  2. 28
      electrum/lnworker.py

7
electrum/lnrouter.py

@ -310,3 +310,10 @@ class LNPathFinder(Logger):
node_info=node_info)) node_info=node_info))
prev_node_id = node_id prev_node_id = node_id
return route 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)

28
electrum/lnworker.py

@ -1140,17 +1140,15 @@ class LNWallet(LNWorker):
path = full_path[:-len(private_route)] path = full_path[:-len(private_route)]
else: else:
# find path now on public graph, to border node # find path now on public graph, to border node
path = self.network.path_finder.find_path_for_payment( path = None
self.node_keypair.pubkey, border_node_pubkey, amount_msat,
my_channels=scid_to_my_channels)
if not path:
continue
try: try:
route = self.network.path_finder.create_route_from_path( route = self.network.path_finder.find_route(
path, self.node_keypair.pubkey, self.node_keypair.pubkey, border_node_pubkey, amount_msat,
my_channels=scid_to_my_channels) path=path, my_channels=scid_to_my_channels)
except NoChannelPolicy: except NoChannelPolicy:
continue continue
if not route:
continue
# we need to shift the node pubkey by one towards the destination: # 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_nodes = [edge[0] for edge in private_route][1:] + [invoice_pubkey]
private_route_rest = [edge[1:] for edge in private_route] private_route_rest = [edge[1:] for edge in private_route]
@ -1186,17 +1184,11 @@ class LNWallet(LNWorker):
break break
# if could not find route using any hint; try without hint now # if could not find route using any hint; try without hint now
if route is None: if route is None:
if full_path: # user pre-selected path route = self.network.path_finder.find_route(
path = full_path self.node_keypair.pubkey, invoice_pubkey, amount_msat,
else: # find path now path=full_path, my_channels=scid_to_my_channels)
path = self.network.path_finder.find_path_for_payment( if not route:
self.node_keypair.pubkey, invoice_pubkey, amount_msat,
my_channels=scid_to_my_channels)
if not path:
raise NoPathFound() 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()): 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}") self.logger.info(f"rejecting insane route {route}")
raise NoPathFound() raise NoPathFound()

Loading…
Cancel
Save