small clean-up re max CLTV delta for LN
This commit is contained in:
@@ -1027,13 +1027,16 @@ class Peer(Logger):
|
|||||||
assert amount_msat > 0, "amount_msat is not greater zero"
|
assert amount_msat > 0, "amount_msat is not greater zero"
|
||||||
if not chan.can_send_update_add_htlc():
|
if not chan.can_send_update_add_htlc():
|
||||||
raise PaymentFailure("Channel cannot send update_add_htlc")
|
raise PaymentFailure("Channel cannot send update_add_htlc")
|
||||||
|
local_height = self.network.get_local_height()
|
||||||
# create onion packet
|
# 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)
|
hops_data, amount_msat, cltv = calc_hops_data_for_payment(route, amount_msat, final_cltv)
|
||||||
assert final_cltv <= cltv, (final_cltv, cltv)
|
assert final_cltv <= cltv, (final_cltv, cltv)
|
||||||
secret_key = os.urandom(32)
|
secret_key = os.urandom(32)
|
||||||
onion = new_onion_packet([x.node_id for x in route], secret_key, hops_data, associated_data=payment_hash)
|
onion = new_onion_packet([x.node_id for x in route], secret_key, hops_data, associated_data=payment_hash)
|
||||||
# create htlc
|
# 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 = UpdateAddHtlc(amount_msat=amount_msat, payment_hash=payment_hash, cltv_expiry=cltv, timestamp=int(time.time()))
|
||||||
htlc = chan.add_htlc(htlc)
|
htlc = chan.add_htlc(htlc)
|
||||||
chan.set_onion_key(htlc.htlc_id, secret_key)
|
chan.set_onion_key(htlc.htlc_id, secret_key)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from .util import bh2u, profiler
|
|||||||
from .logging import Logger
|
from .logging import Logger
|
||||||
from .lnutil import NUM_MAX_EDGES_IN_PAYMENT_PATH, ShortChannelID
|
from .lnutil import NUM_MAX_EDGES_IN_PAYMENT_PATH, ShortChannelID
|
||||||
from .channel_db import ChannelDB, Policy
|
from .channel_db import ChannelDB, Policy
|
||||||
|
from .lnutil import NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .lnchannel import Channel
|
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
|
cltv += route_edge.cltv_expiry_delta
|
||||||
total_fee = amt - invoice_amount_msat
|
total_fee = amt - invoice_amount_msat
|
||||||
# TODO revise ad-hoc heuristics
|
# TODO revise ad-hoc heuristics
|
||||||
# cltv cannot be more than 2 months
|
if cltv > NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE:
|
||||||
if cltv > 60 * 144:
|
|
||||||
return False
|
return False
|
||||||
if not is_fee_sane(total_fee, payment_amount_msat=invoice_amount_msat):
|
if not is_fee_sane(total_fee, payment_amount_msat=invoice_amount_msat):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ NBLOCK_OUR_CLTV_EXPIRY_DELTA = 144
|
|||||||
OUR_FEE_BASE_MSAT = 1000
|
OUR_FEE_BASE_MSAT = 1000
|
||||||
OUR_FEE_PROPORTIONAL_MILLIONTHS = 1
|
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
|
# When we open a channel, the remote peer has to support at least this
|
||||||
|
|||||||
@@ -1040,7 +1040,7 @@ class LNWallet(LNWorker):
|
|||||||
addr.amount = Decimal(amount_sat) / COIN
|
addr.amount = Decimal(amount_sat) / COIN
|
||||||
if addr.amount is None:
|
if addr.amount is None:
|
||||||
raise InvoiceError(_("Missing amount"))
|
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(
|
raise InvoiceError("{}\n{}".format(
|
||||||
_("Invoice wants us to risk locking funds for unreasonably long."),
|
_("Invoice wants us to risk locking funds for unreasonably long."),
|
||||||
f"min_final_cltv_expiry: {addr.get_min_final_cltv_expiry()}"))
|
f"min_final_cltv_expiry: {addr.get_min_final_cltv_expiry()}"))
|
||||||
|
|||||||
Reference in New Issue
Block a user