From 21baea1dc25aaba3fc806023c31ecb1f21627940 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sun, 25 Jul 2021 15:11:15 +0200 Subject: [PATCH] bugfix: consider own policy for last hop the idea is to ignore channels as the last hop if we'd earn less by sending the rebalanced sats back through that channel, compared to what we won't be able to earn because we take funds out of the channel of the first hop --- logic.py | 9 +++------ routes.py | 10 ++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/logic.py b/logic.py index 3c46452..bb949b0 100644 --- a/logic.py +++ b/logic.py @@ -53,20 +53,17 @@ def rebalance(self): ) payment_request = self.generate_invoice() - min_fee_last_hop = None + min_ppm_last_hop = None if self.econ_fee and self.first_hop_channel: policy_first_hop = self.lnd.get_policy_to(self.first_hop_channel.chan_id) - fee_rate = policy_first_hop.fee_rate_milli_msat - min_fee_last_hop = self.econ_fee_factor * self.compute_fee( - self.amount, fee_rate, policy_first_hop - ) + min_ppm_last_hop = self.econ_fee_factor * policy_first_hop.fee_rate_milli_msat routes = Routes( self.lnd, payment_request, self.first_hop_channel, self.last_hop_channel, fee_limit_msat, - min_fee_last_hop, + min_ppm_last_hop, ) self.initialize_ignored_channels(routes, fee_limit_msat) diff --git a/routes.py b/routes.py index da55631..7b3473d 100644 --- a/routes.py +++ b/routes.py @@ -13,7 +13,7 @@ def __init__( first_hop_channel, last_hop_channel, fee_limit_msat, - min_fee_msat_last_hop, + min_ppm_last_hop, ): self.lnd = lnd self.payment_request = payment_request @@ -25,7 +25,7 @@ def __init__( self.ignored_nodes = [] self.num_requested_routes = 0 self.fee_limit_msat = fee_limit_msat - self.min_fee_msat_last_hop = min_fee_msat_last_hop + self.min_ppm_last_hop = min_ppm_last_hop def has_next(self): self.update_routes() @@ -112,9 +112,11 @@ def ignore_hop_on_route(self, hop_to_ignore, route): def ignore_high_fee_hops(self, route): ignore = [] - if self.min_fee_msat_last_hop: + if self.min_ppm_last_hop: last_hop = route.hops[-1] - if last_hop.fee_msat < self.min_fee_msat_last_hop: + policy = self.lnd.get_policy_to(last_hop.chan_id) + ppm_last_hop = policy.fee_rate_milli_msat + if ppm_last_hop < self.min_ppm_last_hop: ignore.append(last_hop) max_fee_msat = 0 max_fee_hop = None