Skip to content

Commit 718a513

Browse files
authored
Merge pull request #9588 from f321x/jit-accept-non-recoverable
Refector on_channel_open to accept incoming channels if the source is a trusted zeroconf node
2 parents ffc84ab + cb56f08 commit 718a513

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

electrum/lnpeer.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -1219,27 +1219,13 @@ async def on_open_channel(self, payload):
12191219
12201220
Channel configurations are initialized in this method.
12211221
"""
1222-
if self.lnworker.has_recoverable_channels():
1223-
# FIXME: we might want to keep the connection open
1224-
raise Exception('not accepting channels')
1222+
12251223
# <- open_channel
12261224
if payload['chain_hash'] != constants.net.rev_genesis_bytes():
12271225
raise Exception('wrong chain_hash')
1228-
funding_sat = payload['funding_satoshis']
1229-
push_msat = payload['push_msat']
1230-
feerate = payload['feerate_per_kw'] # note: we are not validating this
1231-
temp_chan_id = payload['temporary_channel_id']
1232-
# store the temp id now, so that it is recognized for e.g. 'error' messages
1233-
# TODO: this is never cleaned up; the dict grows unbounded until disconnect
1234-
self.temp_id_to_id[temp_chan_id] = None
12351226

12361227
open_channel_tlvs = payload.get('open_channel_tlvs')
12371228
channel_type = open_channel_tlvs.get('channel_type') if open_channel_tlvs else None
1238-
1239-
channel_opening_fee = open_channel_tlvs.get('channel_opening_fee') if open_channel_tlvs else None
1240-
if channel_opening_fee:
1241-
# todo check that the fee is reasonable
1242-
pass
12431229
# The receiving node MAY fail the channel if:
12441230
# option_channel_type was negotiated but the message doesn't include a channel_type
12451231
if self.is_channel_type() and channel_type is None:
@@ -1251,6 +1237,29 @@ async def on_open_channel(self, payload):
12511237
if not channel_type.complies_with_features(self.features):
12521238
raise Exception("sender has sent a channel type we don't support")
12531239

1240+
if self.is_channel_type():
1241+
is_zeroconf = bool(channel_type & ChannelType.OPTION_ZEROCONF)
1242+
if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()):
1243+
raise Exception(f"not accepting zeroconf from node {self.pubkey}")
1244+
else:
1245+
is_zeroconf = False
1246+
1247+
if self.lnworker.has_recoverable_channels() and not is_zeroconf:
1248+
# FIXME: we might want to keep the connection open
1249+
raise Exception('not accepting channels')
1250+
1251+
funding_sat = payload['funding_satoshis']
1252+
push_msat = payload['push_msat']
1253+
feerate = payload['feerate_per_kw'] # note: we are not validating this
1254+
temp_chan_id = payload['temporary_channel_id']
1255+
# store the temp id now, so that it is recognized for e.g. 'error' messages
1256+
# TODO: this is never cleaned up; the dict grows unbounded until disconnect
1257+
self.temp_id_to_id[temp_chan_id] = None
1258+
channel_opening_fee = open_channel_tlvs.get('channel_opening_fee') if open_channel_tlvs else None
1259+
if channel_opening_fee:
1260+
# todo check that the fee is reasonable
1261+
pass
1262+
12541263
if self.use_anchors():
12551264
multisig_funding_keypair = lnutil.derive_multisig_funding_key_if_they_opened(
12561265
funding_root_secret=self.lnworker.funding_root_keypair.privkey,
@@ -1311,9 +1320,6 @@ async def on_open_channel(self, payload):
13111320
per_commitment_point_first = secret_to_pubkey(
13121321
int.from_bytes(per_commitment_secret_first, 'big'))
13131322

1314-
is_zeroconf = channel_type & channel_type.OPTION_ZEROCONF
1315-
if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()):
1316-
raise Exception(f"not accepting zeroconf from node {self.pubkey}")
13171323
min_depth = 0 if is_zeroconf else 3
13181324

13191325
accept_channel_tlvs = {

0 commit comments

Comments
 (0)