From c8f45e3a044fe675552f7a7e65ae43591d6a1f32 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 18 Oct 2017 21:59:06 -0700 Subject: [PATCH] routing: add new param to FindRoutes for CLTV expiry for final hop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we modify the FindRoutes method to pass in the CLTV expiry for the final hop. If the value isn’t passed in, then we’ll use the current global default value in place. --- routing/router.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/routing/router.go b/routing/router.go index 6c46fc8f..1b98b2a5 100644 --- a/routing/router.go +++ b/routing/router.go @@ -25,6 +25,12 @@ import ( "github.com/lightningnetwork/lightning-onion" ) +const ( + // DefaultFinalCLTVDelta is the default value to be used as the final + // CLTV delta for a route if one is unspecified. + DefaultFinalCLTVDelta = 9 +) + // ChannelGraphSource represent the source of information about the topology of // lightning network, it responsible for addition of nodes, edges // and applying edges updates, return the current block with with out @@ -948,7 +954,14 @@ func pruneChannelFromRoutes(routes []*Route, skipChan uint64) []*Route { // route that will be ranked the highest is the one with the lowest cumulative // fee along the route. func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey, - amt lnwire.MilliSatoshi) ([]*Route, error) { + amt lnwire.MilliSatoshi, finalExpiry ...uint16) ([]*Route, error) { + + var finalCLTVDelta uint16 + if len(finalExpiry) == 0 { + finalCLTVDelta = DefaultFinalCLTVDelta + } else { + finalCLTVDelta = finalExpiry[0] + } // TODO(roasbeef): make num routes a param @@ -1024,7 +1037,7 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey, // hop in the path as it contains a "self-hop" that is inserted // by our KSP algorithm. route, err := newRoute(amt, sourceVertex, path[1:], - uint32(currentHeight)) + uint32(currentHeight), finalCLTVDelta) if err != nil { continue }