Skip to content

Commit

Permalink
bugfix: consider own policy for last hop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
C-Otto committed Jul 25, 2021
1 parent 18b2124 commit 21baea1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 3 additions & 6 deletions logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21baea1

Please sign in to comment.