Skip to content

Commit

Permalink
Add synced_to_chain to the onchain matcher
Browse files Browse the repository at this point in the history
Add synced_to_chain as a criterion to the onchain matcher.
synced_to_chain becomes false if LND is not synced to the
chain for more than 5 minutes. In the past, this was an
indicator of a severe issue that required a hotfix for lnd.
  • Loading branch information
feelancer21 committed Jun 10, 2024
1 parent 401101f commit 2b103c8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Currently available properties:
| **onchain.conf_target** | defines the confirmation target that is used for the determination of the onchain fee rate (default: 6)|# blocks|
| **onchain.min_fee_rate** | match on the onchain fee rate|# sat per vbyte|
| **onchain.max_fee_rate** | match on the onchain fee rate|# sat per vbyte|
| **onchain.synced_to_chain** | match on the synced to chain. False if lnd is not synced to chain for 5 minutes.|true\|false|


File references should contain 1 item per line
Expand Down
14 changes: 14 additions & 0 deletions charge_lnd/lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, lnd_dir, server, tls_cert_path=None, macaroon_path=None):
self.graph = None
self.info = None
self.version = None
self.synced_to_chain = None
self.channels = None
self.node_info = {}
self.chan_info = {}
Expand Down Expand Up @@ -68,6 +69,19 @@ def get_info(self):

def supports_inbound_fees(self):
return self.min_version(0, 18)

def get_synced_to_chain(self):
# It can happen that lnd is not synced to the chain for a few seconds, typically
# after a new block has been found or after a restart of lnd. If lnd is still
# not synced to the chain after 5 minutes, we set the parameter to false.
if self.synced_to_chain is None:
self.synced_to_chain = False
for _ in range(300):
if self.lnstub.GetInfo(ln.GetInfoRequest()).synced_to_chain:
self.synced_to_chain = True
break
time.sleep(1)
return self.synced_to_chain

def get_feereport(self):
feereport = self.lnstub.FeeReport(ln.FeeReportRequest())
Expand Down
6 changes: 5 additions & 1 deletion charge_lnd/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,16 @@ def match_by_chan(self, channel, config):
return True

def match_by_onchain(self, channel, config):
accepted = ['min_fee_rate', 'max_fee_rate', 'conf_target']
accepted = ['min_fee_rate', 'max_fee_rate',
'conf_target', 'synced_to_chain']

for key in config.keys():
if key.split(".")[0] == 'onchain' and key.split(".")[1] not in accepted:
raise Exception("Unknown property '%s'" % key)

if 'onchain.synced_to_chain' in config and not config.getboolean('onchain.synced_to_chain') == self.lnd.get_synced_to_chain():
return False

fee_rate = self.lnd.get_fee_estimate(config.getint('onchain.conf_target', DEFAULT_CONF_TARGET))

if 'onchain.max_fee_rate' in config and not config.getfloat('onchain.max_fee_rate') >= fee_rate:
Expand Down
7 changes: 7 additions & 0 deletions examples/complex-ruleset.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ base_fee_msat = 0
onchan.min_fee_rate = 500
base_fee_msat = 5_000

[lost-onchain-sync]
# The fact that lnd was not synchronized with the chain for more than 5 minutes
# was an indicator of a severe problem in the past.
onchain.synced_to_chain = false
base_fee_msat = 210_000
fee_ppm = 210_000

[ignored_channels]
# don't let charge-lnd set fees (strategy=ignore) for channels to/from the specified nodes
node.id = 02da8d5a759ee9e4438da617cfdb61c87f723fb76c4b6371b877d0347abe953a4f,
Expand Down

0 comments on commit 2b103c8

Please sign in to comment.