Browse Source

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.
patch-4
SomberNight 2 years ago
parent
commit
a758c99bbe
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 7
      electrum/channel_db.py
  2. 27
      electrum/gui/kivy/main_window.py
  3. 11
      electrum/gui/kivy/uix/ui_screens/lightning.kv

7
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)

27
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())

11
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'

Loading…
Cancel
Save