commit 30e942bead85cb7750fa6e669b7fa3313dc82317
parent 32fcad5bc3bd36d376ecf650633dd65af361e0b1
Author: ThomasV <thomasv@electrum.org>
Date: Thu, 11 Jul 2019 13:50:21 +0200
fix: delete from channel_db
Diffstat:
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/electrum/channel_db.py b/electrum/channel_db.py
@@ -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,))
@@ -392,6 +393,11 @@ class ChannelDB(SqlDB):
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()
c.execute("REPLACE INTO node_info (node_id, features, timestamp, alias) VALUES (?,?,?,?)", list(node_info))
@@ -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')
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -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]