Browse Source

fix confusion re max path length

regtest_lnd
SomberNight 6 years ago
parent
commit
09f2867629
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 6
      electrum/lnonion.py
  2. 6
      electrum/lnrouter.py
  3. 1
      electrum/lnutil.py
  4. 4
      electrum/lnworker.py

6
electrum/lnonion.py

@ -33,7 +33,7 @@ from cryptography.hazmat.backends import default_backend
from . import ecc from . import ecc
from .crypto import sha256, hmac_oneshot from .crypto import sha256, hmac_oneshot
from .util import bh2u, profiler, xor_bytes, bfh from .util import bh2u, profiler, xor_bytes, bfh
from .lnutil import get_ecdh, PaymentFailure, NUM_MAX_HOPS_IN_PAYMENT_PATH from .lnutil import get_ecdh, PaymentFailure, NUM_MAX_HOPS_IN_PAYMENT_PATH, NUM_MAX_EDGES_IN_PAYMENT_PATH
from .lnrouter import RouteEdge from .lnrouter import RouteEdge
@ -191,8 +191,8 @@ def calc_hops_data_for_payment(route: List[RouteEdge], amount_msat: int, final_c
"""Returns the hops_data to be used for constructing an onion packet, """Returns the hops_data to be used for constructing an onion packet,
and the amount_msat and cltv to be used on our immediate channel. and the amount_msat and cltv to be used on our immediate channel.
""" """
if len(route) > NUM_MAX_HOPS_IN_PAYMENT_PATH: if len(route) > NUM_MAX_EDGES_IN_PAYMENT_PATH:
raise PaymentFailure(f"too long route ({len(route)} hops)") raise PaymentFailure(f"too long route ({len(route)} edges)")
amt = amount_msat amt = amount_msat
cltv = final_cltv cltv = final_cltv

6
electrum/lnrouter.py

@ -39,7 +39,7 @@ from .storage import JsonDB
from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update
from .crypto import Hash from .crypto import Hash
from . import ecc from . import ecc
from .lnutil import LN_GLOBAL_FEATURES_KNOWN_SET, LNPeerAddr, NUM_MAX_HOPS_IN_PAYMENT_PATH from .lnutil import LN_GLOBAL_FEATURES_KNOWN_SET, LNPeerAddr, NUM_MAX_EDGES_IN_PAYMENT_PATH
class UnknownEvenFeatureBits(Exception): pass class UnknownEvenFeatureBits(Exception): pass
@ -535,7 +535,7 @@ def is_route_sane_to_use(route: List[RouteEdge], invoice_amount_msat: int, min_f
"""Run some sanity checks on the whole route, before attempting to use it. """Run some sanity checks on the whole route, before attempting to use it.
called when we are paying; so e.g. lower cltv is better called when we are paying; so e.g. lower cltv is better
""" """
if len(route) > NUM_MAX_HOPS_IN_PAYMENT_PATH: if len(route) > NUM_MAX_EDGES_IN_PAYMENT_PATH:
return False return False
amt = invoice_amount_msat amt = invoice_amount_msat
cltv = min_final_cltv_expiry cltv = min_final_cltv_expiry
@ -606,7 +606,7 @@ class LNPathFinder(PrintError):
unable_channels = set(map(lambda x: x.short_channel_id, filter(lambda x: not x.can_pay(amount_msat), 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?? # TODO find multiple paths??
# FIXME paths cannot be longer than 20 (onion packet)... # FIXME paths cannot be longer than 21 edges (onion packet)...
# run Dijkstra # run Dijkstra
distance_from_start = defaultdict(lambda: float('inf')) distance_from_start = defaultdict(lambda: float('inf'))

1
electrum/lnutil.py

@ -614,4 +614,5 @@ class EncumberedTransaction(NamedTuple("EncumberedTransaction", [('tx', Transact
NUM_MAX_HOPS_IN_PAYMENT_PATH = 20 NUM_MAX_HOPS_IN_PAYMENT_PATH = 20
NUM_MAX_EDGES_IN_PAYMENT_PATH = NUM_MAX_HOPS_IN_PAYMENT_PATH + 1

4
electrum/lnworker.py

@ -26,7 +26,7 @@ from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
PaymentFailure, split_host_port, ConnStringFormatError, PaymentFailure, split_host_port, ConnStringFormatError,
generate_keypair, LnKeyFamily, LOCAL, REMOTE, generate_keypair, LnKeyFamily, LOCAL, REMOTE,
UnknownPaymentHash, MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE, UnknownPaymentHash, MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE,
NUM_MAX_HOPS_IN_PAYMENT_PATH) NUM_MAX_EDGES_IN_PAYMENT_PATH)
from .lnaddr import lndecode from .lnaddr import lndecode
from .i18n import _ from .i18n import _
from .lnrouter import RouteEdge, is_route_sane_to_use from .lnrouter import RouteEdge, is_route_sane_to_use
@ -286,7 +286,7 @@ class LNWorker(PrintError):
channels = list(self.channels.values()) channels = list(self.channels.values())
for private_route in r_tags: for private_route in r_tags:
if len(private_route) == 0: continue if len(private_route) == 0: continue
if len(private_route) > NUM_MAX_HOPS_IN_PAYMENT_PATH: continue if len(private_route) > NUM_MAX_EDGES_IN_PAYMENT_PATH: continue
border_node_pubkey = private_route[0][0] 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, channels) path = self.network.path_finder.find_path_for_payment(self.node_keypair.pubkey, border_node_pubkey, amount_msat, channels)
if not path: continue if not path: continue

Loading…
Cancel
Save