Skip to content

Commit

Permalink
graph+routing: let FetchNodeFeatures take a RTx
Browse files Browse the repository at this point in the history
Most call-sites of this method have a read transaction available to pass
in. Note that this also means that calls to FetchNodeFeatures made from
the router are made under the same read transaction as calls to
ForEachNodeDirectedChannel which makes things cleaner.
  • Loading branch information
ellemouton committed Nov 4, 2024
1 parent d22d9a2 commit 3755829
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions graph/db/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx RTx,
toNodeCallback := func() route.Vertex {
return node
}
toNodeFeatures, err := c.FetchNodeFeatures(node)
toNodeFeatures, err := c.FetchNodeFeatures(tx, node)
if err != nil {
return err
}
Expand Down Expand Up @@ -570,15 +570,15 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx RTx,

// FetchNodeFeatures returns the features of a given node. If no features are
// known for the node, an empty feature vector is returned.
func (c *ChannelGraph) FetchNodeFeatures(
func (c *ChannelGraph) FetchNodeFeatures(tx RTx,
node route.Vertex) (*lnwire.FeatureVector, error) {

if c.graphCache != nil {
return c.graphCache.GetFeatures(node), nil
}

// Fallback that uses the database.
targetNode, err := c.FetchLightningNode(nil, node)
targetNode, err := c.FetchLightningNode(tx, node)
switch err {
// If the node exists and has features, return them directly.
case nil:
Expand Down Expand Up @@ -625,7 +625,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
return node.PubKeyBytes
}
toNodeFeatures, err := c.FetchNodeFeatures(
node.PubKeyBytes,
tx, node.PubKeyBytes,
)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions graph/graphsession/graph_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (g *session) ForEachNodeChannel(nodePub route.Vertex,
func (g *session) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {

return g.graph.FetchNodeFeatures(nodePub)
return g.graph.FetchNodeFeatures(g.tx, nodePub)
}

// A compile-time check to ensure that *session implements the
Expand Down Expand Up @@ -132,7 +132,8 @@ type graph interface {

// FetchNodeFeatures returns the features of a given node. If no
// features are known for the node, an empty feature vector is returned.
FetchNodeFeatures(node route.Vertex) (*lnwire.FeatureVector, error)
FetchNodeFeatures(tx graphdb.RTx, node route.Vertex) (
*lnwire.FeatureVector, error)
}

// A compile-time check to ensure that *channeldb.ChannelGraph implements the
Expand Down
2 changes: 1 addition & 1 deletion routing/integrated_routing_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,5 @@ func (g *mockGraphSessionChanDB) ForEachNodeChannel(nodePub route.Vertex,
func (g *mockGraphSessionChanDB) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {

return g.graph.FetchNodeFeatures(nodePub)
return g.graph.FetchNodeFeatures(g.tx, nodePub)
}

0 comments on commit 3755829

Please sign in to comment.