electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 90f3b667aad43b21adbbbe29204e9b317130b49d
parent d0a80226ea89c673fe9bc45d570c2e287faf91a2
Author: SomberNight <somber.night@protonmail.com>
Date:   Mon, 30 Mar 2020 01:42:14 +0200

small clean-up re max CLTV delta for LN

Diffstat:
Melectrum/lnpeer.py | 5++++-
Melectrum/lnrouter.py | 4++--
Melectrum/lnutil.py | 2+-
Melectrum/lnworker.py | 2+-
4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -1027,13 +1027,16 @@ class Peer(Logger): assert amount_msat > 0, "amount_msat is not greater zero" if not chan.can_send_update_add_htlc(): raise PaymentFailure("Channel cannot send update_add_htlc") + local_height = self.network.get_local_height() # create onion packet - final_cltv = self.network.get_local_height() + min_final_cltv_expiry + final_cltv = local_height + min_final_cltv_expiry hops_data, amount_msat, cltv = calc_hops_data_for_payment(route, amount_msat, final_cltv) assert final_cltv <= cltv, (final_cltv, cltv) secret_key = os.urandom(32) onion = new_onion_packet([x.node_id for x in route], secret_key, hops_data, associated_data=payment_hash) # create htlc + if cltv > local_height + lnutil.NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE: + raise PaymentFailure(f"htlc expiry too far into future. (in {cltv-local_height} blocks)") htlc = UpdateAddHtlc(amount_msat=amount_msat, payment_hash=payment_hash, cltv_expiry=cltv, timestamp=int(time.time())) htlc = chan.add_htlc(htlc) chan.set_onion_key(htlc.htlc_id, secret_key) diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py @@ -31,6 +31,7 @@ from .util import bh2u, profiler from .logging import Logger from .lnutil import NUM_MAX_EDGES_IN_PAYMENT_PATH, ShortChannelID from .channel_db import ChannelDB, Policy +from .lnutil import NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE if TYPE_CHECKING: from .lnchannel import Channel @@ -99,8 +100,7 @@ def is_route_sane_to_use(route: LNPaymentRoute, invoice_amount_msat: int, min_fi cltv += route_edge.cltv_expiry_delta total_fee = amt - invoice_amount_msat # TODO revise ad-hoc heuristics - # cltv cannot be more than 2 months - if cltv > 60 * 144: + if cltv > NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE: return False if not is_fee_sane(total_fee, payment_amount_msat=invoice_amount_msat): return False diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -193,7 +193,7 @@ NBLOCK_OUR_CLTV_EXPIRY_DELTA = 144 OUR_FEE_BASE_MSAT = 1000 OUR_FEE_PROPORTIONAL_MILLIONTHS = 1 -NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE = 4032 +NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE = 28 * 144 # When we open a channel, the remote peer has to support at least this diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -1040,7 +1040,7 @@ class LNWallet(LNWorker): addr.amount = Decimal(amount_sat) / COIN if addr.amount is None: raise InvoiceError(_("Missing amount")) - if addr.get_min_final_cltv_expiry() > 60 * 144: + if addr.get_min_final_cltv_expiry() > lnutil.NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE: raise InvoiceError("{}\n{}".format( _("Invoice wants us to risk locking funds for unreasonably long."), f"min_final_cltv_expiry: {addr.get_min_final_cltv_expiry()}"))