Browse Source

Refresh LN status in GUI using network callback.

regtest_lnd
ThomasV 7 years ago
committed by SomberNight
parent
commit
15bfd980bb
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  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

@ -157,6 +157,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.create_status_bar() self.create_status_bar()
self.need_update = threading.Event() self.need_update = threading.Event()
self.need_update_ln = threading.Event()
self.decimal_point = config.get('decimal_point', DECIMAL_POINT_DEFAULT) self.decimal_point = config.get('decimal_point', DECIMAL_POINT_DEFAULT)
try: try:
@ -223,7 +224,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
interests = ['wallet_updated', 'network_updated', 'blockchain_updated', interests = ['wallet_updated', 'network_updated', 'blockchain_updated',
'new_transaction', 'status', 'new_transaction', 'status',
'banner', 'verified', 'fee', 'fee_histogram', 'on_quotes', '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 # To avoid leaking references to "self" that prevent the
# window from being GC-ed when closed, callbacks should be # window from being GC-ed when closed, callbacks should be
# methods of this class only, and specifically not be # methods of this class only, and specifically not be
@ -371,6 +372,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.channels_list.update_rows.emit(*args) self.channels_list.update_rows.emit(*args)
elif event == 'channel': elif event == 'channel':
self.channels_list.update_single_row.emit(*args) self.channels_list.update_single_row.emit(*args)
elif event == 'ln_status':
self.need_update_ln.set()
else: else:
self.logger.info(f"unexpected network message: {event} {args}") 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) h.addWidget(b)
return h return h
def on_update(self): def update_status(self):
n = len(self.parent.network.lightning_nodes) n = len(self.parent.network.lightning_nodes)
nc = len(self.parent.network.channel_db)
np = len(self.parent.wallet.lnworker.peers) 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): def new_channel_dialog(self):
d = WindowModalDialog(self.parent, _('Open Channel')) d = WindowModalDialog(self.parent, _('Open Channel'))

5
lib/lnbase.py

@ -282,7 +282,6 @@ def aiosafe(f):
class Peer(PrintError): class Peer(PrintError):
def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False): def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False):
self.channel_update_event = asyncio.Event()
self.host = host self.host = host
self.port = port self.port = port
self.pubkey = pubkey self.pubkey = pubkey
@ -457,17 +456,17 @@ class Peer(PrintError):
'addresses': addresses 'addresses': addresses
} }
self.print_error('node announcement', binascii.hexlify(pubkey), alias, addresses) self.print_error('node announcement', binascii.hexlify(pubkey), alias, addresses)
self.network.trigger_callback('ln_status')
def on_init(self, payload): def on_init(self, payload):
pass pass
def on_channel_update(self, payload): def on_channel_update(self, payload):
self.channel_db.on_channel_update(payload) self.channel_db.on_channel_update(payload)
self.channel_update_event.set()
def on_channel_announcement(self, payload): def on_channel_announcement(self, payload):
self.channel_db.on_channel_announcement(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): def on_announcement_signatures(self, payload):
channel_id = payload['channel_id'] channel_id = payload['channel_id']

3
lib/lnrouter.py

@ -100,6 +100,9 @@ class ChannelDB(PrintError):
self._id_to_channel_info = {} self._id_to_channel_info = {}
self._channels_for_node = defaultdict(set) # node -> set(short_channel_id) 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): def get_channel_info(self, channel_id):
return self._id_to_channel_info.get(channel_id, None) 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)) 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.network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), asyncio.get_event_loop()))
self.peers[node_id] = peer self.peers[node_id] = peer
self.lock = threading.Lock() self.network.trigger_callback('ln_status')
def save_channel(self, openchannel): def save_channel(self, openchannel):
assert type(openchannel) is HTLCStateMachine 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): def test_find_path_for_payment(self):
class fake_network: class fake_network:
channel_db = lnrouter.ChannelDB() channel_db = lnrouter.ChannelDB()
trigger_callback = lambda x: None
class fake_ln_worker: class fake_ln_worker:
path_finder = lnrouter.LNPathFinder(fake_network.channel_db) path_finder = lnrouter.LNPathFinder(fake_network.channel_db)
privkey = bitcoin.sha256('privkeyseed') privkey = bitcoin.sha256('privkeyseed')

Loading…
Cancel
Save