lnworker: move RecvMPPResolution and status to lnutil
What changed, and why it matters
This commit is a simple code cleanup: it moves two Lightning Network data structures (RecvMPPResolution and ReceivedMPPStatus) from one file to another shared utility file so both lnpeer.py and lnworker.py can use them without circular imports. There is no functional change and no security relevance.
No action required. This is a benign refactor with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch relocates RecvMPPResolution (an IntEnum for MPP receive states) and ReceivedMPPStatus (a NamedTuple with serialization logic) from electrum/lnworker.py to electrum/lnutil.py. It updates imports in lnpeer.py and lnworker.py accordingly and removes a local import inside a method. The code behavior is identical; this is a pure refactor.
Changed components
electrum/lnutil.pyelectrum/lnworker.pyelectrum/lnpeer.pyInspect captured patch +27 / −25
diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
index 1dcccfc..a4bddd1 100644
--- a/electrum/lnpeer.py
+++ b/electrum/lnpeer.py
@@ -48,7 +48,7 @@ from .lnutil import (Outpoint, LocalConfig, RECEIVED, UpdateAddHtlc, ChannelConf
IncompatibleLightningFeatures, ChannelType, LNProtocolWarning, validate_features,
IncompatibleOrInsaneFeatures, FeeBudgetExceeded,
GossipForwardingMessage, GossipTimestampFilter, channel_id_from_funding_tx,
- PaymentFeeBudget, serialize_htlc_key, Keypair)
+ PaymentFeeBudget, serialize_htlc_key, Keypair, RecvMPPResolution)
from .lntransport import LNTransport, LNTransportBase, LightningPeerConnectionClosed, HandshakeFailed
from .lnmsg import encode_msg, decode_msg, UnknownOptionalMsgType, FailedToParseMsg
from .interface import GracefulDisconnect
@@ -2465,7 +2465,6 @@ class Peer(Logger, EventListener):
exc_incorrect_or_unknown_pd: OnionRoutingFailure,
log_fail_reason: Callable[[str], None],
) -> bool:
- from .lnworker import RecvMPPResolution
mpp_resolution = self.lnworker.check_mpp_status(
payment_secret=payment_secret,
short_channel_id=short_channel_id,
diff --git a/electrum/lnutil.py b/electrum/lnutil.py
index 80e74de..c750c15 100644
--- a/electrum/lnutil.py
+++ b/electrum/lnutil.py
@@ -1930,6 +1930,30 @@ class UpdateAddHtlc:
self._validate()
+# Note: these states are persisted in the wallet file.
+# Do not modify them without performing a wallet db upgrade
+class RecvMPPResolution(IntEnum):
+ WAITING = 0
+ EXPIRED = 1
+ ACCEPTED = 2
+ FAILED = 3
+
+
+class ReceivedMPPStatus(NamedTuple):
+ resolution: RecvMPPResolution
+ expected_msat: int
+ htlc_set: Set[Tuple[ShortChannelID, UpdateAddHtlc]]
+
+ @staticmethod
+ @stored_in('received_mpp_htlcs', tuple)
+ def from_tuple(resolution, expected_msat, htlc_list) -> 'ReceivedMPPStatus':
+ htlc_set = set([(ShortChannelID(bytes.fromhex(scid)), UpdateAddHtlc.from_tuple(*x)) for (scid, x) in htlc_list])
+ return ReceivedMPPStatus(
+ resolution=RecvMPPResolution(resolution),
+ expected_msat=expected_msat,
+ htlc_set=htlc_set)
+
+
class OnionFailureCodeMetaFlag(IntFlag):
BADONION = 0x8000
PERM = 0x4000
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index 63c6132..fe217cb 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -68,7 +68,8 @@ from .lnutil import (
LnKeyFamily, LOCAL, REMOTE, MIN_FINAL_CLTV_DELTA_FOR_INVOICE, SENT, RECEIVED, HTLCOwner, UpdateAddHtlc, LnFeatures,
ShortChannelID, HtlcLog, NoPathFound, InvalidGossipMsg, FeeBudgetExceeded, ImportedChannelBackupStorage,
OnchainChannelBackupStorage, ln_compare_features, IncompatibleLightningFeatures, PaymentFeeBudget,
- NBLOCK_CLTV_DELTA_TOO_FAR_INTO_FUTURE, GossipForwardingMessage, MIN_FUNDING_SAT
+ NBLOCK_CLTV_DELTA_TOO_FAR_INTO_FUTURE, GossipForwardingMessage, MIN_FUNDING_SAT,
+ RecvMPPResolution, ReceivedMPPStatus,
)
from .lnonion import decode_onion_error, OnionFailureCode, OnionRoutingFailure, OnionPacket
from .lnmsg import decode_msg
@@ -125,28 +126,6 @@ class PaymentInfo:
self.validate()
-# Note: these states are persisted in the wallet file.
-# Do not modify them without performing a wallet db upgrade
-class RecvMPPResolution(IntEnum):
- WAITING = 0
- EXPIRED = 1
- ACCEPTED = 2
- FAILED = 3
-
-
-class ReceivedMPPStatus(NamedTuple):
- resolution: RecvMPPResolution
- expected_msat: int
- htlc_set: Set[Tuple[ShortChannelID, UpdateAddHtlc]]
-
- @stored_in('received_mpp_htlcs', tuple)
- def from_tuple(resolution, expected_msat, htlc_list) -> 'ReceivedMPPStatus':
- htlc_set = set([(ShortChannelID(bytes.fromhex(scid)), UpdateAddHtlc.from_tuple(*x)) for (scid, x) in htlc_list])
- return ReceivedMPPStatus(
- resolution=RecvMPPResolution(resolution),
- expected_msat=expected_msat,
- htlc_set=htlc_set)
-
SentHtlcKey = Tuple[bytes, ShortChannelID, int] # RHASH, scid, htlc_id
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.