commit 4efcb53d24d5f1040556d5fb4194eb8007943602
parent 6045de759bdd5b47361d1749e210ddbd863100fb
Author: bitromortac <bitromortac@protonmail.com>
Date: Thu, 8 Oct 2020 06:36:02 +0200
network: load gossip db early
The gossip db is loaded early when the network is started to save
time when the gui is locked and a wallet not yet loaded. Side effects
of the LNWallet to start peering when a channel db is loaded is
circumvented.
Diffstat:
7 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/electrum/channel_db.py b/electrum/channel_db.py
@@ -613,6 +613,8 @@ class ChannelDB(SqlDB):
@sql
@profiler
def load_data(self):
+ if self.data_loaded.is_set():
+ return
# Note: this method takes several seconds... mostly due to lnmsg.decode_msg being slow.
# I believe lnmsg (and lightning.json) will need a rewrite anyway, so instead of tweaking
# load_data() here, that should be done. see #6006
diff --git a/electrum/daemon.py b/electrum/daemon.py
@@ -444,6 +444,9 @@ class Daemon(Logger):
daemon_jobs.append(self.watchtower.run)
if self.network:
self.network.start(jobs=[self.fx.run])
+ # prepare lightning functionality, also load channel db early
+ self.network.maybe_init_lightning()
+ self.network.channel_db.load_data()
self.taskgroup = TaskGroup()
asyncio.run_coroutine_threadsafe(self._run(jobs=daemon_jobs), self.asyncio_loop)
diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py
@@ -208,7 +208,7 @@ class ElectrumGui(Logger):
self.app.new_window_signal.emit(path, uri)
def show_lightning_dialog(self):
- if not self.daemon.network.is_lightning_running():
+ if not self.daemon.network.has_channel_db():
return
if not self.lightning_dialog:
self.lightning_dialog = LightningDialog(self)
diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py
@@ -79,7 +79,7 @@ class ChannelsList(MyTreeView):
labels[subject] = label
status = chan.get_state_for_GUI()
closed = chan.is_closed()
- if self.network and self.network.is_lightning_running():
+ if self.network and self.network.has_channel_db():
node_info = self.parent.network.channel_db.get_node_info_for_node_id(chan.node_id)
node_alias = (node_info.alias if node_info else '') or ''
else:
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -460,7 +460,7 @@ class LNGossip(LNWorker):
self.has_started = True
async def maintain_db(self):
- await self.channel_db.load_data()
+ await self.channel_db.data_loaded.wait()
while True:
if len(self.unknown_ids) == 0:
self.channel_db.prune_old_policies(self.max_age)
@@ -584,6 +584,10 @@ class LNWallet(LNWorker):
def start_network(self, network: 'Network'):
assert network
+ self.network = network
+ self.config = network.config
+ self.channel_db = self.network.channel_db
+
self.lnwatcher = LNWalletWatcher(self, network)
self.lnwatcher.start_network(network)
self.network = network
@@ -592,7 +596,6 @@ class LNWallet(LNWorker):
for chan in self.channels.values():
self.lnwatcher.add_channel(chan.funding_outpoint.to_str(), chan.get_funding_address())
- super().start_network(network)
for coro in [
self.maybe_listen(),
self.lnwatcher.on_network_update('network_updated'), # shortcut (don't block) if funding tx locked and verified
diff --git a/electrum/network.py b/electrum/network.py
@@ -344,7 +344,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
"""Our guess whether the device has Internet-connectivity."""
return self._has_ever_managed_to_connect_to_server
- def is_lightning_running(self):
+ def has_channel_db(self):
return self.channel_db is not None
def maybe_init_lightning(self):
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -363,7 +363,6 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
AddressSynchronizer.start_network(self, network)
if network:
if self.lnworker:
- network.maybe_init_lightning()
self.lnworker.start_network(network)
# only start gossiping when we already have channels
if self.db.get('channels'):