Skip to content

Commit 7a6b4ad

Browse files
committed
validate zeroconf channel once mined
1 parent 838189a commit 7a6b4ad

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

electrum/lnchannel.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class AbstractChannel(Logger, ABC):
191191
short_channel_id: Optional[ShortChannelID] = None
192192
funding_outpoint: Outpoint
193193
node_id: bytes # note that it might not be the full 33 bytes; for OCB it is only the prefix
194+
should_request_force_close: bool = False
194195
_state: ChannelState
195196

196197
def set_short_channel_id(self, short_id: ShortChannelID) -> None:
@@ -398,13 +399,20 @@ def update_funded_state(self, *, funding_txid: str, funding_height: TxMinedInfo)
398399
if funding_height.conf>0:
399400
self.set_short_channel_id(ShortChannelID.from_components(
400401
funding_height.height, funding_height.txpos, self.funding_outpoint.output_index))
401-
if self.is_zeroconf():
402-
# remove zeroconf flag as we are now confirmed, this is to prevent an electrum server causing
403-
# us to remove a channel later in update_unfunded_state by omitting its funding tx
404-
self.remove_zeroconf_flag()
405402
if self.get_state() == ChannelState.OPENING:
406403
if self.is_funding_tx_mined(funding_height):
407404
self.set_state(ChannelState.FUNDED)
405+
elif self.is_zeroconf() and funding_height.conf >= 3 and not self.should_request_force_close:
406+
if not self.is_funding_tx_mined(funding_height):
407+
# funding tx is invalid (invalid amount or address) we need to get rid of the channel again
408+
self.should_request_force_close = True
409+
if self.lnworker and self.node_id in self.lnworker.peers:
410+
# reconnect to trigger force close request
411+
self.lnworker.peers[self.node_id].close_and_cleanup()
412+
else:
413+
# remove zeroconf flag as we are now confirmed, this is to prevent an electrum server causing
414+
# us to remove a channel later in update_unfunded_state by omitting its funding tx
415+
self.remove_zeroconf_flag()
408416

409417
def update_closed_state(self, *, funding_txid: str, funding_height: TxMinedInfo,
410418
closing_txid: str, closing_height: TxMinedInfo, keep_watching: bool) -> None:
@@ -775,7 +783,6 @@ def __init__(self, state: 'StoredDict', *, name=None, lnworker=None, initial_fee
775783
self.revocation_store = RevocationStore(state["revocation_store"])
776784
self._can_send_ctx_updates = True # type: bool
777785
self._receive_fail_reasons = {} # type: Dict[int, (bytes, OnionRoutingFailure)]
778-
self.should_request_force_close = False
779786
self.unconfirmed_closing_txid = None # not a state, only for GUI
780787
self.sent_channel_ready = False # no need to persist this, because channel_ready is re-sent in channel_reestablish
781788
self.sent_announcement_signatures = False

0 commit comments

Comments
 (0)