electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 7edbd5682ae2de059e7608b00ff7b6184c122e10
parent 2fafd01945569cb0ef1cad9320e426874fb40f7d
Author: SomberNight <somber.night@protonmail.com>
Date:   Sat, 20 Oct 2018 16:50:43 +0200

fix confusion re max path length

Diffstat:
Melectrum/lnonion.py | 6+++---
Melectrum/lnrouter.py | 6+++---
Melectrum/lnutil.py | 1+
Melectrum/lnworker.py | 4++--
4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/electrum/lnonion.py b/electrum/lnonion.py @@ -33,7 +33,7 @@ from cryptography.hazmat.backends import default_backend from . import ecc from .crypto import sha256, hmac_oneshot 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 @@ -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, and the amount_msat and cltv to be used on our immediate channel. """ - if len(route) > NUM_MAX_HOPS_IN_PAYMENT_PATH: - raise PaymentFailure(f"too long route ({len(route)} hops)") + if len(route) > NUM_MAX_EDGES_IN_PAYMENT_PATH: + raise PaymentFailure(f"too long route ({len(route)} edges)") amt = amount_msat cltv = final_cltv diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py @@ -39,7 +39,7 @@ from .storage import JsonDB from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update from .crypto import Hash 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 @@ -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. 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 amt = invoice_amount_msat 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))) # 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 distance_from_start = defaultdict(lambda: float('inf')) diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -614,4 +614,5 @@ class EncumberedTransaction(NamedTuple("EncumberedTransaction", [('tx', Transact NUM_MAX_HOPS_IN_PAYMENT_PATH = 20 +NUM_MAX_EDGES_IN_PAYMENT_PATH = NUM_MAX_HOPS_IN_PAYMENT_PATH + 1 diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -26,7 +26,7 @@ from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr, PaymentFailure, split_host_port, ConnStringFormatError, generate_keypair, LnKeyFamily, LOCAL, REMOTE, UnknownPaymentHash, MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE, - NUM_MAX_HOPS_IN_PAYMENT_PATH) + NUM_MAX_EDGES_IN_PAYMENT_PATH) from .lnaddr import lndecode from .i18n import _ from .lnrouter import RouteEdge, is_route_sane_to_use @@ -286,7 +286,7 @@ class LNWorker(PrintError): channels = list(self.channels.values()) for private_route in r_tags: 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] path = self.network.path_finder.find_path_for_payment(self.node_keypair.pubkey, border_node_pubkey, amount_msat, channels) if not path: continue