mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
add peer suggestion to open channel dialog. move add_peer code back to lnworker constructor
This commit is contained in:
parent
2ee41975f9
commit
31b67c422b
3 changed files with 20 additions and 10 deletions
|
@ -72,12 +72,13 @@ class ChannelsList(MyTreeWidget):
|
|||
self.status.setText(_('{} peers, {} nodes, {} channels').format(np, n, nc))
|
||||
|
||||
def new_channel_dialog(self):
|
||||
lnworker = self.parent.wallet.lnworker
|
||||
d = WindowModalDialog(self.parent, _('Open Channel'))
|
||||
d.setFixedWidth(700)
|
||||
vbox = QVBoxLayout(d)
|
||||
h = QGridLayout()
|
||||
local_nodeid = QLineEdit()
|
||||
local_nodeid.setText(bh2u(self.parent.wallet.lnworker.pubkey))
|
||||
local_nodeid.setText(bh2u(lnworker.pubkey))
|
||||
local_nodeid.setReadOnly(True)
|
||||
local_nodeid.setCursorPosition(0)
|
||||
remote_nodeid = QLineEdit()
|
||||
|
@ -95,6 +96,9 @@ class ChannelsList(MyTreeWidget):
|
|||
h.addWidget(push_amt_inp, 3, 1)
|
||||
vbox.addLayout(h)
|
||||
vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
|
||||
suggestion = lnworker.suggest_peer() or b''
|
||||
remote_nodeid.setText(bh2u(suggestion))
|
||||
remote_nodeid.setCursorPosition(0)
|
||||
if not d.exec_():
|
||||
return
|
||||
local_amt = local_amt_inp.get_amount()
|
||||
|
@ -111,8 +115,8 @@ class ChannelsList(MyTreeWidget):
|
|||
except:
|
||||
self.parent.show_error(_('Invalid node ID, must be 33 bytes and hexadecimal'))
|
||||
return
|
||||
peer = self.parent.wallet.lnworker.peers.get(node_id)
|
||||
|
||||
peer = lnworker.peers.get(node_id)
|
||||
if not peer:
|
||||
known = node_id in self.parent.network.lightning_nodes
|
||||
if rest is not None:
|
||||
|
@ -131,8 +135,7 @@ class ChannelsList(MyTreeWidget):
|
|||
except:
|
||||
self.parent.show_error(_('Port number must be decimal'))
|
||||
return
|
||||
|
||||
self.parent.wallet.lnworker.add_peer(host, port, node_id)
|
||||
lnworker.add_peer(host, port, node_id)
|
||||
|
||||
self.main_window.protect(self.open_channel, (node_id, local_amt, push_amt))
|
||||
|
||||
|
|
|
@ -305,7 +305,7 @@ class Peer(PrintError):
|
|||
self.announcement_signatures = defaultdict(asyncio.Queue)
|
||||
self.update_fail_htlc = defaultdict(asyncio.Queue)
|
||||
self.localfeatures = (0x08 if request_initial_sync else 0)
|
||||
self.channels = lnworker.channels
|
||||
self.channels = lnworker.channels_for_peer(pubkey)
|
||||
self.invoices = lnworker.invoices
|
||||
self.attempted_route = {}
|
||||
|
||||
|
|
|
@ -43,11 +43,23 @@ class LNWorker(PrintError):
|
|||
self.channel_state = {chan.channel_id: "DISCONNECTED" for chan in self.channels.values()}
|
||||
for chan_id, chan in self.channels.items():
|
||||
self.network.lnwatcher.watch_channel(chan, self.on_channel_utxos)
|
||||
peer_list = self.config.get('lightning_peers', node_list)
|
||||
for host, port, pubkey in peer_list:
|
||||
self.add_peer(host, int(port), bfh(pubkey))
|
||||
# wait until we see confirmations
|
||||
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.network.futures.append(asyncio.run_coroutine_threadsafe(self.main_loop(), asyncio.get_event_loop()))
|
||||
|
||||
def suggest_peer(self):
|
||||
for node_id, peer in self.peers.items():
|
||||
print(bh2u(node_id), len(peer.channels))
|
||||
if len(peer.channels) > 0:
|
||||
continue
|
||||
if not(peer.initialized.done()):
|
||||
continue
|
||||
return node_id
|
||||
|
||||
def channels_for_peer(self, node_id):
|
||||
assert type(node_id) is bytes
|
||||
return {x: y for (x, y) in self.channels.items() if y.node_id == node_id}
|
||||
|
@ -63,8 +75,6 @@ class LNWorker(PrintError):
|
|||
if openchannel.channel_id not in self.channel_state:
|
||||
self.channel_state[openchannel.channel_id] = "OPENING"
|
||||
self.channels[openchannel.channel_id] = openchannel
|
||||
for node_id, peer in self.peers.items():
|
||||
peer.channels = self.channels_for_peer(node_id)
|
||||
if openchannel.remote_state.next_per_commitment_point == openchannel.remote_state.current_per_commitment_point:
|
||||
raise Exception("Tried to save channel with next_point == current_point, this should not happen")
|
||||
dumped = [x.serialize() for x in self.channels.values()]
|
||||
|
@ -188,9 +198,6 @@ class LNWorker(PrintError):
|
|||
|
||||
@aiosafe
|
||||
async def main_loop(self):
|
||||
peer_list = self.config.get('lightning_peers', node_list)
|
||||
for host, port, pubkey in peer_list:
|
||||
self.add_peer(host, int(port), bfh(pubkey))
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
for k, peer in list(self.peers.items()):
|
||||
|
|
Loading…
Add table
Reference in a new issue