mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-03 03:29:50 +02:00
routing: reorganize BuildRoute
This commit is contained in:
parent
9decf80a68
commit
16f6284d97
@ -1409,8 +1409,7 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
||||
hops []route.Vertex, outgoingChan *uint64,
|
||||
finalCltvDelta int32, payAddr *[32]byte) (*route.Route, error) {
|
||||
|
||||
log.Tracef("BuildRoute called: hopsCount=%v, amt=%v",
|
||||
len(hops), amt)
|
||||
log.Tracef("BuildRoute called: hopsCount=%v, amt=%v", len(hops), amt)
|
||||
|
||||
var outgoingChans map[uint64]struct{}
|
||||
if outgoingChan != nil {
|
||||
@ -1419,6 +1418,17 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
||||
}
|
||||
}
|
||||
|
||||
// We'll attempt to obtain a set of bandwidth hints that helps us select
|
||||
// the best outgoing channel to use in case no outgoing channel is set.
|
||||
bandwidthHints, err := newBandwidthManager(
|
||||
r.cfg.RoutingGraph, r.cfg.SelfNode, r.cfg.GetLink,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sourceNode := r.cfg.SelfNode
|
||||
|
||||
// If no amount is specified, we need to build a route for the minimum
|
||||
// amount that this route can carry.
|
||||
useMinAmt := amt == nil
|
||||
@ -1436,23 +1446,6 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
||||
runningAmt = *amt
|
||||
}
|
||||
|
||||
// We'll attempt to obtain a set of bandwidth hints that helps us select
|
||||
// the best outgoing channel to use in case no outgoing channel is set.
|
||||
bandwidthHints, err := newBandwidthManager(
|
||||
r.cfg.RoutingGraph, r.cfg.SelfNode, r.cfg.GetLink,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Fetch the current block height outside the routing transaction, to
|
||||
// prevent the rpc call blocking the database.
|
||||
_, height, err := r.cfg.Chain.GetBestBlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sourceNode := r.cfg.SelfNode
|
||||
unifiers, senderAmt, err := getRouteUnifiers(
|
||||
sourceNode, hops, useMinAmt, runningAmt, outgoingChans,
|
||||
r.cfg.RoutingGraph, bandwidthHints,
|
||||
@ -1468,6 +1461,13 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Fetch the current block height outside the routing transaction, to
|
||||
// prevent the rpc call blocking the database.
|
||||
_, height, err := r.cfg.Chain.GetBestBlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Build and return the final route.
|
||||
return newRoute(
|
||||
sourceNode, pathEdges, uint32(height),
|
||||
|
Loading…
x
Reference in New Issue
Block a user