From 3dde7bc4e2a1e218ce8b3e725a57f0c9fd0ae0f2 Mon Sep 17 00:00:00 2001 From: nsa Date: Tue, 23 Jul 2019 20:59:31 -0400 Subject: [PATCH] routing: adding the BlockPadding value to sendpayment This commit adds the BlockPadding value (currently 3) to sendpayment calls so that if some blocks are mined while the htlc is in-flight, the exit hop won't reject it. --- routing/payment_session.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/routing/payment_session.go b/routing/payment_session.go index 117523e9..b1d8a9b0 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -8,6 +8,10 @@ import ( "github.com/lightningnetwork/lnd/routing/route" ) +// BlockPadding is used to increment the finalCltvDelta value for the last hop +// to prevent an HTLC being failed if some blocks are mined while it's in-flight. +const BlockPadding uint16 = 3 + // PaymentSession is used during SendPayment attempts to provide routes to // attempt. It also defines methods to give the PaymentSession additional // information learned during the previous attempts. @@ -65,6 +69,10 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment, return nil, fmt.Errorf("pre-built route already tried") } + // Add BlockPadding to the finalCltvDelta so that the receiving node + // does not reject the HTLC if some blocks are mined while it's in-flight. + finalCltvDelta += BlockPadding + // If a route cltv limit was specified, we need to subtract the final // delta before passing it into path finding. The optimal path is // independent of the final cltv delta and the path finding algorithm is