Browse Source

use WaitingDialog to close channels

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
eb4e6b2e54
  1. 28
      electrum/gui/qt/channels_list.py
  2. 15
      electrum/lnbase.py
  3. 2
      electrum/lnchan.py
  4. 6
      electrum/lnworker.py

28
electrum/gui/qt/channels_list.py

@ -40,22 +40,26 @@ class ChannelsList(MyTreeWidget):
] ]
def create_menu(self, position): def create_menu(self, position):
from .util import WaitingDialog
network = self.parent.network
lnworker = self.parent.wallet.lnworker
menu = QMenu() menu = QMenu()
channel_id = self.currentItem().data(0, QtCore.Qt.UserRole) channel_id = self.currentItem().data(0, QtCore.Qt.UserRole)
def on_success(txid):
self.main_window.show_error('Channel closed' + '\n' + txid)
def on_failure(exc_info):
type_, e, traceback = exc_info
self.main_window.show_error('Failed to close channel:\n{}'.format(repr(e)))
def close(): def close():
netw = self.parent.network def task():
coro = self.parent.wallet.lnworker.close_channel(channel_id) coro = lnworker.close_channel(channel_id)
try: return network.run_from_another_thread(coro)
_txid = netw.run_from_another_thread(coro) WaitingDialog(self, 'please wait..', task, on_success, on_failure)
except Exception as e:
self.main_window.show_error('Force-close failed:\n{}'.format(repr(e)))
def force_close(): def force_close():
netw = self.parent.network def task():
coro = self.parent.wallet.lnworker.force_close_channel(channel_id) coro = lnworker.force_close_channel(channel_id)
try: return network.run_from_another_thread(coro)
_txid = netw.run_from_another_thread(coro) WaitingDialog(self, 'please wait..', task, on_success, on_failure)
except Exception as e:
self.main_window.show_error('Force-close failed:\n{}'.format(repr(e)))
menu.addAction(_("Close channel"), close) menu.addAction(_("Close channel"), close)
menu.addAction(_("Force-close channel"), force_close) menu.addAction(_("Force-close channel"), force_close)
menu.exec_(self.viewport().mapToGlobal(position)) menu.exec_(self.viewport().mapToGlobal(position))

15
electrum/lnbase.py

@ -1129,8 +1129,9 @@ class Peer(PrintError):
self.shutdown_received[chan_id] = asyncio.Future() self.shutdown_received[chan_id] = asyncio.Future()
self.send_shutdown(chan) self.send_shutdown(chan)
payload = await self.shutdown_received[chan_id] payload = await self.shutdown_received[chan_id]
await self._shutdown(chan, payload) txid = await self._shutdown(chan, payload)
self.network.trigger_callback('ln_message', self.lnworker, 'Channel closed') self.print_error('Channel closed', txid)
return txid
@log_exceptions @log_exceptions
async def on_shutdown(self, payload): async def on_shutdown(self, payload):
@ -1140,12 +1141,11 @@ class Peer(PrintError):
chan_id = payload['channel_id'] chan_id = payload['channel_id']
if chan_id in self.shutdown_received: if chan_id in self.shutdown_received:
self.shutdown_received[chan_id].set_result(payload) self.shutdown_received[chan_id].set_result(payload)
self.print_error('Channel closed by us')
else: else:
chan = self.channels[chan_id] chan = self.channels[chan_id]
self.send_shutdown(chan) self.send_shutdown(chan)
await self._shutdown(chan, payload) txid = await self._shutdown(chan, payload)
self.print_error('Channel closed by remote peer') self.print_error('Channel closed by remote peer', txid)
def send_shutdown(self, chan): def send_shutdown(self, chan):
scriptpubkey = bfh(bitcoin.address_to_script(chan.sweep_address)) scriptpubkey = bfh(bitcoin.address_to_script(chan.sweep_address))
@ -1154,7 +1154,7 @@ class Peer(PrintError):
@log_exceptions @log_exceptions
async def _shutdown(self, chan, payload): async def _shutdown(self, chan, payload):
scriptpubkey = bfh(bitcoin.address_to_script(chan.sweep_address)) scriptpubkey = bfh(bitcoin.address_to_script(chan.sweep_address))
signature, fee = chan.make_closing_tx(scriptpubkey, payload['scriptpubkey']) signature, fee, txid = chan.make_closing_tx(scriptpubkey, payload['scriptpubkey'])
self.send_message('closing_signed', channel_id=chan.channel_id, fee_satoshis=fee, signature=signature) self.send_message('closing_signed', channel_id=chan.channel_id, fee_satoshis=fee, signature=signature)
while chan.get_state() != 'CLOSED': while chan.get_state() != 'CLOSED':
try: try:
@ -1163,5 +1163,6 @@ class Peer(PrintError):
pass pass
else: else:
fee = int.from_bytes(closing_signed['fee_satoshis'], 'big') fee = int.from_bytes(closing_signed['fee_satoshis'], 'big')
signature, _ = chan.make_closing_tx(scriptpubkey, payload['scriptpubkey'], fee_sat=fee) signature, _, txid = chan.make_closing_tx(scriptpubkey, payload['scriptpubkey'], fee_sat=fee)
self.send_message('closing_signed', channel_id=chan.channel_id, fee_satoshis=fee, signature=signature) self.send_message('closing_signed', channel_id=chan.channel_id, fee_satoshis=fee, signature=signature)
return txid

2
electrum/lnchan.py

@ -757,7 +757,7 @@ class Channel(PrintError):
der_sig = bfh(closing_tx.sign_txin(0, self.config[LOCAL].multisig_key.privkey)) der_sig = bfh(closing_tx.sign_txin(0, self.config[LOCAL].multisig_key.privkey))
sig = ecc.sig_string_from_der_sig(der_sig[:-1]) sig = ecc.sig_string_from_der_sig(der_sig[:-1])
return sig, fee_sat return sig, fee_sat, closing_tx.txid()
def maybe_create_sweeptx_for_their_ctx_to_remote(chan, ctx, their_pcp: bytes, def maybe_create_sweeptx_for_their_ctx_to_remote(chan, ctx, their_pcp: bytes,
sweep_address) -> Optional[EncumberedTransaction]: sweep_address) -> Optional[EncumberedTransaction]:

6
electrum/lnworker.py

@ -421,7 +421,7 @@ class LNWorker(PrintError):
async def close_channel(self, chan_id): async def close_channel(self, chan_id):
chan = self.channels[chan_id] chan = self.channels[chan_id]
peer = self.peers[chan.node_id] peer = self.peers[chan.node_id]
await peer.close_channel(chan_id) return await peer.close_channel(chan_id)
async def force_close_channel(self, chan_id): async def force_close_channel(self, chan_id):
chan = self.channels[chan_id] chan = self.channels[chan_id]
@ -437,9 +437,7 @@ class LNWorker(PrintError):
none_idx = tx._inputs[0]["signatures"].index(None) none_idx = tx._inputs[0]["signatures"].index(None)
tx.add_signature_to_txin(0, none_idx, bh2u(remote_sig)) tx.add_signature_to_txin(0, none_idx, bh2u(remote_sig))
assert tx.is_complete() assert tx.is_complete()
txid = await self.network.broadcast_transaction(tx) return await self.network.broadcast_transaction(tx)
self.network.trigger_callback('ln_message', self, 'Channel closed' + '\n' + txid)
return txid
def _get_next_peers_to_try(self) -> Sequence[LNPeerAddr]: def _get_next_peers_to_try(self) -> Sequence[LNPeerAddr]:
now = time.time() now = time.time()

Loading…
Cancel
Save