diff --git a/graph/db/graph.go b/graph/db/graph.go index 49c24441b..cb53ae547 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -594,6 +594,30 @@ func (c *ChannelGraph) FetchNodeFeaturesTx(tx kvdb.RTx, } } +// ForEachNodeDirectedChannel iterates through all channels of a given node, +// executing the passed callback on the directed edge representing the channel +// and its incoming policy. If the callback returns an error, then the iteration +// is halted with the error propagated back up to the caller. If the graphCache +// is available, then it will be used to retrieve the node's channels instead +// of the database. +// +// Unknown policies are passed into the callback as nil values. +func (c *ChannelGraph) ForEachNodeDirectedChannel(nodePub route.Vertex, + cb func(channel *DirectedChannel) error) error { + + return c.ForEachNodeDirectedChannelTx(nil, nodePub, cb) +} + +// FetchNodeFeatures returns the features of the given node. If no features are +// known for the node, an empty feature vector is returned. +// If the graphCache is available, then it will be used to retrieve the node's +// features instead of the database. +func (c *ChannelGraph) FetchNodeFeatures(nodePub route.Vertex) ( + *lnwire.FeatureVector, error) { + + return c.FetchNodeFeaturesTx(nil, nodePub) +} + // ForEachNodeCached is similar to forEachNode, but it utilizes the channel // graph cache instead. Note that this doesn't return all the information the // regular forEachNode method does. diff --git a/graph/graphsession/graph_session.go b/graph/graphsession/graph_session.go index 31265ff56..535a8beb5 100644 --- a/graph/graphsession/graph_session.go +++ b/graph/graphsession/graph_session.go @@ -56,15 +56,6 @@ type session struct { tx kvdb.RTx } -// NewRoutingGraph constructs a session that which does not first start a -// read-only transaction and so each call on the routing.Graph will create a -// new transaction. -func NewRoutingGraph(graph ReadOnlyGraph) routing.Graph { - return &session{ - graph: graph, - } -} - // close closes the read-only transaction being used to access the backing // graph. If no transaction was started then this is a no-op. func (g *session) close() error { diff --git a/rpcserver.go b/rpcserver.go index e096d31f8..2ed695ff0 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -51,7 +51,6 @@ import ( "github.com/lightningnetwork/lnd/graph" graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/graph/db/models" - "github.com/lightningnetwork/lnd/graph/graphsession" "github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/input" @@ -711,8 +710,8 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service, amount lnwire.MilliSatoshi) (btcutil.Amount, error) { return routing.FetchAmountPairCapacity( - graphsession.NewRoutingGraph(graph), - selfNode.PubKeyBytes, nodeFrom, nodeTo, amount, + graph, selfNode.PubKeyBytes, nodeFrom, nodeTo, + amount, ) }, FetchChannelEndpoints: func(chanID uint64) (route.Vertex, diff --git a/server.go b/server.go index f85d60f52..0e370d293 100644 --- a/server.go +++ b/server.go @@ -1073,7 +1073,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, s.chanRouter, err = routing.New(routing.Config{ SelfNode: selfNode.PubKeyBytes, - RoutingGraph: graphsession.NewRoutingGraph(dbs.GraphDB), + RoutingGraph: dbs.GraphDB, Chain: cc.ChainIO, Payer: s.htlcSwitch, Control: s.controlTower,