From 6a0e537b9c0e78d0f2cc23515995eb3a850360bd Mon Sep 17 00:00:00 2001 From: f321x Date: Fri, 28 Feb 2025 12:56:33 +0100 Subject: [PATCH 1/3] accept incoming channels if its from trusted zeroconf node --- electrum/lnpeer.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index afe96b5cb..3254cb6b9 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1023,27 +1023,13 @@ class Peer(Logger, EventListener): Channel configurations are initialized in this method. """ - if self.lnworker.has_recoverable_channels(): - # FIXME: we might want to keep the connection open - raise Exception('not accepting channels') + # <- open_channel if payload['chain_hash'] != constants.net.rev_genesis_bytes(): raise Exception('wrong chain_hash') - funding_sat = payload['funding_satoshis'] - push_msat = payload['push_msat'] - feerate = payload['feerate_per_kw'] # note: we are not validating this - temp_chan_id = payload['temporary_channel_id'] - # store the temp id now, so that it is recognized for e.g. 'error' messages - # TODO: this is never cleaned up; the dict grows unbounded until disconnect - self.temp_id_to_id[temp_chan_id] = None open_channel_tlvs = payload.get('open_channel_tlvs') channel_type = open_channel_tlvs.get('channel_type') if open_channel_tlvs else None - - channel_opening_fee = open_channel_tlvs.get('channel_opening_fee') if open_channel_tlvs else None - if channel_opening_fee: - # todo check that the fee is reasonable - pass # The receiving node MAY fail the channel if: # option_channel_type was negotiated but the message doesn't include a channel_type if self.is_channel_type() and channel_type is None: @@ -1055,6 +1041,26 @@ class Peer(Logger, EventListener): if not channel_type.complies_with_features(self.features): raise Exception("sender has sent a channel type we don't support") + is_zeroconf = channel_type & channel_type.OPTION_ZEROCONF + if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()): + raise Exception(f"not accepting zeroconf from node {self.pubkey}") + + if self.lnworker.has_recoverable_channels() and not is_zeroconf: + # FIXME: we might want to keep the connection open + raise Exception('not accepting channels') + + funding_sat = payload['funding_satoshis'] + push_msat = payload['push_msat'] + feerate = payload['feerate_per_kw'] # note: we are not validating this + temp_chan_id = payload['temporary_channel_id'] + # store the temp id now, so that it is recognized for e.g. 'error' messages + # TODO: this is never cleaned up; the dict grows unbounded until disconnect + self.temp_id_to_id[temp_chan_id] = None + channel_opening_fee = open_channel_tlvs.get('channel_opening_fee') if open_channel_tlvs else None + if channel_opening_fee: + # todo check that the fee is reasonable + pass + if self.use_anchors(): multisig_funding_keypair = lnutil.derive_multisig_funding_key_if_they_opened( funding_root_secret=self.lnworker.funding_root_keypair.privkey, @@ -1115,9 +1121,6 @@ class Peer(Logger, EventListener): per_commitment_point_first = secret_to_pubkey( int.from_bytes(per_commitment_secret_first, 'big')) - is_zeroconf = channel_type & channel_type.OPTION_ZEROCONF - if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()): - raise Exception(f"not accepting zeroconf from node {self.pubkey}") min_depth = 0 if is_zeroconf else 3 accept_channel_tlvs = { From bc90f517d110efd8babf38f7ef72ce6c9beda112 Mon Sep 17 00:00:00 2001 From: f321x Date: Tue, 4 Mar 2025 14:28:17 +0100 Subject: [PATCH 2/3] check if channel type before checking if zeroconf option --- electrum/lnpeer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 3254cb6b9..95dc1c786 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1041,9 +1041,12 @@ class Peer(Logger, EventListener): if not channel_type.complies_with_features(self.features): raise Exception("sender has sent a channel type we don't support") - is_zeroconf = channel_type & channel_type.OPTION_ZEROCONF - if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()): - raise Exception(f"not accepting zeroconf from node {self.pubkey}") + if self.is_channel_type(): + is_zeroconf = channel_type & channel_type.OPTION_ZEROCONF + if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()): + raise Exception(f"not accepting zeroconf from node {self.pubkey}") + else: + is_zeroconf = False if self.lnworker.has_recoverable_channels() and not is_zeroconf: # FIXME: we might want to keep the connection open From cb56f0873dc65dccfd3111d1ca675bc8991a31bb Mon Sep 17 00:00:00 2001 From: f321x Date: Tue, 4 Mar 2025 17:03:55 +0100 Subject: [PATCH 3/3] improve ChannelType option check --- electrum/lnpeer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 95dc1c786..1a3179211 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1042,7 +1042,7 @@ class Peer(Logger, EventListener): raise Exception("sender has sent a channel type we don't support") if self.is_channel_type(): - is_zeroconf = channel_type & channel_type.OPTION_ZEROCONF + is_zeroconf = bool(channel_type & ChannelType.OPTION_ZEROCONF) if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()): raise Exception(f"not accepting zeroconf from node {self.pubkey}") else: