mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 10:09:08 +02:00
multi: add abstraction for Router and SessionSource graph access
In this commit, we completely remove the Router's dependence on a Graph source that requires a `kvdb.RTx`. In so doing, we are more prepared for a future where the Graph source is backed by different DB structure such as pure SQL. The two areas affected here are: the ChannelRouter's graph access that it uses for pathfinding. And the SessionSource's graph access that it uses for payments. The ChannelRouter gets given a Graph and the SessionSource is given a GraphSessionFactory which it can use to create a new session. Behind the scenes, this will acquire a kvdb.RTx that will be used for calls to the Graph's `ForEachNodeChannel` method.
This commit is contained in:
18
rpcserver.go
18
rpcserver.go
@ -41,6 +41,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chanbackup"
|
||||
"github.com/lightningnetwork/lnd/chanfitness"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/graphsession"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
@ -691,22 +692,9 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
|
||||
FetchAmountPairCapacity: func(nodeFrom, nodeTo route.Vertex,
|
||||
amount lnwire.MilliSatoshi) (btcutil.Amount, error) {
|
||||
|
||||
routingGraph, err := routing.NewCachedGraph(graph)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer func() {
|
||||
closeErr := routingGraph.Close()
|
||||
if closeErr != nil {
|
||||
rpcsLog.Errorf("not able to close "+
|
||||
"routing graph tx: %v",
|
||||
closeErr)
|
||||
}
|
||||
}()
|
||||
|
||||
return routing.FetchAmountPairCapacity(
|
||||
routingGraph, selfNode.PubKeyBytes, nodeFrom,
|
||||
nodeTo, amount,
|
||||
graphsession.NewRoutingGraph(graph),
|
||||
selfNode.PubKeyBytes, nodeFrom, nodeTo, amount,
|
||||
)
|
||||
},
|
||||
FetchChannelEndpoints: func(chanID uint64) (route.Vertex,
|
||||
|
Reference in New Issue
Block a user