Skip to content

Commit 2b0cab6

Browse files
committed
partial merge 2: f321x's "lightning: refactor htlc switch"
split-off from spesmilo#10230 Merge commit '286fc4b86e4d23cb9af15b9061b3d709e7592bcb'
2 parents 3d27992 + 286fc4b commit 2b0cab6

File tree

10 files changed

+465
-404
lines changed

10 files changed

+465
-404
lines changed

electrum/commands.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
)
6969
from .address_synchronizer import TX_HEIGHT_LOCAL
7070
from .mnemonic import Mnemonic
71-
from .lnutil import (channel_id_from_funding_tx, LnFeatures, SENT, MIN_FINAL_CLTV_DELTA_FOR_INVOICE,
71+
from .lnutil import (channel_id_from_funding_tx, LnFeatures, SENT, MIN_FINAL_CLTV_DELTA_ACCEPTED,
7272
PaymentFeeBudget, NBLOCK_CLTV_DELTA_TOO_FAR_INTO_FUTURE)
7373
from .plugin import run_hook, DeviceMgr, Plugins
7474
from .version import ELECTRUM_VERSION
@@ -1382,7 +1382,7 @@ async def add_hold_invoice(
13821382
amount: Optional[Decimal] = None,
13831383
memo: str = "",
13841384
expiry: int = 3600,
1385-
min_final_cltv_expiry_delta: int = MIN_FINAL_CLTV_DELTA_FOR_INVOICE * 2,
1385+
min_final_cltv_expiry_delta: int = MIN_FINAL_CLTV_DELTA_ACCEPTED * 2,
13861386
wallet: Abstract_Wallet = None
13871387
) -> dict:
13881388
"""
@@ -1399,24 +1399,24 @@ async def add_hold_invoice(
13991399
assert payment_hash not in wallet.lnworker.payment_info, "Payment hash already used!"
14001400
assert payment_hash not in wallet.lnworker.dont_settle_htlcs, "Payment hash already used!"
14011401
assert wallet.lnworker.get_preimage(bfh(payment_hash)) is None, "Already got a preimage for this payment hash!"
1402-
assert MIN_FINAL_CLTV_DELTA_FOR_INVOICE < min_final_cltv_expiry_delta < 576, "Use a sane min_final_cltv_expiry_delta value"
1402+
assert MIN_FINAL_CLTV_DELTA_ACCEPTED < min_final_cltv_expiry_delta < 576, "Use a sane min_final_cltv_expiry_delta value"
14031403
amount = amount if amount and satoshis(amount) > 0 else None # make amount either >0 or None
14041404
inbound_capacity = wallet.lnworker.num_sats_can_receive()
14051405
assert inbound_capacity > satoshis(amount or 0), \
14061406
f"Not enough inbound capacity [{inbound_capacity} sat] to receive this payment"
14071407

1408+
wallet.lnworker.add_payment_info_for_hold_invoice(
1409+
bfh(payment_hash),
1410+
lightning_amount_sat=satoshis(amount) if amount else None,
1411+
min_final_cltv_delta=min_final_cltv_expiry_delta,
1412+
exp_delay=expiry,
1413+
)
1414+
info = wallet.lnworker.get_payment_info(bfh(payment_hash))
14081415
lnaddr, invoice = wallet.lnworker.get_bolt11_invoice(
1409-
payment_hash=bfh(payment_hash),
1410-
amount_msat=satoshis(amount) * 1000 if amount else None,
1416+
payment_info=info,
14111417
message=memo,
1412-
expiry=expiry,
1413-
min_final_cltv_expiry_delta=min_final_cltv_expiry_delta,
14141418
fallback_address=None
14151419
)
1416-
wallet.lnworker.add_payment_info_for_hold_invoice(
1417-
bfh(payment_hash),
1418-
satoshis(amount) if amount else None,
1419-
)
14201420
wallet.lnworker.dont_settle_htlcs[payment_hash] = None
14211421
wallet.set_label(payment_hash, memo)
14221422
result = {

electrum/gui/qt/main_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ def warning_callback() -> Optional[str]:
27582758
self.closing_warning_callbacks.append(warning_callback)
27592759

27602760
def _check_ongoing_force_closures(self) -> Optional[str]:
2761-
from electrum.lnutil import MIN_FINAL_CLTV_DELTA_FOR_INVOICE
2761+
from electrum.lnutil import MIN_FINAL_CLTV_DELTA_ACCEPTED
27622762
if not self.wallet.has_lightning():
27632763
return None
27642764
if not self.network:
@@ -2767,7 +2767,7 @@ def _check_ongoing_force_closures(self) -> Optional[str]:
27672767
if not force_closes:
27682768
return
27692769
# fixme: this is inaccurate, we need local_height - cltv_of_htlc
2770-
cltv_delta = MIN_FINAL_CLTV_DELTA_FOR_INVOICE
2770+
cltv_delta = MIN_FINAL_CLTV_DELTA_ACCEPTED
27712771
msg = '\n\n'.join([
27722772
_("Pending channel force-close"),
27732773
messages.MSG_FORCE_CLOSE_WARNING.format(cltv_delta),

electrum/lnpeer.py

Lines changed: 3 additions & 321 deletions
Large diffs are not rendered by default.

electrum/lnutil.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,10 @@ class LNProtocolWarning(Exception):
505505
# the minimum cltv_expiry accepted for newly received HTLCs
506506
# note: when changing, consider Blockchain.is_tip_stale()
507507
MIN_FINAL_CLTV_DELTA_ACCEPTED = 144
508-
# set it a tiny bit higher for invoices as blocks could get mined
509-
# during forward path of payment
510-
MIN_FINAL_CLTV_DELTA_FOR_INVOICE = MIN_FINAL_CLTV_DELTA_ACCEPTED + 3
508+
509+
# buffer added to min_final_cltv_delta of created bolt11 invoices to make verifying the cltv delta
510+
# of incoming payment htlcs reliable even if some blocks have been mined during forwarding
511+
MIN_FINAL_CLTV_DELTA_BUFFER_INVOICE = 3
511512

512513
# the deadline for offered HTLCs:
513514
# the deadline after which the channel has to be failed and timed out on-chain

0 commit comments

Comments
 (0)