From 59a7a9d308dbcaa191c8befb1a9d63d99644e45c Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 10 Jan 2020 21:35:10 +0100 Subject: [PATCH 1/2] invoices: pre-check key send expiry --- invoices/invoiceregistry.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/invoices/invoiceregistry.go b/invoices/invoiceregistry.go index c3354c97..238e3bb7 100644 --- a/invoices/invoiceregistry.go +++ b/invoices/invoiceregistry.go @@ -736,6 +736,12 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx, // Use the minimum block delta that we require for settling htlcs. finalCltvDelta := i.cfg.FinalCltvRejectDelta + // Pre-check expiry here to prevent inserting an invoice that will not + // be settled. + if ctx.expiry < uint32(ctx.currentHeight+finalCltvDelta) { + return errors.New("final expiry too soon") + } + // Create placeholder invoice. invoice := &channeldb.Invoice{ CreationDate: i.cfg.Clock.Now(), From d3fa9767a9729756bab9b4a1121344b265410b1a Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 10 Jan 2020 10:25:53 +0100 Subject: [PATCH 2/2] rpc: use more sensible final cltv delta default when sending payments --- rpcserver.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index d16ad790..2f2142d2 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3535,7 +3535,11 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme if rpcPayReq.FinalCltvDelta != 0 { payIntent.cltvDelta = uint16(rpcPayReq.FinalCltvDelta) } else { - payIntent.cltvDelta = zpay32.DefaultFinalCLTVDelta + // If no final cltv delta is given, assume the default that we + // use when creating an invoice. We do not assume the default of + // 9 blocks that is defined in BOLT-11, because this is never + // enough for other lnd nodes. + payIntent.cltvDelta = uint16(cfg.Bitcoin.TimeLockDelta) } // If the user is manually specifying payment details, then the payment