lnmsg: pass filename as parameter instead of boolean
What changed, and why it matters
This commit is a small internal code cleanup in Electrum's Lightning message parser. It changes how the parser chooses which CSV specification file to load, switching from a true/false flag to a filename string. There is no security-relevant change: the same two files are still loaded in the same way, and no new attacker-controlled input is introduced.
No security action required. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors LNSerializer.init to accept a name: str = 'peer_wire' parameter instead of for_onion_wire: bool = False. It then constructs the CSV path as lnwire/{name}.csv. The two call sites are updated: the default instance continues to load peer_wire.csv, and OnionWireSerializer now passes name='onion_wire' to load onion_wire.csv. The parsing logic for onion message types remains identical. No input validation, file access, or serialization behavior changes in a security-relevant way.
Changed components
electrum/lnmsg.pyInspect captured patch +4 / −7
diff --git a/electrum/lnmsg.py b/electrum/lnmsg.py
index eeb83af..e8ad41d 100644
--- a/electrum/lnmsg.py
+++ b/electrum/lnmsg.py
@@ -323,7 +323,7 @@ def _parse_msgtype_intvalue_for_onion_wire(value: str) -> int:
class LNSerializer:
- def __init__(self, *, for_onion_wire: bool = False):
+ def __init__(self, *, name: str = 'peer_wire'):
# TODO msg_type could be 'int' everywhere...
self.msg_scheme_from_type = {} # type: Dict[bytes, List[Sequence[str]]]
self.msg_type_from_name = {} # type: Dict[str, bytes]
@@ -334,10 +334,7 @@ class LNSerializer:
self.subtypes = {} # type: Dict[str, Dict[str, Sequence[str]]]
- if for_onion_wire:
- path = os.path.join(os.path.dirname(__file__), "lnwire", "onion_wire.csv")
- else:
- path = os.path.join(os.path.dirname(__file__), "lnwire", "peer_wire.csv")
+ path = os.path.join(os.path.dirname(__file__), "lnwire", name + ".csv")
with open(path, newline='') as f:
csvreader = csv.reader(f)
for row in csvreader:
@@ -345,7 +342,7 @@ class LNSerializer:
if row[0] == "msgtype":
# msgtype,<msgname>,<value>[,<option>]
msg_type_name = row[1]
- if for_onion_wire:
+ if name == 'onion_wire':
msg_type_int = _parse_msgtype_intvalue_for_onion_wire(str(row[2]))
else:
msg_type_int = int(row[2])
@@ -668,4 +665,4 @@ encode_msg = _inst.encode_msg
decode_msg = _inst.decode_msg
-OnionWireSerializer = LNSerializer(for_onion_wire=True)
+OnionWireSerializer = LNSerializer(name='onion_wire')
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.