add option to remove channel after it has been closed
This commit is contained in:
@@ -23,6 +23,8 @@ class ChannelsList(MyTreeView):
|
|||||||
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)
|
||||||
|
self.network = self.parent.network
|
||||||
|
self.lnworker = self.parent.wallet.lnworker
|
||||||
|
|
||||||
def format_fields(self, chan):
|
def format_fields(self, chan):
|
||||||
labels = {}
|
labels = {}
|
||||||
@@ -42,36 +44,46 @@ class ChannelsList(MyTreeView):
|
|||||||
chan.get_state()
|
chan.get_state()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def on_success(txid):
|
||||||
|
self.main_window.show_error('Channel closed' + '\n' + txid)
|
||||||
|
|
||||||
|
def on_failure(exc_info):
|
||||||
|
type_, e, tb = exc_info
|
||||||
|
traceback.print_tb(tb)
|
||||||
|
self.main_window.show_error('Failed to close channel:\n{}'.format(repr(e)))
|
||||||
|
|
||||||
|
def close(self, channel_id):
|
||||||
|
def task():
|
||||||
|
coro = self.lnworker.close_channel(channel_id)
|
||||||
|
return self.network.run_from_another_thread(coro)
|
||||||
|
WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)
|
||||||
|
|
||||||
|
def force_close(self, channel_id):
|
||||||
|
def task():
|
||||||
|
coro = self.lnworker.force_close_channel(channel_id)
|
||||||
|
return self.network.run_from_another_thread(coro)
|
||||||
|
if self.parent.question('Force-close channel?\nReclaimed funds will not be immediately available.'):
|
||||||
|
WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)
|
||||||
|
|
||||||
|
def remove_channel(self, channel_id):
|
||||||
|
if self.main_window.question(_('Are you sure you want to delete this channel? This will purge associated transactions from your wallet history.')):
|
||||||
|
self.lnworker.remove_channel(channel_id)
|
||||||
|
|
||||||
def create_menu(self, position):
|
def create_menu(self, position):
|
||||||
from .util import WaitingDialog
|
from .util import WaitingDialog
|
||||||
network = self.parent.network
|
|
||||||
lnworker = self.parent.wallet.lnworker
|
|
||||||
menu = QMenu()
|
menu = QMenu()
|
||||||
idx = self.selectionModel().currentIndex()
|
idx = self.selectionModel().currentIndex()
|
||||||
item = self.model().itemFromIndex(idx)
|
item = self.model().itemFromIndex(idx)
|
||||||
if not item:
|
if not item:
|
||||||
return
|
return
|
||||||
channel_id = idx.sibling(idx.row(), 0).data(QtCore.Qt.UserRole)
|
channel_id = idx.sibling(idx.row(), 0).data(QtCore.Qt.UserRole)
|
||||||
def on_success(txid):
|
chan = self.lnworker.channels[channel_id]
|
||||||
self.main_window.show_error('Channel closed' + '\n' + txid)
|
|
||||||
def on_failure(exc_info):
|
|
||||||
type_, e, tb = exc_info
|
|
||||||
traceback.print_tb(tb)
|
|
||||||
self.main_window.show_error('Failed to close channel:\n{}'.format(repr(e)))
|
|
||||||
def close():
|
|
||||||
def task():
|
|
||||||
coro = lnworker.close_channel(channel_id)
|
|
||||||
return network.run_from_another_thread(coro)
|
|
||||||
WaitingDialog(self, 'please wait..', task, on_success, on_failure)
|
|
||||||
def force_close():
|
|
||||||
def task():
|
|
||||||
coro = lnworker.force_close_channel(channel_id)
|
|
||||||
return network.run_from_another_thread(coro)
|
|
||||||
if self.parent.question('Force-close channel?\nClaiming funds will not be immediately available.'):
|
|
||||||
WaitingDialog(self, 'please wait..', task, on_success, on_failure)
|
|
||||||
menu.addAction(_("Details..."), lambda: self.details(channel_id))
|
menu.addAction(_("Details..."), lambda: self.details(channel_id))
|
||||||
menu.addAction(_("Close channel"), close)
|
if not chan.is_closed():
|
||||||
menu.addAction(_("Force-close channel"), force_close)
|
menu.addAction(_("Close channel"), lambda: self.close_channel(channel_id))
|
||||||
|
menu.addAction(_("Force-close channel"), lambda: self.force_close(channel_id))
|
||||||
|
else:
|
||||||
|
menu.addAction(_("Remove"), lambda: self.remove_channel(channel_id))
|
||||||
menu.exec_(self.viewport().mapToGlobal(position))
|
menu.exec_(self.viewport().mapToGlobal(position))
|
||||||
|
|
||||||
def details(self, channel_id):
|
def details(self, channel_id):
|
||||||
|
|||||||
@@ -443,16 +443,20 @@ class LNWallet(LNWorker):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
return {x: y for (x, y) in self.channels.items() if y.node_id == node_id}
|
return {x: y for (x, y) in self.channels.items() if y.node_id == node_id}
|
||||||
|
|
||||||
def save_channel(self, openchannel):
|
def save_channel(self, chan):
|
||||||
assert type(openchannel) is Channel
|
assert type(chan) is Channel
|
||||||
if openchannel.config[REMOTE].next_per_commitment_point == openchannel.config[REMOTE].current_per_commitment_point:
|
if chan.config[REMOTE].next_per_commitment_point == chan.config[REMOTE].current_per_commitment_point:
|
||||||
raise Exception("Tried to save channel with next_point == current_point, this should not happen")
|
raise Exception("Tried to save channel with next_point == current_point, this should not happen")
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.channels[openchannel.channel_id] = openchannel
|
self.channels[chan.channel_id] = chan
|
||||||
|
self.save_channels()
|
||||||
|
self.network.trigger_callback('channel', chan)
|
||||||
|
|
||||||
|
def save_channels(self):
|
||||||
|
with self.lock:
|
||||||
dumped = [x.serialize() for x in self.channels.values()]
|
dumped = [x.serialize() for x in self.channels.values()]
|
||||||
self.storage.put("channels", dumped)
|
self.storage.put("channels", dumped)
|
||||||
self.storage.write()
|
self.storage.write()
|
||||||
self.network.trigger_callback('channel', openchannel)
|
|
||||||
|
|
||||||
def save_short_chan_id(self, chan):
|
def save_short_chan_id(self, chan):
|
||||||
"""
|
"""
|
||||||
@@ -875,6 +879,15 @@ class LNWallet(LNWorker):
|
|||||||
await self.network.broadcast_transaction(tx)
|
await self.network.broadcast_transaction(tx)
|
||||||
return tx.txid()
|
return tx.txid()
|
||||||
|
|
||||||
|
def remove_channel(self, chan_id):
|
||||||
|
# TODO: assert that closing tx is deep-mined and htlcs are swept
|
||||||
|
chan = self.channels[chan_id]
|
||||||
|
assert chan.is_closed()
|
||||||
|
self.channels.pop(chan_id)
|
||||||
|
self.save_channel(chan)
|
||||||
|
self.network.trigger_callback('channels')
|
||||||
|
self.network.trigger_callback('wallet_updated')
|
||||||
|
|
||||||
async def reestablish_peers_and_channels(self):
|
async def reestablish_peers_and_channels(self):
|
||||||
async def reestablish_peer_for_given_channel():
|
async def reestablish_peer_for_given_channel():
|
||||||
# try last good address first
|
# try last good address first
|
||||||
|
|||||||
Reference in New Issue
Block a user