diff --git a/routing/payment_session.go b/routing/payment_session.go index 117523e91..b1d8a9b03 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