mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-11 09:23:09 +02:00
routing: perform path finding inside a single DB transaction
This commit modifies the path finding logic such that all path finding is done inside a _single_ database transaction. With this change, we ensure that we don’t end up possibly creating hundreds of database transactions slowing down the path finding and payment sending process all together.
This commit is contained in:
@@ -978,14 +978,24 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx, err := r.cfg.Graph.Database().Begin(false)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Now that we know the destination is reachable within the graph,
|
||||
// we'll execute our KSP algorithm to find the k-shortest paths from
|
||||
// our source to the destination.
|
||||
shortestPaths, err := findPaths(r.cfg.Graph, r.selfNode, target, amt)
|
||||
shortestPaths, err := findPaths(tx, r.cfg.Graph, r.selfNode, target,
|
||||
amt)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx.Rollback()
|
||||
|
||||
// Now that we have a set of paths, we'll need to turn them into
|
||||
// *routes* by computing the required time-lock and fee information for
|
||||
// each path. During this process, some paths may be discarded if they
|
||||
@@ -1032,7 +1042,7 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
|
||||
return validRoutes[i].TotalFees < validRoutes[j].TotalFees
|
||||
})
|
||||
|
||||
log.Tracef("Obtained %v paths sending %v to %x: %v", len(validRoutes),
|
||||
go log.Tracef("Obtained %v paths sending %v to %x: %v", len(validRoutes),
|
||||
amt, dest, newLogClosure(func() string {
|
||||
return spew.Sdump(validRoutes)
|
||||
}),
|
||||
|
Reference in New Issue
Block a user