From 5e03d751ebb6b6f94fafbc800f34ad2bc7f09cc9 Mon Sep 17 00:00:00 2001 From: bitromortac Date: Fri, 9 Apr 2021 09:40:33 +0200 Subject: [PATCH] lnrouter: add hint timestamp --- electrum/commands.py | 4 ++++ electrum/lnrouter.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 96fca6ca6..91b2e10b2 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -1091,6 +1091,10 @@ class Commands: async def clear_ln_blacklist(self): self.network.path_finder.liquidity_hints.clear_blacklist() + @command('n') + async def reset_liquidity_hints(self): + self.network.path_finder.liquidity_hints.reset_liquidity_hints() + @command('w') async def list_invoices(self, wallet: Abstract_Wallet = None): l = wallet.get_invoices() diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py index e691766f3..0cb73b264 100644 --- a/electrum/lnrouter.py +++ b/electrum/lnrouter.py @@ -43,6 +43,7 @@ if TYPE_CHECKING: DEFAULT_PENALTY_BASE_MSAT = 500 # how much base fee we apply for unknown sending capability of a channel DEFAULT_PENALTY_PROPORTIONAL_MILLIONTH = 100 # how much relative fee we apply for unknown sending capability of a channel BLACKLIST_DURATION = 3600 # how long (in seconds) a channel remains blacklisted +HINT_DURATION = 3600 # how long (in seconds) a liquidity hint remains valid class NoChannelPolicy(Exception): @@ -181,10 +182,15 @@ class LiquidityHint: self._can_send_backward = None self._cannot_send_backward = None self.blacklist_timestamp = 0 + self.hint_timestamp = 0 + + def is_hint_invalid(self) -> bool: + now = int(time.time()) + return now - self.hint_timestamp > HINT_DURATION @property def can_send_forward(self): - return self._can_send_forward + return None if self.is_hint_invalid() else self._can_send_forward @can_send_forward.setter def can_send_forward(self, amount): @@ -199,7 +205,7 @@ class LiquidityHint: @property def can_send_backward(self): - return self._can_send_backward + return None if self.is_hint_invalid() else self._can_send_backward @can_send_backward.setter def can_send_backward(self, amount): @@ -211,7 +217,7 @@ class LiquidityHint: @property def cannot_send_forward(self): - return self._cannot_send_forward + return None if self.is_hint_invalid() else self._cannot_send_forward @cannot_send_forward.setter def cannot_send_forward(self, amount): @@ -228,7 +234,7 @@ class LiquidityHint: @property def cannot_send_backward(self): - return self._cannot_send_backward + return None if self.is_hint_invalid() else self._cannot_send_backward @cannot_send_backward.setter def cannot_send_backward(self, amount): @@ -254,12 +260,14 @@ class LiquidityHint: return self.cannot_send_backward def update_can_send(self, is_forward_direction: bool, amount: int): + self.hint_timestamp = int(time.time()) if is_forward_direction: self.can_send_forward = amount else: self.can_send_backward = amount def update_cannot_send(self, is_forward_direction: bool, amount: int): + self.hint_timestamp = int(time.time()) if is_forward_direction: self.cannot_send_forward = amount else: @@ -356,6 +364,11 @@ class LiquidityHintMgr: for k, v in self._liquidity_hints.items(): v.blacklist_timestamp = 0 + @with_lock + def reset_liquidity_hints(self): + for k, v in self._liquidity_hints.items(): + v.hint_timestamp = 0 + def __repr__(self): string = "liquidity hints:\n" if self._liquidity_hints: