lnrouter: add hint timestamp
This commit is contained in:
@@ -1091,6 +1091,10 @@ class Commands:
|
|||||||
async def clear_ln_blacklist(self):
|
async def clear_ln_blacklist(self):
|
||||||
self.network.path_finder.liquidity_hints.clear_blacklist()
|
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')
|
@command('w')
|
||||||
async def list_invoices(self, wallet: Abstract_Wallet = None):
|
async def list_invoices(self, wallet: Abstract_Wallet = None):
|
||||||
l = wallet.get_invoices()
|
l = wallet.get_invoices()
|
||||||
|
|||||||
@@ -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_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
|
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
|
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):
|
class NoChannelPolicy(Exception):
|
||||||
@@ -181,10 +182,15 @@ class LiquidityHint:
|
|||||||
self._can_send_backward = None
|
self._can_send_backward = None
|
||||||
self._cannot_send_backward = None
|
self._cannot_send_backward = None
|
||||||
self.blacklist_timestamp = 0
|
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
|
@property
|
||||||
def can_send_forward(self):
|
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
|
@can_send_forward.setter
|
||||||
def can_send_forward(self, amount):
|
def can_send_forward(self, amount):
|
||||||
@@ -199,7 +205,7 @@ class LiquidityHint:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def can_send_backward(self):
|
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
|
@can_send_backward.setter
|
||||||
def can_send_backward(self, amount):
|
def can_send_backward(self, amount):
|
||||||
@@ -211,7 +217,7 @@ class LiquidityHint:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def cannot_send_forward(self):
|
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
|
@cannot_send_forward.setter
|
||||||
def cannot_send_forward(self, amount):
|
def cannot_send_forward(self, amount):
|
||||||
@@ -228,7 +234,7 @@ class LiquidityHint:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def cannot_send_backward(self):
|
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
|
@cannot_send_backward.setter
|
||||||
def cannot_send_backward(self, amount):
|
def cannot_send_backward(self, amount):
|
||||||
@@ -254,12 +260,14 @@ class LiquidityHint:
|
|||||||
return self.cannot_send_backward
|
return self.cannot_send_backward
|
||||||
|
|
||||||
def update_can_send(self, is_forward_direction: bool, amount: int):
|
def update_can_send(self, is_forward_direction: bool, amount: int):
|
||||||
|
self.hint_timestamp = int(time.time())
|
||||||
if is_forward_direction:
|
if is_forward_direction:
|
||||||
self.can_send_forward = amount
|
self.can_send_forward = amount
|
||||||
else:
|
else:
|
||||||
self.can_send_backward = amount
|
self.can_send_backward = amount
|
||||||
|
|
||||||
def update_cannot_send(self, is_forward_direction: bool, amount: int):
|
def update_cannot_send(self, is_forward_direction: bool, amount: int):
|
||||||
|
self.hint_timestamp = int(time.time())
|
||||||
if is_forward_direction:
|
if is_forward_direction:
|
||||||
self.cannot_send_forward = amount
|
self.cannot_send_forward = amount
|
||||||
else:
|
else:
|
||||||
@@ -356,6 +364,11 @@ class LiquidityHintMgr:
|
|||||||
for k, v in self._liquidity_hints.items():
|
for k, v in self._liquidity_hints.items():
|
||||||
v.blacklist_timestamp = 0
|
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):
|
def __repr__(self):
|
||||||
string = "liquidity hints:\n"
|
string = "liquidity hints:\n"
|
||||||
if self._liquidity_hints:
|
if self._liquidity_hints:
|
||||||
|
|||||||
Reference in New Issue
Block a user