feeadjuster: upgrade to new setchannel command

This commit is contained in:
Michael Schmoock
2022-04-03 17:01:51 +02:00
parent 5b2dd9a3f6
commit 5c43c7f3bf

View File

@@ -113,7 +113,10 @@ def setchannelfee(plugin: Plugin, scid: str, base: int, ppm: int):
if fees is None or base == fees['base'] and ppm == fees['ppm']:
return False
try:
plugin.rpc.setchannelfee(scid, base, ppm)
if plugin.rpcfeemethod == 'setchannel':
plugin.rpc.setchannel(scid, base, ppm) # new method
else:
plugin.rpc.setchannelfee(scid, base, ppm) # deprecated
return True
except RpcError as e:
plugin.log(f"Could not adjust fees for channel {scid}: '{e}'", level="error")
@@ -300,6 +303,11 @@ def init(options: dict, configuration: dict, plugin: Plugin, **kwargs):
and "destination" in c["command"]]) == 1:
plugin.listchannels_by_dst = True
# detect if server supports new 'setchannel' command over setchannelfee
plugin.rpcfeemethod = 'setchannelfee'
if len([c for c in rpchelp if c["command"].startswith("setchannel ")]) == 1:
plugin.rpcfeemethod = 'setchannel'
plugin.log(f"Plugin feeadjuster initialized "
f"({plugin.adj_basefee} base / {plugin.adj_ppmfee} ppm) with an "
f"imbalance of {int(100 * plugin.imbalance)}%/{int(100 * ( 1 - plugin.imbalance))}%, "