From a758c99bbefae136a2b0aff4b18a36ecf9136689 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 2 Jun 2022 18:28:21 +0200 Subject: [PATCH] kivy: add "clear all gossip" button in ln gossip dialog One usecase is perhaps to save space if using trampoline anyway... more importantly, if using gossip, LNGossip is heavily filtering what messages we request and get, and e.g. can missing new NodeAnnouncements, etc, and this is a quick-and-dirty workaround to force a fresh start. --- electrum/channel_db.py | 7 ++++- electrum/gui/kivy/main_window.py | 27 +++++++++++++++++++ electrum/gui/kivy/uix/ui_screens/lightning.kv | 11 ++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/electrum/channel_db.py b/electrum/channel_db.py index 33ca2020a..a8e2452df 100644 --- a/electrum/channel_db.py +++ b/electrum/channel_db.py @@ -51,6 +51,7 @@ if TYPE_CHECKING: from .network import Network from .lnchannel import Channel from .lnrouter import RouteEdge + from .simple_config import SimpleConfig FLAG_DISABLE = 1 << 1 @@ -304,7 +305,7 @@ class ChannelDB(SqlDB): NUM_MAX_RECENT_PEERS = 20 def __init__(self, network: 'Network'): - path = os.path.join(get_headers_dir(network.config), 'gossip_db') + path = self.get_file_path(network.config) super().__init__(network.asyncio_loop, path, commit_interval=100) self.lock = threading.RLock() self.num_nodes = 0 @@ -328,6 +329,10 @@ class ChannelDB(SqlDB): self.data_loaded = asyncio.Event() self.network = network # only for callback + @classmethod + def get_file_path(cls, config: 'SimpleConfig') -> str: + return os.path.join(get_headers_dir(config), 'gossip_db') + def update_counts(self): self.num_nodes = len(self._nodes) self.num_channels = len(self._channels) diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index c106f00da..dd30e7175 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -783,6 +783,33 @@ class ElectrumWindow(App, Logger): self._channels_dialog = LightningChannelsDialog(self) self._channels_dialog.open() + def delete_ln_gossip_dialog(self): + def delete_gossip(b: bool): + if not b: + return + if self.network: + self.network.run_from_another_thread( + self.network.stop_gossip(full_shutdown=True)) + + os.unlink(gossip_db_file) + self.show_error(_("Local gossip database deleted.")) + self.network.start_gossip() + + if self.network is None or self.network.channel_db is None: + return # TODO show msg to user, or the button should be disabled instead + gossip_db_file = self.network.channel_db.get_file_path(self.electrum_config) + try: + size_mb = os.path.getsize(gossip_db_file) / (1024**2) + except OSError: + self.logger.exception("Cannot get file size.") + return + d = Question( + _('Do you want to delete the local gossip database?') + '\n' + + '(' + _('file size') + f': {size_mb:.2f} MiB)\n' + + _('It will be automatically re-downloaded after, unless you disable the gossip.'), + delete_gossip) + d.open() + def on_channel(self, evt, wallet, chan): if self._channels_dialog: Clock.schedule_once(lambda dt: self._channels_dialog.update()) diff --git a/electrum/gui/kivy/uix/ui_screens/lightning.kv b/electrum/gui/kivy/uix/ui_screens/lightning.kv index a239a13f1..f1975c2d7 100644 --- a/electrum/gui/kivy/uix/ui_screens/lightning.kv +++ b/electrum/gui/kivy/uix/ui_screens/lightning.kv @@ -26,3 +26,14 @@ Popup: SettingsItem: title: _("Pending") + ': ' + str(app.lightning_gossip_num_queries) description: _("Channel updates to query.") + BoxLayout: + size_hint: 1, None + height: '48dp' + Button: + size_hint: 0.5, None + height: '48dp' + text: _('Clear all gossip') + on_release: app.delete_ln_gossip_dialog() + Widget: + size_hint: 0.5, None + height: '48dp'