mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Display channel status in the GUI.
Do not convert channel_id to integer; there is no reason to do that.
This commit is contained in:
parent
bf6d28e1f0
commit
21c883bd0b
3 changed files with 38 additions and 32 deletions
|
@ -2,35 +2,39 @@
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
from electrum.util import inv_dict, bh2u
|
from electrum.util import inv_dict, bh2u
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
from electrum.lnbase import OpenChannel
|
||||||
from .util import MyTreeWidget, SortableTreeWidgetItem
|
from .util import MyTreeWidget, SortableTreeWidgetItem
|
||||||
|
|
||||||
class ChannelsList(MyTreeWidget):
|
class ChannelsList(MyTreeWidget):
|
||||||
update_rows = QtCore.pyqtSignal(list)
|
update_rows = QtCore.pyqtSignal(list)
|
||||||
update_single_row = QtCore.pyqtSignal(dict)
|
update_single_row = QtCore.pyqtSignal(OpenChannel)
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Capacity'), _('Balance')], 0)
|
MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Capacity'), _('Balance'), _('Status')], 0)
|
||||||
self.main_window = parent
|
self.main_window = parent
|
||||||
self.update_rows.connect(self.do_update_rows)
|
self.update_rows.connect(self.do_update_rows)
|
||||||
self.update_single_row.connect(self.do_update_single_row)
|
self.update_single_row.connect(self.do_update_single_row)
|
||||||
|
|
||||||
def format_fields(self, chan):
|
def format_fields(self, chan):
|
||||||
return [bh2u(chan.node_id), self.parent.format_amount(chan.constraints.capacity), self.parent.format_amount(chan.local_state.amount_msat//1000)]
|
status = self.parent.wallet.lnworker.channel_state[chan.channel_id]
|
||||||
|
return [bh2u(chan.node_id), self.parent.format_amount(chan.constraints.capacity), self.parent.format_amount(chan.local_state.amount_msat//1000), status]
|
||||||
|
|
||||||
def create_menu(self, position):
|
def create_menu(self, position):
|
||||||
menu = QtWidgets.QMenu()
|
menu = QtWidgets.QMenu()
|
||||||
cur = self.currentItem()
|
cur = self.currentItem()
|
||||||
|
print('ID', cur.data(0, QtCore.Qt.UserRole))
|
||||||
def close():
|
def close():
|
||||||
print("closechannel result", self.parent.network.lnworker.close_channel_from_other_thread(cur.di))
|
print("closechannel result", self.parent.wallet.lnworker.close_channel_from_other_thread(cur.di))
|
||||||
menu.addAction(_("Close channel"), close)
|
menu.addAction(_("Close channel"), close)
|
||||||
menu.exec_(self.viewport().mapToGlobal(position))
|
menu.exec_(self.viewport().mapToGlobal(position))
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
@QtCore.pyqtSlot(OpenChannel)
|
||||||
def do_update_single_row(self, chan):
|
def do_update_single_row(self, chan):
|
||||||
items = self.findItems(chan.channel_id, QtCore.Qt.UserRole|QtCore.Qt.MatchContains|QtCore.Qt.MatchRecursive, column=1)
|
for i in range(self.topLevelItemCount()):
|
||||||
for item in items:
|
item = self.topLevelItem(i)
|
||||||
for i, v in enumerate(self.format_fields(chan)):
|
if item.data(0, QtCore.Qt.UserRole) == chan.channel_id:
|
||||||
item.setData(i, QtCore.Qt.DisplayRole, v)
|
for i, v in enumerate(self.format_fields(chan)):
|
||||||
|
item.setData(i, QtCore.Qt.DisplayRole, v)
|
||||||
|
|
||||||
@QtCore.pyqtSlot(list)
|
@QtCore.pyqtSlot(list)
|
||||||
def do_update_rows(self, channels):
|
def do_update_rows(self, channels):
|
||||||
|
@ -73,4 +77,4 @@ class ChannelsList(MyTreeWidget):
|
||||||
push_amt = int(push_amt_inp.text())
|
push_amt = int(push_amt_inp.text())
|
||||||
assert local_amt >= 200000
|
assert local_amt >= 200000
|
||||||
assert local_amt >= push_amt
|
assert local_amt >= push_amt
|
||||||
obj = self.parent.network.lnworker.open_channel(node_id, local_amt, push_amt, password)
|
obj = self.parent.wallet.lnworker.open_channel(node_id, local_amt, push_amt, password)
|
||||||
|
|
|
@ -583,6 +583,7 @@ class Peer(PrintError):
|
||||||
self.path_finder = path_finder
|
self.path_finder = path_finder
|
||||||
self.read_buffer = b''
|
self.read_buffer = b''
|
||||||
self.ping_time = 0
|
self.ping_time = 0
|
||||||
|
self.initialized = asyncio.Future()
|
||||||
self.channel_accepted = defaultdict(asyncio.Queue)
|
self.channel_accepted = defaultdict(asyncio.Queue)
|
||||||
self.funding_signed = defaultdict(asyncio.Queue)
|
self.funding_signed = defaultdict(asyncio.Queue)
|
||||||
self.remote_funding_locked = defaultdict(asyncio.Queue)
|
self.remote_funding_locked = defaultdict(asyncio.Queue)
|
||||||
|
@ -708,13 +709,13 @@ class Peer(PrintError):
|
||||||
self.channel_accepted[temp_chan_id].put_nowait(payload)
|
self.channel_accepted[temp_chan_id].put_nowait(payload)
|
||||||
|
|
||||||
def on_funding_signed(self, payload):
|
def on_funding_signed(self, payload):
|
||||||
channel_id = int.from_bytes(payload['channel_id'], 'big')
|
channel_id = payload['channel_id']
|
||||||
if channel_id not in self.funding_signed: raise Exception("Got unknown funding_signed")
|
if channel_id not in self.funding_signed: raise Exception("Got unknown funding_signed")
|
||||||
self.funding_signed[channel_id].put_nowait(payload)
|
self.funding_signed[channel_id].put_nowait(payload)
|
||||||
|
|
||||||
def on_funding_locked(self, payload):
|
def on_funding_locked(self, payload):
|
||||||
channel_id = int.from_bytes(payload['channel_id'], 'big')
|
channel_id = payload['channel_id']
|
||||||
if channel_id not in self.funding_signed: print("Got unknown funding_locked", payload)
|
if channel_id not in self.remote_funding_locked: print("Got unknown funding_locked", payload)
|
||||||
self.remote_funding_locked[channel_id].put_nowait(payload)
|
self.remote_funding_locked[channel_id].put_nowait(payload)
|
||||||
|
|
||||||
def on_node_announcement(self, payload):
|
def on_node_announcement(self, payload):
|
||||||
|
@ -771,8 +772,9 @@ class Peer(PrintError):
|
||||||
# read init
|
# read init
|
||||||
msg = await self.read_message()
|
msg = await self.read_message()
|
||||||
self.process_message(msg)
|
self.process_message(msg)
|
||||||
|
self.initialized.set_result(True)
|
||||||
# reestablish channels
|
# reestablish channels
|
||||||
[await self.reestablish_channel(c) for c in self.channels.values()]
|
[self.reestablish_channel(c) for c in self.channels.values()]
|
||||||
# loop
|
# loop
|
||||||
while True:
|
while True:
|
||||||
self.ping_if_required()
|
self.ping_if_required()
|
||||||
|
@ -931,7 +933,9 @@ class Peer(PrintError):
|
||||||
)
|
)
|
||||||
return chan
|
return chan
|
||||||
|
|
||||||
async def reestablish_channel(self, chan):
|
def reestablish_channel(self, chan):
|
||||||
|
self.channel_state[chan.channel_id] = 'REESTABLISHING'
|
||||||
|
self.network.trigger_callback('channel', chan)
|
||||||
self.send_message(gen_msg("channel_reestablish",
|
self.send_message(gen_msg("channel_reestablish",
|
||||||
channel_id=chan.channel_id,
|
channel_id=chan.channel_id,
|
||||||
next_local_commitment_number=chan.local_state.ctn+1,
|
next_local_commitment_number=chan.local_state.ctn+1,
|
||||||
|
@ -939,12 +943,10 @@ class Peer(PrintError):
|
||||||
))
|
))
|
||||||
|
|
||||||
def on_channel_reestablish(self, payload):
|
def on_channel_reestablish(self, payload):
|
||||||
chan_id = int.from_bytes(payload["channel_id"], 'big')
|
chan_id = payload["channel_id"]
|
||||||
for chan in self.channels.values():
|
chan = self.channels.get(chan_id)
|
||||||
if chan.channel_id == chan_id:
|
if not chan:
|
||||||
break
|
print("Warning: received unknown channel_reestablish", bh2u(chan_id))
|
||||||
else:
|
|
||||||
print("Warning: received unknown channel_reestablish", chan_id, list(self.channels.values()))
|
|
||||||
return
|
return
|
||||||
channel_reestablish_msg = payload
|
channel_reestablish_msg = payload
|
||||||
remote_ctn = int.from_bytes(channel_reestablish_msg["next_local_commitment_number"], 'big')
|
remote_ctn = int.from_bytes(channel_reestablish_msg["next_local_commitment_number"], 'big')
|
||||||
|
@ -955,11 +957,12 @@ class Peer(PrintError):
|
||||||
raise Exception("expected local ctn {}, got {}".format(chan.local_state.ctn, local_ctn))
|
raise Exception("expected local ctn {}, got {}".format(chan.local_state.ctn, local_ctn))
|
||||||
if channel_reestablish_msg["my_current_per_commitment_point"] != chan.remote_state.last_per_commitment_point:
|
if channel_reestablish_msg["my_current_per_commitment_point"] != chan.remote_state.last_per_commitment_point:
|
||||||
raise Exception("Remote PCP mismatch")
|
raise Exception("Remote PCP mismatch")
|
||||||
|
self.channel_state[chan_id] = 'OPEN' if chan.local_state.funding_locked_received else 'OPENING'
|
||||||
|
self.network.trigger_callback('channel', chan)
|
||||||
|
|
||||||
async def funding_locked(self, chan):
|
async def funding_locked(self, chan):
|
||||||
channel_id = chan.channel_id
|
channel_id = chan.channel_id
|
||||||
short_channel_id = chan.short_channel_id
|
short_channel_id = chan.short_channel_id
|
||||||
|
|
||||||
per_commitment_secret_index = 2**48 - 2
|
per_commitment_secret_index = 2**48 - 2
|
||||||
per_commitment_point_second = secret_to_pubkey(int.from_bytes(
|
per_commitment_point_second = secret_to_pubkey(int.from_bytes(
|
||||||
get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, per_commitment_secret_index), 'big'))
|
get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, per_commitment_secret_index), 'big'))
|
||||||
|
@ -1118,7 +1121,7 @@ class Peer(PrintError):
|
||||||
|
|
||||||
@aiosafe
|
@aiosafe
|
||||||
async def receive_commitment_revoke_ack(self, htlc, decoded, payment_preimage):
|
async def receive_commitment_revoke_ack(self, htlc, decoded, payment_preimage):
|
||||||
chan = self.channels[int.from_bytes(htlc['channel_id'], 'big')]
|
chan = self.channels[htlc['channel_id']]
|
||||||
channel_id = chan.channel_id
|
channel_id = chan.channel_id
|
||||||
expected_received_msat = int(decoded.amount * COIN * 1000)
|
expected_received_msat = int(decoded.amount * COIN * 1000)
|
||||||
while True:
|
while True:
|
||||||
|
@ -1238,11 +1241,11 @@ class Peer(PrintError):
|
||||||
|
|
||||||
def on_commitment_signed(self, payload):
|
def on_commitment_signed(self, payload):
|
||||||
self.print_error("commitment_signed", payload)
|
self.print_error("commitment_signed", payload)
|
||||||
channel_id = int.from_bytes(payload['channel_id'], 'big')
|
channel_id = payload['channel_id']
|
||||||
self.commitment_signed[channel_id].put_nowait(payload)
|
self.commitment_signed[channel_id].put_nowait(payload)
|
||||||
|
|
||||||
def on_update_fulfill_htlc(self, payload):
|
def on_update_fulfill_htlc(self, payload):
|
||||||
channel_id = int.from_bytes(payload["channel_id"], 'big')
|
channel_id = payload["channel_id"]
|
||||||
self.update_fulfill_htlc[channel_id].put_nowait(payload)
|
self.update_fulfill_htlc[channel_id].put_nowait(payload)
|
||||||
|
|
||||||
def on_update_fail_malformed_htlc(self, payload):
|
def on_update_fail_malformed_htlc(self, payload):
|
||||||
|
@ -1265,7 +1268,7 @@ class Peer(PrintError):
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
def on_revoke_and_ack(self, payload):
|
def on_revoke_and_ack(self, payload):
|
||||||
channel_id = int.from_bytes(payload["channel_id"], 'big')
|
channel_id = payload["channel_id"]
|
||||||
self.revoke_and_ack[channel_id].put_nowait(payload)
|
self.revoke_and_ack[channel_id].put_nowait(payload)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ from . import lnrouter
|
||||||
is_key = lambda k: k.endswith("_basepoint") or k.endswith("_key")
|
is_key = lambda k: k.endswith("_basepoint") or k.endswith("_key")
|
||||||
|
|
||||||
def maybeDecode(k, v):
|
def maybeDecode(k, v):
|
||||||
if k in ["node_id", "short_channel_id", "pubkey", "privkey", "last_per_commitment_point", "next_per_commitment_point", "per_commitment_secret_seed"] and v is not None:
|
if k in ["node_id", "channel_id", "short_channel_id", "pubkey", "privkey", "last_per_commitment_point", "next_per_commitment_point", "per_commitment_secret_seed"] and v is not None:
|
||||||
return binascii.unhexlify(v)
|
return binascii.unhexlify(v)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -102,14 +102,12 @@ class LNWorker(PrintError):
|
||||||
self.nodes = {} # received node announcements
|
self.nodes = {} # received node announcements
|
||||||
self.channel_db = lnrouter.ChannelDB()
|
self.channel_db = lnrouter.ChannelDB()
|
||||||
self.path_finder = lnrouter.LNPathFinder(self.channel_db)
|
self.path_finder = lnrouter.LNPathFinder(self.channel_db)
|
||||||
self.channels = {x['channel_id']: reconstruct_namedtuples(x) for x in wallet.storage.get("channels", [])}
|
self.channels = {x.channel_id: x for x in map(reconstruct_namedtuples, wallet.storage.get("channels", []))}
|
||||||
self.invoices = wallet.storage.get('lightning_invoices', {})
|
self.invoices = wallet.storage.get('lightning_invoices', {})
|
||||||
peer_list = network.config.get('lightning_peers', node_list)
|
peer_list = network.config.get('lightning_peers', node_list)
|
||||||
self.channel_state = {chan.channel_id: "OPENING" for chan in self.channels.values()}
|
self.channel_state = {chan.channel_id: "DISCONNECTED" for chan in self.channels.values()}
|
||||||
for host, port, pubkey in peer_list:
|
for host, port, pubkey in peer_list:
|
||||||
self.add_peer(host, int(port), pubkey)
|
self.add_peer(host, int(port), pubkey)
|
||||||
|
|
||||||
self.callbacks = defaultdict(list)
|
|
||||||
# wait until we see confirmations
|
# wait until we see confirmations
|
||||||
self.network.register_callback(self.on_network_update, ['updated', 'verified']) # thread safe
|
self.network.register_callback(self.on_network_update, ['updated', 'verified']) # thread safe
|
||||||
self.on_network_update('updated') # shortcut (don't block) if funding tx locked and verified
|
self.on_network_update('updated') # shortcut (don't block) if funding tx locked and verified
|
||||||
|
@ -159,7 +157,7 @@ class LNWorker(PrintError):
|
||||||
|
|
||||||
def on_network_update(self, event, *args):
|
def on_network_update(self, event, *args):
|
||||||
for chan in self.channels.values():
|
for chan in self.channels.values():
|
||||||
if self.channel_state[chan.channel_id] == "OPEN":
|
if self.channel_state[chan.channel_id] != "OPENING":
|
||||||
continue
|
continue
|
||||||
chan = self.save_short_chan_id(chan)
|
chan = self.save_short_chan_id(chan)
|
||||||
if not chan:
|
if not chan:
|
||||||
|
@ -171,6 +169,7 @@ class LNWorker(PrintError):
|
||||||
# aiosafe because we don't wait for result
|
# aiosafe because we don't wait for result
|
||||||
@aiosafe
|
@aiosafe
|
||||||
async def wait_funding_locked_and_mark_open(self, peer, chan):
|
async def wait_funding_locked_and_mark_open(self, peer, chan):
|
||||||
|
await peer.initialized
|
||||||
if self.channel_state[chan.channel_id] == "OPEN":
|
if self.channel_state[chan.channel_id] == "OPEN":
|
||||||
return
|
return
|
||||||
if not chan.local_state.funding_locked_received:
|
if not chan.local_state.funding_locked_received:
|
||||||
|
|
Loading…
Add table
Reference in a new issue