URI: 
       tlnrouter: simplify max fee sanity checks - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit c81335fb44e78ae4a2c7ef963e65384b18ca18d6
   DIR parent 2fab6814442ee843ab1271d2c83a873c1ea4b6f4
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Mon,  2 Mar 2020 19:55:11 +0100
       
       lnrouter: simplify max fee sanity checks
       
       Diffstat:
         M electrum/lnrouter.py                |      36 ++++++++++++++++----------------
       
       1 file changed, 18 insertions(+), 18 deletions(-)
       ---
   DIR diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py
       t@@ -74,16 +74,11 @@ class RouteEdge(NamedTuple):
            def is_sane_to_use(self, amount_msat: int) -> bool:
                # TODO revise ad-hoc heuristics
                # cltv cannot be more than 2 weeks
       -        if self.cltv_expiry_delta > 14 * 144: return False
       +        if self.cltv_expiry_delta > 14 * 144:
       +            return False
                total_fee = self.fee_for_edge(amount_msat)
       -        # fees below 50 sat are fine
       -        if total_fee > 50_000:
       -            # fee cannot be higher than amt
       -            if total_fee > amount_msat: return False
       -            # fee cannot be higher than 5000 sat
       -            if total_fee > 5_000_000: return False
       -            # unless amt is tiny, fee cannot be more than 10%
       -            if amount_msat > 1_000_000 and total_fee > amount_msat/10: return False
       +        if not is_fee_sane(total_fee, payment_amount_msat=amount_msat):
       +            return False
                return True
        
        
       t@@ -105,18 +100,23 @@ def is_route_sane_to_use(route: LNPaymentRoute, invoice_amount_msat: int, min_fi
            total_fee = amt - invoice_amount_msat
            # TODO revise ad-hoc heuristics
            # cltv cannot be more than 2 months
       -    if cltv > 60 * 144: return False
       -    # fees below 50 sat are fine
       -    if total_fee > 50_000:
       -        # fee cannot be higher than amt
       -        if total_fee > invoice_amount_msat: return False
       -        # fee cannot be higher than 5000 sat
       -        if total_fee > 5_000_000: return False
       -        # unless amt is tiny, fee cannot be more than 10%
       -        if invoice_amount_msat > 1_000_000 and total_fee > invoice_amount_msat/10: return False
       +    if cltv > 60 * 144:
       +        return False
       +    if not is_fee_sane(total_fee, payment_amount_msat=invoice_amount_msat):
       +        return False
            return True
        
        
       +def is_fee_sane(fee_msat: int, *, payment_amount_msat: int) -> bool:
       +    # fees <= 2 sat are fine
       +    if fee_msat <= 2_000:
       +        return True
       +    # fees <= 1 % of payment are fine
       +    if 100 * fee_msat <= payment_amount_msat:
       +        return True
       +    return False
       +
       +
        class LNPathFinder(Logger):
        
            def __init__(self, channel_db: ChannelDB):