Browse Source

Refresh LN status in GUI using network callback.

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 7 years ago
parent
commit
1db7a8334a
  1. 5
      electrum/gui/qt/main_window.py
  2. 5
      gui/qt/channels_list.py
  3. 5
      lib/lnbase.py
  4. 3
      lib/lnrouter.py
  5. 2
      lib/lnworker.py
  6. 1
      lib/tests/test_lnrouter.py

5
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}")

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

5
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']

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

2
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

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

Loading…
Cancel
Save