Browse Source

lnrouter: remove blacklist boolean

patch-4
bitromortac 4 years ago
parent
commit
bc20f57a78
No known key found for this signature in database GPG Key ID: 1965063FC13BEBE2
  1. 19
      electrum/lnrouter.py
  2. 4
      electrum/lnworker.py

19
electrum/lnrouter.py

@ -180,8 +180,7 @@ class LiquidityHint:
self._cannot_send_forward = None
self._can_send_backward = None
self._cannot_send_backward = None
self.is_blacklisted = False
self.timestamp = 0
self.blacklist_timestamp = 0
@property
def can_send_forward(self):
@ -267,9 +266,10 @@ class LiquidityHint:
self.cannot_send_backward = amount
def __repr__(self):
return f"forward: can send: {self._can_send_forward}, cannot send: {self._cannot_send_forward}, \n" \
f"backward: can send: {self._can_send_backward} cannot send: {self._cannot_send_backward}, \n" \
f"blacklisted: {self.is_blacklisted}"
is_blacklisted = False if not self.blacklist_timestamp else int(time.time()) - self.blacklist_timestamp < BLACKLIST_DURATION
return f"forward: can send: {self._can_send_forward} msat, cannot send: {self._cannot_send_forward} msat, \n" \
f"backward: can send: {self._can_send_backward} msat, cannot send: {self._cannot_send_backward} msat, \n" \
f"blacklisted: {is_blacklisted}"
class LiquidityHintMgr:
@ -341,21 +341,20 @@ class LiquidityHintMgr:
return fee_for_edge_msat(amount, DEFAULT_PENALTY_BASE_MSAT, DEFAULT_PENALTY_PROPORTIONAL_MILLIONTH)
@with_lock
def add_to_blacklist(self, node_from: bytes, node_to: bytes, channel_id: ShortChannelID):
def add_to_blacklist(self, channel_id: ShortChannelID):
hint = self.get_hint(channel_id)
hint.is_blacklisted = True
now = int(time.time())
hint.timestamp = now
hint.blacklist_timestamp = now
@with_lock
def get_blacklist(self) -> Set[ShortChannelID]:
now = int(time.time())
return set(k for k, v in self._liquidity_hints.items() if now - v.timestamp < BLACKLIST_DURATION)
return set(k for k, v in self._liquidity_hints.items() if now - v.blacklist_timestamp < BLACKLIST_DURATION)
@with_lock
def clear_blacklist(self):
for k, v in self._liquidity_hints.items():
v.is_blacklisted = False
v.blacklist_timestamp = 0
def __repr__(self):
string = "liquidity hints:\n"

4
electrum/lnworker.py

@ -1338,7 +1338,7 @@ class LNWallet(LNWorker):
failing_channel=ShortChannelID(payload['short_channel_id']))
elif blacklist:
self.network.path_finder.liquidity_hints.add_to_blacklist(
node_from, node_to, payload['short_channel_id'])
payload['short_channel_id'])
# if we can't decide on some action, we are stuck
if not (blacklist or update):
@ -1346,7 +1346,7 @@ class LNWallet(LNWorker):
# for errors that do not include a channel update
else:
self.network.path_finder.liquidity_hints.add_to_blacklist(node_from, node_to, fallback_channel)
self.network.path_finder.liquidity_hints.add_to_blacklist(fallback_channel)
def _handle_chanupd_from_failed_htlc(self, payload, *, route, sender_idx) -> Tuple[bool, bool]:
blacklist = False

Loading…
Cancel
Save