From cf9b9429663db2fa1adc58ee6ac1f3491bd4762a Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 3 Feb 2021 10:47:18 +0100 Subject: [PATCH] rebalance: fix potential looping mistakes --- rebalance/rebalance.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rebalance/rebalance.py b/rebalance/rebalance.py index 36e31d5..500bece 100755 --- a/rebalance/rebalance.py +++ b/rebalance/rebalance.py @@ -299,7 +299,7 @@ def get_ideal_ratio(channels: list, enough_liquidity: Millisatoshi): our = sum(ch["to_us_msat"] for ch in channels) total = sum(ch["total_msat"] for ch in channels) chs = list(channels) # get a copy! - while True: + while len(chs) > 0: ratio = int(our) / int(total) smallest_channel = min(chs, key=lambda ch: ch["total_msat"]) if smallest_channel["total_msat"] * min(ratio, 1 - ratio) > enough_liquidity: @@ -408,6 +408,8 @@ def maybe_rebalance_once(plugin: Plugin, failed_pairs: list): channels = get_open_channels(plugin) for ch1 in channels: for ch2 in channels: + if ch1 == ch2: + continue result = maybe_rebalance_pairs(plugin, ch1, ch2, failed_pairs) if result["success"] or plugin.rebalance_stop: return result