1
0

lnchannel: add new states: WE_ARE_TOXIC, REQUESTED_FCLOSE

The `WE_ARE_TOXIC` state is added as a sanity check to ensure that if
the remote has proven that we have lost state we do not accidentally
do a local force-close. E.g. if we receive an "error" message for the
channel, we might normally do an automatic force-close. Manually
force-closing in such a state is not offered anymore by the GUI.

The `REQUESTED_FCLOSE` state is added as it is quite likely that
we receive an error message from the remote after requesting a fclose,
e.g. during a later chan-reestablish. In such a scenario, we should
not do an auto-local-fclose, however the manual option of a local-fclose
should still be offered.
This commit is contained in:
SomberNight
2022-06-07 22:53:05 +02:00
parent ee85f98fd6
commit f12e87be93
4 changed files with 75 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ from kivy.uix.popup import Popup
from electrum.util import bh2u
from electrum.logging import Logger
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id
from electrum.lnchannel import AbstractChannel, Channel, ChannelState
from electrum.lnchannel import AbstractChannel, Channel, ChannelState, ChanCloseOption
from electrum.gui.kivy.i18n import _
from electrum.transaction import PartialTxOutput, Transaction
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, format_fee_satoshis, quantize_feerate
@@ -495,8 +495,8 @@ class ChannelDetailsPopup(Popup, Logger):
action_dropdown = self.ids.action_dropdown # type: ActionDropdown
options = [
ActionButtonOption(text=_('Backup'), func=lambda btn: self.export_backup()),
ActionButtonOption(text=_('Close channel'), func=lambda btn: self.close(), enabled=not self.is_closed),
ActionButtonOption(text=_('Force-close'), func=lambda btn: self.force_close(), enabled=not self.is_closed),
ActionButtonOption(text=_('Close channel'), func=lambda btn: self.close(), enabled=ChanCloseOption.COOP_CLOSE in self.chan.get_close_options()),
ActionButtonOption(text=_('Force-close'), func=lambda btn: self.force_close(), enabled=ChanCloseOption.LOCAL_FCLOSE in self.chan.get_close_options()),
ActionButtonOption(text=_('Delete'), func=lambda btn: self.remove_channel(), enabled=self.can_be_deleted),
]
if not self.chan.is_closed():
@@ -557,7 +557,8 @@ class ChannelDetailsPopup(Popup, Logger):
self.app.qr_dialog(_("Channel Backup " + self.chan.short_id_for_GUI()), text, help_text=help_text)
def force_close(self):
if self.chan.is_closed():
if ChanCloseOption.LOCAL_FCLOSE not in self.chan.get_close_options():
# note: likely channel is already closed, or could be unsafe to do local force-close (e.g. we are toxic)
self.app.show_error(_('Channel already closed'))
return
to_self_delay = self.chan.config[REMOTE].to_self_delay