electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 1db7a8334afc8b2b60c7b87be1a12917439c1549
parent 9145d61797e9740d32a33c3e60788e07579d62e7
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 13 Jul 2018 12:28:00 +0200

Refresh LN status in GUI using network callback.

Diffstat:
Melectrum/gui/qt/main_window.py | 5++++-
Mgui/qt/channels_list.py | 5+++--
Mlib/lnbase.py | 5++---
Mlib/lnrouter.py | 3+++
Mlib/lnworker.py | 2+-
Mlib/tests/test_lnrouter.py | 1+
6 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -155,6 +155,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.create_status_bar() self.need_update = threading.Event() + self.need_update_ln = threading.Event() self.decimal_point = config.get('decimal_point', DECIMAL_POINT_DEFAULT) try: @@ -221,7 +222,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): interests = ['wallet_updated', 'network_updated', 'blockchain_updated', 'new_transaction', 'status', 'banner', 'verified', 'fee', 'fee_histogram', 'on_quotes', - 'on_history', 'channel', 'channels'] + 'on_history', 'channel', 'channels', 'ln_status'] # To avoid leaking references to "self" that prevent the # window from being GC-ed when closed, callbacks should be # methods of this class only, and specifically not be @@ -369,6 +370,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.channels_list.update_rows.emit(*args) elif event == 'channel': self.channels_list.update_single_row.emit(*args) + elif event == 'ln_status': + self.need_update_ln.set() else: self.logger.info(f"unexpected network message: {event} {args}") diff --git a/gui/qt/channels_list.py b/gui/qt/channels_list.py @@ -65,10 +65,11 @@ class ChannelsList(MyTreeWidget): h.addWidget(b) return h - def on_update(self): + def update_status(self): n = len(self.parent.network.lightning_nodes) + nc = len(self.parent.network.channel_db) np = len(self.parent.wallet.lnworker.peers) - self.status.setText(_('{} peers, {} nodes').format(np, n)) + self.status.setText(_('{} peers, {} nodes, {} channels').format(np, n, nc)) def new_channel_dialog(self): d = WindowModalDialog(self.parent, _('Open Channel')) diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -282,7 +282,6 @@ def aiosafe(f): class Peer(PrintError): def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False): - self.channel_update_event = asyncio.Event() self.host = host self.port = port self.pubkey = pubkey @@ -457,17 +456,17 @@ class Peer(PrintError): 'addresses': addresses } self.print_error('node announcement', binascii.hexlify(pubkey), alias, addresses) + self.network.trigger_callback('ln_status') def on_init(self, payload): pass def on_channel_update(self, payload): self.channel_db.on_channel_update(payload) - self.channel_update_event.set() def on_channel_announcement(self, payload): self.channel_db.on_channel_announcement(payload) - self.channel_update_event.set() + self.network.trigger_callback('ln_status') def on_announcement_signatures(self, payload): channel_id = payload['channel_id'] diff --git a/lib/lnrouter.py b/lib/lnrouter.py @@ -100,6 +100,9 @@ class ChannelDB(PrintError): self._id_to_channel_info = {} self._channels_for_node = defaultdict(set) # node -> set(short_channel_id) + def __len__(self): + return len(self._id_to_channel_info) + def get_channel_info(self, channel_id): return self._id_to_channel_info.get(channel_id, None) diff --git a/lib/lnworker.py b/lib/lnworker.py @@ -57,7 +57,7 @@ class LNWorker(PrintError): peer = Peer(self, host, int(port), node_id, request_initial_sync=self.config.get("request_initial_sync", True)) self.network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), asyncio.get_event_loop())) self.peers[node_id] = peer - self.lock = threading.Lock() + self.network.trigger_callback('ln_status') def save_channel(self, openchannel): assert type(openchannel) is HTLCStateMachine diff --git a/lib/tests/test_lnrouter.py b/lib/tests/test_lnrouter.py @@ -26,6 +26,7 @@ class Test_LNRouter(unittest.TestCase): def test_find_path_for_payment(self): class fake_network: channel_db = lnrouter.ChannelDB() + trigger_callback = lambda x: None class fake_ln_worker: path_finder = lnrouter.LNPathFinder(fake_network.channel_db) privkey = bitcoin.sha256('privkeyseed')