onion_message: move round-robin logic in Request method
What changed, and why it matters
This commit is a small internal code cleanup in Electrum's Lightning onion-message handling. It moves the 'round-robin' destination selection logic into its own helper method and ensures a single destination is treated as a list earlier. There is no visible security fix or behavior change beyond slightly cleaner code organization.
No security action required. Treat as routine refactoring; review in normal code-review context if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors OnionMessageManager.Request: it adds a constructor check that wraps a single bytes destination into a one-element list, and introduces get_next_destination() to encapsulate round-robin selection. _send_pending_message now calls that helper instead of inlining the logic. The change also switches from self.pending.get(key) to self.pending[key], which would raise KeyError on a missing key rather than returning None. This is a stricter, more explicit access pattern but does not alter the intended control flow when the key exists.
Changed components
electrum/onion_message.pyOnionMessageManager.RequestOnionMessageManager._send_pending_messageInspect captured patch +13 / −8
diff --git a/electrum/onion_message.py b/electrum/onion_message.py
index 9f3c415..a98775e 100644
--- a/electrum/onion_message.py
+++ b/electrum/onion_message.py
@@ -515,6 +515,17 @@ class OnionMessageManager(Logger):
self.node_id_or_blinded_paths = node_id_or_blinded_paths
self.current_index: int = 0
+ # ensure node_id_or_blinded_paths is list
+ if isinstance(self.node_id_or_blinded_paths, bytes):
+ self.node_id_or_blinded_paths = [self.node_id_or_blinded_paths]
+
+ def get_next_destination(self) -> bytes:
+ """get next path (round-robin)"""
+ dests = self.node_id_or_blinded_paths
+ dest = dests[self.current_index]
+ self.current_index = (self.current_index + 1) % len(dests)
+ return dest
+
def __init__(self, lnwallet: 'LNWallet'):
Logger.__init__(self)
self.network = None # type: Optional['Network']
@@ -663,15 +674,9 @@ class OnionMessageManager(Logger):
def _send_pending_message(self, key: bytes) -> None:
"""adds reply_path to payload"""
- req = self.pending.get(key)
+ req = self.pending[key]
payload = req.payload
-
- # get next path (round robin)
- dests = req.node_id_or_blinded_paths
- if isinstance(req.node_id_or_blinded_paths, bytes):
- dests = [req.node_id_or_blinded_paths]
- dest = dests[req.current_index]
- req.current_index = (req.current_index + 1) % len(dests)
+ dest = req.get_next_destination()
self.logger.debug(f'send_pending_message {key=} {payload=} {dest=}')
Why this scored 12/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.