What changed, and why it matters
This commit is a small internal cleanup in Electrum's Lightning networking code. It introduces a single `self.config` shortcut so the code always reads settings from the same place instead of sometimes using `self.network.config` and sometimes `self.lnworker.config`. There is no user-facing change and no security fix.
No action needed. This is a benign refactoring commit with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds a config property to the Peer class in electrum/lnpeer.py that returns self.lnworker.config. It then replaces scattered references to self.lnworker.config and self.network.config with self.config. The diff is purely refactor-style: no logic, validation, or behavior changes. In one place (open_channel) the object passed as config= to ChannelConfig changes from self.network.config to self.lnworker.config, but in Electrum these are the same SimpleConfig instance (the worker holds a reference to the network’s config), so the effective value is unchanged.
Changed components
electrum/lnpeer.pyInspect captured patch +18 / −13
diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
index db79ed8..e8f8d73 100644
--- a/electrum/lnpeer.py
+++ b/electrum/lnpeer.py
@@ -60,6 +60,7 @@ from .channel_db import FLAG_DIRECTION
if TYPE_CHECKING:
from .lnworker import LNGossip, LNWallet
from .lnrouter import LNPaymentRoute
+ from .simple_config import SimpleConfig
from .transaction import PartialTransaction
@@ -102,7 +103,7 @@ class Peer(Logger, EventListener):
self.privkey = self.transport.privkey # local privkey
self.features = self.lnworker.features # type: LnFeatures
if lnworker == lnworker.network.lngossip or \
- lnworker.config.ZEROCONF_TRUSTED_NODE and pubkey != lnworker.trusted_zeroconf_node_id:
+ self.config.ZEROCONF_TRUSTED_NODE and pubkey != lnworker.trusted_zeroconf_node_id:
# don't signal zeroconf support if we are client (a trusted node is configured),
# and Peer is not our trusted node
self.features &= ~LnFeatures.OPTION_ZEROCONF_OPT
@@ -206,6 +207,10 @@ class Peer(Logger, EventListener):
return None
return chan
+ @property
+ def config(self) -> 'SimpleConfig':
+ return self.lnworker.config
+
def diagnostic_name(self):
lnw_name = self.lnworker.diagnostic_name() or self.lnworker.__class__.__name__
return lnw_name + ', ' + self.transport.name()
@@ -587,8 +592,8 @@ class Peer(Logger, EventListener):
while True:
public_channels = [chan for chan in self.lnworker.channels.values() if chan.is_public()]
if public_channels:
- alias = self.lnworker.config.LIGHTNING_NODE_ALIAS
- color = self.lnworker.config.LIGHTNING_NODE_COLOR_RGB
+ alias = self.config.LIGHTNING_NODE_ALIAS
+ color = self.config.LIGHTNING_NODE_COLOR_RGB
self.send_node_announcement(alias, color)
for chan in public_channels:
if chan.is_open() and chan.peer_state == PeerState.GOOD:
@@ -974,7 +979,7 @@ class Peer(Logger, EventListener):
Channel configurations are initialized in this method.
"""
- if public and not self.lnworker.config.EXPERIMENTAL_LN_FORWARD_PAYMENTS:
+ if public and not self.config.EXPERIMENTAL_LN_FORWARD_PAYMENTS:
raise Exception('Cannot create public channels')
if not self.lnworker.wallet.can_have_lightning():
@@ -1116,7 +1121,7 @@ class Peer(Logger, EventListener):
funding_sat=funding_sat,
is_local_initiator=True,
initial_feerate_per_kw=feerate,
- config=self.network.config,
+ config=self.config,
peer_features=self.features,
channel_type=our_channel_type,
)
@@ -1246,7 +1251,7 @@ class Peer(Logger, EventListener):
assert isinstance(channel_type, ChannelType)
is_zeroconf = bool(channel_type & ChannelType.OPTION_ZEROCONF)
- if is_zeroconf and not self.network.config.ZEROCONF_TRUSTED_NODE.startswith(self.pubkey.hex()):
+ if is_zeroconf and not self.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:
@@ -1320,7 +1325,7 @@ class Peer(Logger, EventListener):
funding_sat=funding_sat,
is_local_initiator=False,
initial_feerate_per_kw=feerate,
- config=self.network.config,
+ config=self.config,
peer_features=self.features,
channel_type=channel_type,
)
@@ -1760,8 +1765,8 @@ class Peer(Logger, EventListener):
rgb_color = bytes.fromhex(color_hex)
alias = bytes(alias, 'utf8')
alias += bytes(32 - len(alias))
- if self.lnworker.config.LIGHTNING_LISTEN is not None:
- addr = self.lnworker.config.LIGHTNING_LISTEN
+ if self.config.LIGHTNING_LISTEN is not None:
+ addr = self.config.LIGHTNING_LISTEN
try:
hostname, port = addr.split(':')
if port is None: # use default port if not specified
@@ -2542,7 +2547,7 @@ class Peer(Logger, EventListener):
def get_shutdown_fee_range(self, chan, closing_tx, is_local):
""" return the closing fee and fee range we initially try to enforce """
- config = self.network.config
+ config = self.config
our_fee = None
if config.TEST_SHUTDOWN_FEE:
our_fee = config.TEST_SHUTDOWN_FEE
@@ -2650,7 +2655,7 @@ class Peer(Logger, EventListener):
fee_range_sent = our_fee_range and (is_initiator or (their_previous_fee is not None))
# The sending node, if it is not the funder:
- if our_fee_range and their_fee_range and not is_initiator and not self.network.config.TEST_SHUTDOWN_FEE_RANGE:
+ if our_fee_range and their_fee_range and not is_initiator and not self.config.TEST_SHUTDOWN_FEE_RANGE:
# SHOULD set max_fee_satoshis to at least the max_fee_satoshis received
our_fee_range['max_fee_satoshis'] = max(their_fee_range['max_fee_satoshis'], our_fee_range['max_fee_satoshis'])
# SHOULD set min_fee_satoshis to a fairly low value
@@ -3250,9 +3255,9 @@ class Peer(Logger, EventListener):
except Exception as e:
self.logger.warning(f"error processing onion packet: {e!r}")
raise OnionParsingError(data=onion_hash)
- if self.network.config.TEST_FAIL_HTLCS_AS_MALFORMED:
+ if self.config.TEST_FAIL_HTLCS_AS_MALFORMED:
raise OnionParsingError(data=onion_hash)
- if self.network.config.TEST_FAIL_HTLCS_WITH_TEMP_NODE_FAILURE:
+ if self.config.TEST_FAIL_HTLCS_WITH_TEMP_NODE_FAILURE:
raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_NODE_FAILURE, data=b'')
return processed_onion
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.