Skip to content

Commit 99c9440

Browse files
committed
graph/db: define a NodeTraverser interface
Which describes methods that will use the graph cache if it is available for fast read-only calls.
1 parent 8ec08fb commit 99c9440

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

graph/db/graph.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ func (c *ChannelGraph) FetchNodeFeaturesTx(tx kvdb.RTx,
602602
// of the database.
603603
//
604604
// Unknown policies are passed into the callback as nil values.
605+
//
606+
// NOTE: this is part of the graphdb.NodeTraverser interface.
605607
func (c *ChannelGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
606608
cb func(channel *DirectedChannel) error) error {
607609

@@ -612,6 +614,8 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
612614
// known for the node, an empty feature vector is returned.
613615
// If the graphCache is available, then it will be used to retrieve the node's
614616
// features instead of the database.
617+
//
618+
// NOTE: this is part of the graphdb.NodeTraverser interface.
615619
func (c *ChannelGraph) FetchNodeFeatures(nodePub route.Vertex) (
616620
*lnwire.FeatureVector, error) {
617621

graph/db/interfaces.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package graphdb
22

33
import (
44
"github.com/lightningnetwork/lnd/graph/db/models"
5+
"github.com/lightningnetwork/lnd/lnwire"
56
"github.com/lightningnetwork/lnd/routing/route"
67
)
78

@@ -23,3 +24,16 @@ type NodeRTx interface {
2324
// the same transaction.
2425
FetchNode(node route.Vertex) (NodeRTx, error)
2526
}
27+
28+
// NodeTraverser is an abstract read only interface that provides information
29+
// about nodes and their edges. The interface is about providing fast read-only
30+
// access to the graph and so if a cache is available, it should be used.
31+
type NodeTraverser interface {
32+
// ForEachNodeDirectedChannel calls the callback for every channel of
33+
// the given node.
34+
ForEachNodeDirectedChannel(nodePub route.Vertex,
35+
cb func(channel *DirectedChannel) error) error
36+
37+
// FetchNodeFeatures returns the features of the given node.
38+
FetchNodeFeatures(nodePub route.Vertex) (*lnwire.FeatureVector, error)
39+
}

0 commit comments

Comments
 (0)