diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py index a7d022759..d85da3068 100644 --- a/electrum/lnrouter.py +++ b/electrum/lnrouter.py @@ -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 @@ -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):