Skip to content

Commit 8ec08fb

Browse files
committed
multi: remove the need for NewRoutingGraph
The `graphsession.NewRoutingGraph` method was used to create a RoutingGraph instance with no consistent read transaction across calls. But now that the ChannelGraph directly implements this, we can remove The NewRoutingGraph method.
1 parent 5d5cfe3 commit 8ec08fb

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

graph/db/graph.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,30 @@ func (c *ChannelGraph) FetchNodeFeaturesTx(tx kvdb.RTx,
594594
}
595595
}
596596

597+
// ForEachNodeDirectedChannel iterates through all channels of a given node,
598+
// executing the passed callback on the directed edge representing the channel
599+
// and its incoming policy. If the callback returns an error, then the iteration
600+
// is halted with the error propagated back up to the caller. If the graphCache
601+
// is available, then it will be used to retrieve the node's channels instead
602+
// of the database.
603+
//
604+
// Unknown policies are passed into the callback as nil values.
605+
func (c *ChannelGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
606+
cb func(channel *DirectedChannel) error) error {
607+
608+
return c.ForEachNodeDirectedChannelTx(nil, nodePub, cb)
609+
}
610+
611+
// FetchNodeFeatures returns the features of the given node. If no features are
612+
// known for the node, an empty feature vector is returned.
613+
// If the graphCache is available, then it will be used to retrieve the node's
614+
// features instead of the database.
615+
func (c *ChannelGraph) FetchNodeFeatures(nodePub route.Vertex) (
616+
*lnwire.FeatureVector, error) {
617+
618+
return c.FetchNodeFeaturesTx(nil, nodePub)
619+
}
620+
597621
// ForEachNodeCached is similar to forEachNode, but it utilizes the channel
598622
// graph cache instead. Note that this doesn't return all the information the
599623
// regular forEachNode method does.

graph/graphsession/graph_session.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ type session struct {
5656
tx kvdb.RTx
5757
}
5858

59-
// NewRoutingGraph constructs a session that which does not first start a
60-
// read-only transaction and so each call on the routing.Graph will create a
61-
// new transaction.
62-
func NewRoutingGraph(graph ReadOnlyGraph) routing.Graph {
63-
return &session{
64-
graph: graph,
65-
}
66-
}
67-
6859
// close closes the read-only transaction being used to access the backing
6960
// graph. If no transaction was started then this is a no-op.
7061
func (g *session) close() error {

rpcserver.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"github.com/lightningnetwork/lnd/graph"
5252
graphdb "github.com/lightningnetwork/lnd/graph/db"
5353
"github.com/lightningnetwork/lnd/graph/db/models"
54-
"github.com/lightningnetwork/lnd/graph/graphsession"
5554
"github.com/lightningnetwork/lnd/htlcswitch"
5655
"github.com/lightningnetwork/lnd/htlcswitch/hop"
5756
"github.com/lightningnetwork/lnd/input"
@@ -711,8 +710,8 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
711710
amount lnwire.MilliSatoshi) (btcutil.Amount, error) {
712711

713712
return routing.FetchAmountPairCapacity(
714-
graphsession.NewRoutingGraph(graph),
715-
selfNode.PubKeyBytes, nodeFrom, nodeTo, amount,
713+
graph, selfNode.PubKeyBytes, nodeFrom, nodeTo,
714+
amount,
716715
)
717716
},
718717
FetchChannelEndpoints: func(chanID uint64) (route.Vertex,

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
10731073

10741074
s.chanRouter, err = routing.New(routing.Config{
10751075
SelfNode: selfNode.PubKeyBytes,
1076-
RoutingGraph: graphsession.NewRoutingGraph(dbs.GraphDB),
1076+
RoutingGraph: dbs.GraphDB,
10771077
Chain: cc.ChainIO,
10781078
Payer: s.htlcSwitch,
10791079
Control: s.controlTower,

0 commit comments

Comments
 (0)