Skip to content

Commit 32aa6ab

Browse files
f321xSomberNight
authored andcommitted
lnutil: rename RecvMPPResolution.ACCEPTED
Renames RecvMPPResolution.ACCEPTED to .COMPLETE as .ACCEPTED is somewhat misleading. Accepted could imply that the preimage for this set has been revealed or that the set has been settled, however it only means that we have received the full set (it is complete), but the set still can be failed (e.g. through cltv timeout) and has not been claimed yet.
1 parent 6a4ad9e commit 32aa6ab

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

electrum/commands.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ async def settle_hold_invoice(self, preimage: str, wallet: Abstract_Wallet = Non
14381438
assert payment_hash in wallet.lnworker.payment_info, \
14391439
f"Couldn't find lightning invoice for {payment_hash=}"
14401440
assert payment_hash in wallet.lnworker.dont_settle_htlcs, f"Invoice {payment_hash=} not a hold invoice?"
1441-
assert wallet.lnworker.is_accepted_mpp(bfh(payment_hash)), \
1441+
assert wallet.lnworker.is_complete_mpp(bfh(payment_hash)), \
14421442
f"MPP incomplete, cannot settle hold invoice {payment_hash} yet"
14431443
info: Optional['PaymentInfo'] = wallet.lnworker.get_payment_info(bfh(payment_hash))
14441444
assert (wallet.lnworker.get_payment_mpp_amount_msat(bfh(payment_hash)) or 0) >= (info.amount_msat or 0)
@@ -1465,7 +1465,7 @@ async def cancel_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
14651465
wallet.lnworker.set_payment_status(bfh(payment_hash), PR_UNPAID)
14661466
wallet.lnworker.delete_payment_info(payment_hash)
14671467
wallet.set_label(payment_hash, None)
1468-
while wallet.lnworker.is_accepted_mpp(bfh(payment_hash)):
1468+
while wallet.lnworker.is_complete_mpp(bfh(payment_hash)):
14691469
# wait until the htlcs got failed so the payment won't get settled accidentally in a race
14701470
await asyncio.sleep(0.1)
14711471
del wallet.lnworker.dont_settle_htlcs[payment_hash]
@@ -1490,18 +1490,18 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
14901490
"""
14911491
assert len(payment_hash) == 64, f"Invalid payment_hash length: {len(payment_hash)} != 64"
14921492
info: Optional['PaymentInfo'] = wallet.lnworker.get_payment_info(bfh(payment_hash))
1493-
is_accepted_mpp: bool = wallet.lnworker.is_accepted_mpp(bfh(payment_hash))
1493+
is_complete_mpp: bool = wallet.lnworker.is_complete_mpp(bfh(payment_hash))
14941494
amount_sat = (wallet.lnworker.get_payment_mpp_amount_msat(bfh(payment_hash)) or 0) // 1000
14951495
result = {
14961496
"status": "unknown",
14971497
"received_amount_sat": amount_sat,
14981498
}
14991499
if info is None:
15001500
pass
1501-
elif not is_accepted_mpp and not wallet.lnworker.get_preimage_hex(payment_hash):
1502-
# is_accepted_mpp is False for settled payments
1501+
elif not is_complete_mpp and not wallet.lnworker.get_preimage_hex(payment_hash):
1502+
# is_complete_mpp is False for settled payments
15031503
result["status"] = "unpaid"
1504-
elif is_accepted_mpp and payment_hash in wallet.lnworker.dont_settle_htlcs:
1504+
elif is_complete_mpp and payment_hash in wallet.lnworker.dont_settle_htlcs:
15051505
result["status"] = "paid"
15061506
payment_key: str = wallet.lnworker._get_payment_key(bfh(payment_hash)).hex()
15071507
htlc_status = wallet.lnworker.received_mpp_htlcs[payment_key]

electrum/lnpeer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ def check_mpp_is_waiting(
24802480
elif mpp_resolution == RecvMPPResolution.FAILED:
24812481
log_fail_reason(f"mpp_resolution is FAILED")
24822482
raise exc_incorrect_or_unknown_pd
2483-
elif mpp_resolution == RecvMPPResolution.ACCEPTED:
2483+
elif mpp_resolution == RecvMPPResolution.COMPLETE:
24842484
return False
24852485
else:
24862486
raise Exception(f"unexpected {mpp_resolution=}")

electrum/lnsweep.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def txs_htlc(
432432
ctn=ctn)
433433
for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items():
434434
if direction == RECEIVED:
435-
if not chan.lnworker.is_accepted_mpp(htlc.payment_hash):
435+
if not chan.lnworker.is_complete_mpp(htlc.payment_hash):
436436
# do not redeem this, it might publish the preimage of an incomplete MPP
437437
continue
438438
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
@@ -727,7 +727,7 @@ def tx_htlc(
727727
for (direction, htlc), (ctx_output_idx, htlc_relative_idx) in htlc_to_ctx_output_idx_map.items():
728728
is_received_htlc = direction == RECEIVED
729729
if not is_received_htlc and not is_revocation:
730-
if not chan.lnworker.is_accepted_mpp(htlc.payment_hash):
730+
if not chan.lnworker.is_complete_mpp(htlc.payment_hash):
731731
# do not redeem this, it might publish the preimage of an incomplete MPP
732732
continue
733733
preimage = chan.lnworker.get_preimage(htlc.payment_hash)

electrum/lnutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ def __post_init__(self):
19351935
class RecvMPPResolution(IntEnum):
19361936
WAITING = 0
19371937
EXPIRED = 1
1938-
ACCEPTED = 2
1938+
COMPLETE = 2
19391939
FAILED = 3
19401940

19411941

electrum/lnworker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,12 +2444,12 @@ def check_mpp_status(
24442444
payment_keys = [payment_key]
24452445
first_timestamp = min([self.get_first_timestamp_of_mpp(pkey) for pkey in payment_keys])
24462446
if self.get_payment_status(payment_hash) == PR_PAID:
2447-
mpp_resolution = RecvMPPResolution.ACCEPTED
2447+
mpp_resolution = RecvMPPResolution.COMPLETE
24482448
elif self.stopping_soon:
24492449
# try to time out pending HTLCs before shutting down
24502450
mpp_resolution = RecvMPPResolution.EXPIRED
24512451
elif all([self.is_mpp_amount_reached(pkey) for pkey in payment_keys]):
2452-
mpp_resolution = RecvMPPResolution.ACCEPTED
2452+
mpp_resolution = RecvMPPResolution.COMPLETE
24532453
elif time.time() - first_timestamp > self.MPP_EXPIRY:
24542454
mpp_resolution = RecvMPPResolution.EXPIRED
24552455
# save resolution, if any.
@@ -2497,10 +2497,10 @@ def is_mpp_amount_reached(self, payment_key: bytes) -> bool:
24972497
total, expected = amounts
24982498
return total >= expected
24992499

2500-
def is_accepted_mpp(self, payment_hash: bytes) -> bool:
2500+
def is_complete_mpp(self, payment_hash: bytes) -> bool:
25012501
payment_key = self._get_payment_key(payment_hash)
25022502
status = self.received_mpp_htlcs.get(payment_key.hex())
2503-
return status and status.resolution == RecvMPPResolution.ACCEPTED
2503+
return status and status.resolution == RecvMPPResolution.COMPLETE
25042504

25052505
def get_payment_mpp_amount_msat(self, payment_hash: bytes) -> Optional[int]:
25062506
"""Returns the received mpp amount for given payment hash."""

tests/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ async def test_hold_invoice_commands(self, mock_save_db):
547547
mock_htlc2.amount_msat = 5_500_000
548548
mock_htlc_status = mock.Mock()
549549
mock_htlc_status.htlc_set = [(None, mock_htlc1), (None, mock_htlc2)]
550-
mock_htlc_status.resolution = RecvMPPResolution.ACCEPTED
550+
mock_htlc_status.resolution = RecvMPPResolution.COMPLETE
551551

552552
payment_key = wallet.lnworker._get_payment_key(bytes.fromhex(payment_hash)).hex()
553553
with mock.patch.dict(wallet.lnworker.received_mpp_htlcs, {payment_key: mock_htlc_status}):

0 commit comments

Comments
 (0)