mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
lnworker: blacklist channel if policy is unchanged but has a new timestamp.
This commit is contained in:
parent
2d0ef78a11
commit
f4dc93cb7d
2 changed files with 39 additions and 13 deletions
|
@ -201,12 +201,14 @@ class UpdateStatus(IntEnum):
|
||||||
ORPHANED = 0
|
ORPHANED = 0
|
||||||
EXPIRED = 1
|
EXPIRED = 1
|
||||||
DEPRECATED = 2
|
DEPRECATED = 2
|
||||||
GOOD = 3
|
UNCHANGED = 3
|
||||||
|
GOOD = 4
|
||||||
|
|
||||||
class CategorizedChannelUpdates(NamedTuple):
|
class CategorizedChannelUpdates(NamedTuple):
|
||||||
orphaned: List # no channel announcement for channel update
|
orphaned: List # no channel announcement for channel update
|
||||||
expired: List # update older than two weeks
|
expired: List # update older than two weeks
|
||||||
deprecated: List # update older than database entry
|
deprecated: List # update older than database entry
|
||||||
|
unchanged: List # unchanged policies
|
||||||
good: List # good updates
|
good: List # good updates
|
||||||
|
|
||||||
|
|
||||||
|
@ -362,22 +364,39 @@ class ChannelDB(SqlDB):
|
||||||
if 'raw' in msg:
|
if 'raw' in msg:
|
||||||
self._db_save_channel(channel_info.short_channel_id, msg['raw'])
|
self._db_save_channel(channel_info.short_channel_id, msg['raw'])
|
||||||
|
|
||||||
def print_change(self, old_policy: Policy, new_policy: Policy):
|
def policy_changed(self, old_policy: Policy, new_policy: Policy, verbose: bool) -> bool:
|
||||||
# print what changed between policies
|
changed = False
|
||||||
if old_policy.cltv_expiry_delta != new_policy.cltv_expiry_delta:
|
if old_policy.cltv_expiry_delta != new_policy.cltv_expiry_delta:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'cltv_expiry_delta: {old_policy.cltv_expiry_delta} -> {new_policy.cltv_expiry_delta}')
|
self.logger.info(f'cltv_expiry_delta: {old_policy.cltv_expiry_delta} -> {new_policy.cltv_expiry_delta}')
|
||||||
if old_policy.htlc_minimum_msat != new_policy.htlc_minimum_msat:
|
if old_policy.htlc_minimum_msat != new_policy.htlc_minimum_msat:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'htlc_minimum_msat: {old_policy.htlc_minimum_msat} -> {new_policy.htlc_minimum_msat}')
|
self.logger.info(f'htlc_minimum_msat: {old_policy.htlc_minimum_msat} -> {new_policy.htlc_minimum_msat}')
|
||||||
if old_policy.htlc_maximum_msat != new_policy.htlc_maximum_msat:
|
if old_policy.htlc_maximum_msat != new_policy.htlc_maximum_msat:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'htlc_maximum_msat: {old_policy.htlc_maximum_msat} -> {new_policy.htlc_maximum_msat}')
|
self.logger.info(f'htlc_maximum_msat: {old_policy.htlc_maximum_msat} -> {new_policy.htlc_maximum_msat}')
|
||||||
if old_policy.fee_base_msat != new_policy.fee_base_msat:
|
if old_policy.fee_base_msat != new_policy.fee_base_msat:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'fee_base_msat: {old_policy.fee_base_msat} -> {new_policy.fee_base_msat}')
|
self.logger.info(f'fee_base_msat: {old_policy.fee_base_msat} -> {new_policy.fee_base_msat}')
|
||||||
if old_policy.fee_proportional_millionths != new_policy.fee_proportional_millionths:
|
if old_policy.fee_proportional_millionths != new_policy.fee_proportional_millionths:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'fee_proportional_millionths: {old_policy.fee_proportional_millionths} -> {new_policy.fee_proportional_millionths}')
|
self.logger.info(f'fee_proportional_millionths: {old_policy.fee_proportional_millionths} -> {new_policy.fee_proportional_millionths}')
|
||||||
if old_policy.channel_flags != new_policy.channel_flags:
|
if old_policy.channel_flags != new_policy.channel_flags:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'channel_flags: {old_policy.channel_flags} -> {new_policy.channel_flags}')
|
self.logger.info(f'channel_flags: {old_policy.channel_flags} -> {new_policy.channel_flags}')
|
||||||
if old_policy.message_flags != new_policy.message_flags:
|
if old_policy.message_flags != new_policy.message_flags:
|
||||||
|
changed |= True
|
||||||
|
if verbose:
|
||||||
self.logger.info(f'message_flags: {old_policy.message_flags} -> {new_policy.message_flags}')
|
self.logger.info(f'message_flags: {old_policy.message_flags} -> {new_policy.message_flags}')
|
||||||
|
if not changed and verbose:
|
||||||
|
self.logger.info(f'policy unchanged: {old_policy.timestamp} -> {new_policy.timestamp}')
|
||||||
|
return changed
|
||||||
|
|
||||||
def add_channel_update(self, payload, max_age=None, verify=False, verbose=True):
|
def add_channel_update(self, payload, max_age=None, verify=False, verbose=True):
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
@ -408,14 +427,16 @@ class ChannelDB(SqlDB):
|
||||||
self._update_num_policies_for_chan(short_channel_id)
|
self._update_num_policies_for_chan(short_channel_id)
|
||||||
if 'raw' in payload:
|
if 'raw' in payload:
|
||||||
self._db_save_policy(policy.key, payload['raw'])
|
self._db_save_policy(policy.key, payload['raw'])
|
||||||
if old_policy and verbose:
|
if old_policy and not self.policy_changed(old_policy, policy, verbose):
|
||||||
self.print_change(old_policy, policy)
|
return UpdateStatus.UNCHANGED
|
||||||
|
else:
|
||||||
return UpdateStatus.GOOD
|
return UpdateStatus.GOOD
|
||||||
|
|
||||||
def add_channel_updates(self, payloads, max_age=None) -> CategorizedChannelUpdates:
|
def add_channel_updates(self, payloads, max_age=None) -> CategorizedChannelUpdates:
|
||||||
orphaned = []
|
orphaned = []
|
||||||
expired = []
|
expired = []
|
||||||
deprecated = []
|
deprecated = []
|
||||||
|
unchanged = []
|
||||||
good = []
|
good = []
|
||||||
for payload in payloads:
|
for payload in payloads:
|
||||||
r = self.add_channel_update(payload, max_age=max_age, verbose=False)
|
r = self.add_channel_update(payload, max_age=max_age, verbose=False)
|
||||||
|
@ -425,6 +446,8 @@ class ChannelDB(SqlDB):
|
||||||
expired.append(payload)
|
expired.append(payload)
|
||||||
elif r == UpdateStatus.DEPRECATED:
|
elif r == UpdateStatus.DEPRECATED:
|
||||||
deprecated.append(payload)
|
deprecated.append(payload)
|
||||||
|
elif r == UpdateStatus.UNCHANGED:
|
||||||
|
unchanged.append(payload)
|
||||||
elif r == UpdateStatus.GOOD:
|
elif r == UpdateStatus.GOOD:
|
||||||
good.append(payload)
|
good.append(payload)
|
||||||
self.update_counts()
|
self.update_counts()
|
||||||
|
@ -432,6 +455,7 @@ class ChannelDB(SqlDB):
|
||||||
orphaned=orphaned,
|
orphaned=orphaned,
|
||||||
expired=expired,
|
expired=expired,
|
||||||
deprecated=deprecated,
|
deprecated=deprecated,
|
||||||
|
unchanged=unchanged,
|
||||||
good=good)
|
good=good)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -947,6 +947,8 @@ class LNWallet(LNWorker):
|
||||||
elif r == UpdateStatus.DEPRECATED:
|
elif r == UpdateStatus.DEPRECATED:
|
||||||
self.logger.info(f'channel update is not more recent.')
|
self.logger.info(f'channel update is not more recent.')
|
||||||
blacklist = True
|
blacklist = True
|
||||||
|
elif r == UpdateStatus.UNCHANGED:
|
||||||
|
blacklist = True
|
||||||
else:
|
else:
|
||||||
blacklist = True
|
blacklist = True
|
||||||
return blacklist
|
return blacklist
|
||||||
|
|
Loading…
Add table
Reference in a new issue