mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-30 02:21:08 +02:00
routing: reorganize BuildRoute
This commit is contained in:
@ -1409,8 +1409,7 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
|||||||
hops []route.Vertex, outgoingChan *uint64,
|
hops []route.Vertex, outgoingChan *uint64,
|
||||||
finalCltvDelta int32, payAddr *[32]byte) (*route.Route, error) {
|
finalCltvDelta int32, payAddr *[32]byte) (*route.Route, error) {
|
||||||
|
|
||||||
log.Tracef("BuildRoute called: hopsCount=%v, amt=%v",
|
log.Tracef("BuildRoute called: hopsCount=%v, amt=%v", len(hops), amt)
|
||||||
len(hops), amt)
|
|
||||||
|
|
||||||
var outgoingChans map[uint64]struct{}
|
var outgoingChans map[uint64]struct{}
|
||||||
if outgoingChan != nil {
|
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
|
// If no amount is specified, we need to build a route for the minimum
|
||||||
// amount that this route can carry.
|
// amount that this route can carry.
|
||||||
useMinAmt := amt == nil
|
useMinAmt := amt == nil
|
||||||
@ -1436,23 +1446,6 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
|||||||
runningAmt = *amt
|
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(
|
unifiers, senderAmt, err := getRouteUnifiers(
|
||||||
sourceNode, hops, useMinAmt, runningAmt, outgoingChans,
|
sourceNode, hops, useMinAmt, runningAmt, outgoingChans,
|
||||||
r.cfg.RoutingGraph, bandwidthHints,
|
r.cfg.RoutingGraph, bandwidthHints,
|
||||||
@ -1468,6 +1461,13 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
|||||||
return nil, err
|
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.
|
// Build and return the final route.
|
||||||
return newRoute(
|
return newRoute(
|
||||||
sourceNode, pathEdges, uint32(height),
|
sourceNode, pathEdges, uint32(height),
|
||||||
|
Reference in New Issue
Block a user