mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 00:41:31 +00:00
fix: delete from channel_db
This commit is contained in:
parent
32fcad5bc3
commit
30e942bead
2 changed files with 17 additions and 9 deletions
|
@ -382,7 +382,8 @@ class ChannelDB(SqlDB):
|
|||
c.execute("""REPLACE INTO policy (key, cltv_expiry_delta, htlc_minimum_msat, htlc_maximum_msat, fee_base_msat, fee_proportional_millionths, channel_flags, timestamp) VALUES (?,?,?,?,?,?, ?, ?)""", list(policy))
|
||||
|
||||
@sql
|
||||
def delete_policy(self, short_channel_id, node_id):
|
||||
def delete_policy(self, node_id, short_channel_id):
|
||||
key = short_channel_id + node_id
|
||||
c = self.conn.cursor()
|
||||
c.execute("""DELETE FROM policy WHERE key=?""", (key,))
|
||||
|
||||
|
@ -391,6 +392,11 @@ class ChannelDB(SqlDB):
|
|||
c = self.conn.cursor()
|
||||
c.execute("REPLACE INTO channel_info (short_channel_id, node1_id, node2_id, capacity_sat) VALUES (?,?,?,?)", list(channel_info))
|
||||
|
||||
@sql
|
||||
def delete_channel(self, short_channel_id):
|
||||
c = self.conn.cursor()
|
||||
c.execute("""DELETE FROM channel_info WHERE short_channel_id=?""", (short_channel_id,))
|
||||
|
||||
@sql
|
||||
def save_node(self, node_info):
|
||||
c = self.conn.cursor()
|
||||
|
@ -467,6 +473,7 @@ class ChannelDB(SqlDB):
|
|||
l = self.get_old_policies(delta)
|
||||
for k in l:
|
||||
self._policies.pop(k)
|
||||
self.delete_policy(*k)
|
||||
if l:
|
||||
self.logger.info(f'Deleting {len(l)} old policies')
|
||||
|
||||
|
@ -476,8 +483,9 @@ class ChannelDB(SqlDB):
|
|||
|
||||
def prune_orphaned_channels(self):
|
||||
l = self.get_orphaned_channels()
|
||||
for k in l:
|
||||
self.remove_channel(k)
|
||||
for short_channel_id in l:
|
||||
self.remove_channel(short_channel_id)
|
||||
self.delete_channel(short_channel_id)
|
||||
self.update_counts()
|
||||
if l:
|
||||
self.logger.info(f'Deleting {len(l)} orphaned channels')
|
||||
|
|
|
@ -109,8 +109,6 @@ class LNWorker(Logger):
|
|||
|
||||
@log_exceptions
|
||||
async def main_loop(self):
|
||||
# fixme: only lngossip should do that
|
||||
await self.channel_db.load_data()
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
now = time.time()
|
||||
|
@ -265,11 +263,13 @@ class LNGossip(LNWorker):
|
|||
self.network.trigger_callback('ln_status', num_peers, num_nodes, known, unknown)
|
||||
|
||||
async def maintain_db(self):
|
||||
self.channel_db.prune_orphaned_channels()
|
||||
await self.channel_db.load_data()
|
||||
while True:
|
||||
self.channel_db.prune_old_policies(self.max_age)
|
||||
if len(self.unknown_ids) == 0:
|
||||
self.channel_db.prune_old_policies(self.max_age)
|
||||
self.channel_db.prune_orphaned_channels()
|
||||
self.refresh_gui()
|
||||
await asyncio.sleep(5)
|
||||
await asyncio.sleep(120)
|
||||
|
||||
async def add_new_ids(self, ids):
|
||||
known = self.channel_db.get_channel_ids()
|
||||
|
@ -277,7 +277,7 @@ class LNGossip(LNWorker):
|
|||
self.unknown_ids.update(new)
|
||||
|
||||
def get_ids_to_query(self):
|
||||
N = 100
|
||||
N = 500
|
||||
l = list(self.unknown_ids)
|
||||
self.unknown_ids = set(l[N:])
|
||||
return l[0:N]
|
||||
|
|
Loading…
Add table
Reference in a new issue