graph/db: thread context through FetchNodeFeatures
This commit is contained in:
8 files changed
+30
-22
No files matched your search
+3
-3
@@ -236,14 +236,14 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(node route.Vertex,
|
||||
// features instead of the database.
|
||||
//
|
||||
// NOTE: this is part of the graphdb.NodeTraverser interface.
|
||||
func (c *ChannelGraph) FetchNodeFeatures(node route.Vertex) (
|
||||
*lnwire.FeatureVector, error) {
|
||||
func (c *ChannelGraph) FetchNodeFeatures(ctx context.Context,
|
||||
node route.Vertex) (*lnwire.FeatureVector, error) {
|
||||
|
||||
if c.graphCache != nil {
|
||||
return c.graphCache.GetFeatures(node), nil
|
||||
}
|
||||
|
||||
return c.db.FetchNodeFeatures(lnwire.GossipVersion1, node)
|
||||
return c.db.FetchNodeFeatures(ctx, lnwire.GossipVersion1, node)
|
||||
}
|
||||
|
||||
// GraphSession will provide the call-back with access to a NodeTraverser
|
||||
|
||||
@@ -298,13 +298,13 @@ func testNodeInsertionAndDeletion(t *testing.T, v lnwire.GossipVersion) {
|
||||
|
||||
// Check that the node's features are fetched correctly. This check
|
||||
// will use the graph cache to fetch the features.
|
||||
features, err := graph.FetchNodeFeatures(node.PubKeyBytes)
|
||||
features, err := graph.FetchNodeFeatures(ctx, node.PubKeyBytes)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, testFeatures, features)
|
||||
|
||||
// Check that the node's features are fetched correctly. This check
|
||||
// will check the database directly.
|
||||
features, err = graph.FetchNodeFeatures(node.PubKeyBytes)
|
||||
features, err = graph.FetchNodeFeatures(ctx, node.PubKeyBytes)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, testFeatures, features)
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ type NodeTraverser interface {
|
||||
cb func(channel *DirectedChannel) error, reset func()) error
|
||||
|
||||
// FetchNodeFeatures returns the features of the given node.
|
||||
FetchNodeFeatures(nodePub route.Vertex) (*lnwire.FeatureVector, error)
|
||||
FetchNodeFeatures(ctx context.Context,
|
||||
nodePub route.Vertex) (*lnwire.FeatureVector, error)
|
||||
}
|
||||
|
||||
// Store represents the main interface for the channel graph database for all
|
||||
@@ -37,7 +38,7 @@ type Store interface { //nolint:interfacebloat
|
||||
cb func(channel *DirectedChannel) error, reset func()) error
|
||||
|
||||
// FetchNodeFeatures returns the features of the given node.
|
||||
FetchNodeFeatures(v lnwire.GossipVersion,
|
||||
FetchNodeFeatures(ctx context.Context, v lnwire.GossipVersion,
|
||||
nodePub route.Vertex) (*lnwire.FeatureVector, error)
|
||||
|
||||
// AddNode adds a vertex/node to the graph database. If the
|
||||
|
||||
@@ -684,7 +684,7 @@ func (c *KVStore) ForEachNodeDirectedChannel(v lnwire.GossipVersion,
|
||||
// known for the node, an empty feature vector is returned.
|
||||
//
|
||||
// NOTE: this is part of the graphdb.NodeTraverser interface.
|
||||
func (c *KVStore) FetchNodeFeatures(v lnwire.GossipVersion,
|
||||
func (c *KVStore) FetchNodeFeatures(_ context.Context, v lnwire.GossipVersion,
|
||||
nodePub route.Vertex) (*lnwire.FeatureVector, error) {
|
||||
|
||||
if v != lnwire.GossipVersion1 {
|
||||
@@ -4511,7 +4511,8 @@ func (c *nodeTraverserSession) ForEachNodeDirectedChannel(
|
||||
// unknown, assume no additional features are supported.
|
||||
//
|
||||
// NOTE: Part of the NodeTraverser interface.
|
||||
func (c *nodeTraverserSession) FetchNodeFeatures(nodePub route.Vertex) (
|
||||
func (c *nodeTraverserSession) FetchNodeFeatures(_ context.Context,
|
||||
nodePub route.Vertex) (
|
||||
*lnwire.FeatureVector, error) {
|
||||
|
||||
return c.db.fetchNodeFeatures(c.tx, nodePub)
|
||||
|
||||
@@ -447,10 +447,9 @@ func (s *SQLStore) DeleteNode(ctx context.Context, v lnwire.GossipVersion,
|
||||
// known for the node, an empty feature vector is returned.
|
||||
//
|
||||
// NOTE: this is part of the graphdb.NodeTraverser interface.
|
||||
func (s *SQLStore) FetchNodeFeatures(v lnwire.GossipVersion,
|
||||
nodePub route.Vertex) (*lnwire.FeatureVector, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
func (s *SQLStore) FetchNodeFeatures(ctx context.Context,
|
||||
v lnwire.GossipVersion, nodePub route.Vertex) (*lnwire.FeatureVector,
|
||||
error) {
|
||||
|
||||
return fetchNodeFeatures(ctx, s.db, v, nodePub)
|
||||
}
|
||||
@@ -3391,11 +3390,10 @@ func (s *sqlNodeTraverser) ForEachNodeDirectedChannel(
|
||||
// unknown, assume no additional features are supported.
|
||||
//
|
||||
// NOTE: Part of the NodeTraverser interface.
|
||||
func (s *sqlNodeTraverser) FetchNodeFeatures(nodePub route.Vertex) (
|
||||
func (s *sqlNodeTraverser) FetchNodeFeatures(ctx context.Context,
|
||||
nodePub route.Vertex) (
|
||||
*lnwire.FeatureVector, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
return fetchNodeFeatures(ctx, s.db, lnwire.GossipVersion1, nodePub)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user