mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 17:31:36 +00:00
PathFinder: change path element semantics from "from node, take edge" to "to get to node, use edge"
This commit is contained in:
parent
50cc603d91
commit
43eb33327e
1 changed files with 7 additions and 5 deletions
|
@ -18,7 +18,7 @@ import time
|
||||||
import binascii
|
import binascii
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union, Tuple
|
||||||
import cryptography.hazmat.primitives.ciphers.aead as AEAD
|
import cryptography.hazmat.primitives.ciphers.aead as AEAD
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
|
@ -1480,11 +1480,12 @@ class LNPathFinder(PrintError):
|
||||||
|
|
||||||
@profiler
|
@profiler
|
||||||
def find_path_for_payment(self, from_node_id: bytes, to_node_id: bytes,
|
def find_path_for_payment(self, from_node_id: bytes, to_node_id: bytes,
|
||||||
amount_msat: int=None) -> Sequence[bytes, bytes]:
|
amount_msat: int=None) -> Sequence[Tuple[bytes, bytes]]:
|
||||||
"""Return a path between from_node_id and to_node_id.
|
"""Return a path between from_node_id and to_node_id.
|
||||||
|
|
||||||
Returns a list of (node_id, short_channel_id) representing a path.
|
Returns a list of (node_id, short_channel_id) representing a path.
|
||||||
To get from node ret[n][0] to ret[n+1][0], use channel ret[n][1]
|
To get from node ret[n][0] to ret[n+1][0], use channel ret[n+1][1];
|
||||||
|
i.e. an element reads as, "to get to node_id, travel through short_channel_id"
|
||||||
"""
|
"""
|
||||||
# TODO find multiple paths??
|
# TODO find multiple paths??
|
||||||
|
|
||||||
|
@ -1519,10 +1520,11 @@ class LNPathFinder(PrintError):
|
||||||
|
|
||||||
# backtrack from end to start
|
# backtrack from end to start
|
||||||
cur_node = to_node_id
|
cur_node = to_node_id
|
||||||
path = [(cur_node, None)]
|
path = []
|
||||||
while cur_node != from_node_id:
|
while cur_node != from_node_id:
|
||||||
cur_node, edge_taken = prev_node[cur_node]
|
prev_node_id, edge_taken = prev_node[cur_node]
|
||||||
path += [(cur_node, edge_taken)]
|
path += [(cur_node, edge_taken)]
|
||||||
|
cur_node = prev_node_id
|
||||||
path.reverse()
|
path.reverse()
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue