mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 15:31:31 +00:00
lnrouter: simplify max fee sanity checks
This commit is contained in:
parent
2fab681444
commit
c81335fb44
1 changed files with 18 additions and 18 deletions
|
@ -74,16 +74,11 @@ class RouteEdge(NamedTuple):
|
||||||
def is_sane_to_use(self, amount_msat: int) -> bool:
|
def is_sane_to_use(self, amount_msat: int) -> bool:
|
||||||
# TODO revise ad-hoc heuristics
|
# TODO revise ad-hoc heuristics
|
||||||
# cltv cannot be more than 2 weeks
|
# 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)
|
total_fee = self.fee_for_edge(amount_msat)
|
||||||
# fees below 50 sat are fine
|
if not is_fee_sane(total_fee, payment_amount_msat=amount_msat):
|
||||||
if total_fee > 50_000:
|
return False
|
||||||
# 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
|
|
||||||
return True
|
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
|
total_fee = amt - invoice_amount_msat
|
||||||
# TODO revise ad-hoc heuristics
|
# TODO revise ad-hoc heuristics
|
||||||
# cltv cannot be more than 2 months
|
# cltv cannot be more than 2 months
|
||||||
if cltv > 60 * 144: return False
|
if cltv > 60 * 144:
|
||||||
# fees below 50 sat are fine
|
return False
|
||||||
if total_fee > 50_000:
|
if not is_fee_sane(total_fee, payment_amount_msat=invoice_amount_msat):
|
||||||
# fee cannot be higher than amt
|
return False
|
||||||
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
|
|
||||||
return True
|
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):
|
class LNPathFinder(Logger):
|
||||||
|
|
||||||
def __init__(self, channel_db: ChannelDB):
|
def __init__(self, channel_db: ChannelDB):
|
||||||
|
|
Loading…
Add table
Reference in a new issue