lnonion: rm is_onion_message param from process_onion_packet
What changed, and why it matters
This is a small internal code cleanup in Electrum's Lightning onion message handling. It removes a redundant function parameter and lets the code figure out the same thing from an existing parameter. There is no security fix or behavior change visible in the commit.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors process_onion_packet() in electrum/lnonion.py to remove the is_onion_message keyword argument. The same boolean is now derived inside the function as is_onion_message = (tlv_stream_name == ‘onionmsg_tlv’). Callers in onion_message.py and tests/test_onion_message.py are updated to stop passing the removed argument. The diff shows no logic changes beyond this parameter elimination.
Changed components
electrum/lnonion.pyelectrum/onion_message.pytests/test_onion_message.pyInspect captured patch +3 / −3
diff --git a/electrum/lnonion.py b/electrum/lnonion.py
index a334fee..984e651 100644
--- a/electrum/lnonion.py
+++ b/electrum/lnonion.py
@@ -434,13 +434,13 @@ def process_onion_packet(
*,
associated_data: bytes = b'',
is_trampoline=False,
- is_onion_message=False,
tlv_stream_name='payload') -> ProcessedOnionPacket:
# TODO: check Onion features ( PERM|NODE|3 (required_node_feature_missing )
if onion_packet.version != 0:
raise UnsupportedOnionPacketVersion()
if not ecc.ECPubkey.is_pubkey_bytes(onion_packet.public_key):
raise InvalidOnionPubkey()
+ is_onion_message = tlv_stream_name == 'onionmsg_tlv'
shared_secret = get_ecdh(our_onion_private_key, onion_packet.public_key)
# check message integrity
mu_key = get_bolt04_onion_key(b'mu', shared_secret)
diff --git a/electrum/onion_message.py b/electrum/onion_message.py
index a98775e..c94db86 100644
--- a/electrum/onion_message.py
+++ b/electrum/onion_message.py
@@ -835,7 +835,7 @@ class OnionMessageManager(Logger):
def process_onion_message_packet(self, blinding: bytes, onion_packet: OnionPacket) -> None:
our_privkey = blinding_privkey(self.lnwallet.node_keypair.privkey, blinding)
- processed_onion_packet = process_onion_packet(onion_packet, our_privkey, is_onion_message=True, tlv_stream_name='onionmsg_tlv')
+ processed_onion_packet = process_onion_packet(onion_packet, our_privkey, tlv_stream_name='onionmsg_tlv')
payload = processed_onion_packet.hop_data.payload
self.logger.debug(f'onion peeled: {processed_onion_packet!r}')
diff --git a/tests/test_onion_message.py b/tests/test_onion_message.py
index 63e5803..d24fd90 100644
--- a/tests/test_onion_message.py
+++ b/tests/test_onion_message.py
@@ -173,7 +173,7 @@ class TestOnionMessage(ElectrumTestCase):
our_privkey_int = our_privkey_int * b_hmac_int % ecc.CURVE_ORDER
our_privkey = our_privkey_int.to_bytes(32, byteorder="big")
- p = process_onion_packet(o, our_privkey, is_onion_message=True, tlv_stream_name='onionmsg_tlv')
+ p = process_onion_packet(o, our_privkey, tlv_stream_name='onionmsg_tlv')
self.assertEqual(p.hop_data.blind_fields, {})
self.assertEqual(p.hop_data.hmac, bfh('a5296325ba478ba1e1a9d1f30a2d5052b2e2889bbd64f72c72bc71d8817288a2'))
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.