simplify lnrouter API
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user