mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 18:25:21 +00:00
path finding: minor clean-up
This commit is contained in:
parent
e85226a6b3
commit
2d0cabbc5f
2 changed files with 10 additions and 7 deletions
|
@ -519,7 +519,7 @@ class LNPathFinder(PrintError):
|
|||
|
||||
@profiler
|
||||
def find_path_for_payment(self, from_node_id: bytes, to_node_id: bytes,
|
||||
amount_msat: int=None, my_channels: dict={}) -> Sequence[Tuple[bytes, bytes]]:
|
||||
amount_msat: int=None, my_channels: List=None) -> Sequence[Tuple[bytes, bytes]]:
|
||||
"""Return a path between from_node_id and to_node_id.
|
||||
|
||||
Returns a list of (node_id, short_channel_id) representing a path.
|
||||
|
@ -527,7 +527,8 @@ class LNPathFinder(PrintError):
|
|||
i.e. an element reads as, "to get to node_id, travel through short_channel_id"
|
||||
"""
|
||||
if amount_msat is not None: assert type(amount_msat) is int
|
||||
unable_channels = set(map(lambda x: x.short_channel_id, filter(lambda x: not x.can_pay(amount_msat), my_channels.values())))
|
||||
if my_channels is None: my_channels = []
|
||||
unable_channels = set(map(lambda x: x.short_channel_id, filter(lambda x: not x.can_pay(amount_msat), my_channels)))
|
||||
|
||||
# TODO find multiple paths??
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class LNWorker(PrintError):
|
|||
self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0)
|
||||
self.config = network.config
|
||||
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
||||
self.channels = {x.channel_id: x for x in map(Channel, wallet.storage.get("channels", []))} # type: Dict[bytes, HTLCStateMachine]
|
||||
self.channels = {x.channel_id: x for x in map(Channel, wallet.storage.get("channels", []))} # type: Dict[bytes, Channel]
|
||||
for c in self.channels.values():
|
||||
c.lnwatcher = network.lnwatcher
|
||||
c.sweep_address = self.sweep_address
|
||||
|
@ -277,11 +277,13 @@ class LNWorker(PrintError):
|
|||
# if there are multiple hints, we will use the first one that works,
|
||||
# from a random permutation
|
||||
random.shuffle(r_tags)
|
||||
with self.lock:
|
||||
channels = list(self.channels.values())
|
||||
for private_route in r_tags:
|
||||
if len(private_route) == 0: continue
|
||||
border_node_pubkey = private_route[0][0]
|
||||
path = self.network.path_finder.find_path_for_payment(self.node_keypair.pubkey, border_node_pubkey, amount_msat, self.channels)
|
||||
if path is None: continue
|
||||
path = self.network.path_finder.find_path_for_payment(self.node_keypair.pubkey, border_node_pubkey, amount_msat, channels)
|
||||
if not path: continue
|
||||
route = self.network.path_finder.create_route_from_path(path, self.node_keypair.pubkey)
|
||||
# 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]
|
||||
|
@ -293,8 +295,8 @@ class LNWorker(PrintError):
|
|||
break
|
||||
# if could not find route using any hint; try without hint now
|
||||
if route is None:
|
||||
path = self.network.path_finder.find_path_for_payment(self.node_keypair.pubkey, invoice_pubkey, amount_msat, self.channels)
|
||||
if path is None:
|
||||
path = self.network.path_finder.find_path_for_payment(self.node_keypair.pubkey, invoice_pubkey, amount_msat, channels)
|
||||
if not path:
|
||||
raise PaymentFailure(_("No path found"))
|
||||
route = self.network.path_finder.create_route_from_path(path, self.node_keypair.pubkey)
|
||||
return route
|
||||
|
|
Loading…
Add table
Reference in a new issue