From d80b30579e66422e8f878658c3e78e842f3cd45c Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 2 Sep 2020 11:54:57 +0200 Subject: [PATCH] feeadjuster: only update fees on substantial unbalancing 5% is a rather conservative value Signed-off-by: Antoine Poinsot --- feeadjuster/feeadjuster.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/feeadjuster/feeadjuster.py b/feeadjuster/feeadjuster.py index fca47c0..19293ca 100755 --- a/feeadjuster/feeadjuster.py +++ b/feeadjuster/feeadjuster.py @@ -22,16 +22,20 @@ def get_ratio(our_percentage): def maybe_adjust_fees(plugin: Plugin, scids: list): for scid in scids: - # FIXME: set a threshold to avoid flooding! - if True: - our = plugin.adj_balances[scid]["our"] - total = plugin.adj_balances[scid]["total"] - ratio = get_ratio(our / total) + our = plugin.adj_balances[scid]["our"] + total = plugin.adj_balances[scid]["total"] + percentage = our / total + last_percentage = plugin.adj_balances[scid].get("last_percentage") + + # Only update on substantial balance moves to avoid flooding + if last_percentage is None or abs(last_percentage - percentage) > 0.05: + ratio = get_ratio(percentage) try: plugin.rpc.setchannelfee(scid, int(plugin.adj_basefee * ratio), int(plugin.adj_ppmfee * ratio)) plugin.log("Adjusted fees of {} with a ratio of {}" .format(scid, ratio)) + plugin.adj_balances[scid]["last_percentage"] = percentage except RpcError as e: plugin.log("setchannelfee error: " + str(e), level="warn")