Skip to content

Commit

Permalink
graph/db: unexport methods that take a transaction
Browse files Browse the repository at this point in the history
Unexport and rename the methods that were previously used by the
graphsession package.
  • Loading branch information
ellemouton committed Feb 13, 2025
1 parent 7d02b53 commit b8e6507
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions graph/db/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,14 @@ func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
}, func() {})
}

// ForEachNodeDirectedChannelTx iterates through all channels of a given node,
// 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. An optional read
// transaction may be provided. If none is provided, a new one will be created.
//
// Unknown policies are passed into the callback as nil values.
//
// NOTE: this is part of the graphsession.graph interface.
func (c *ChannelGraph) ForEachNodeDirectedChannelTx(tx kvdb.RTx,
func (c *ChannelGraph) forEachNodeDirectedChannel(tx kvdb.RTx,
node route.Vertex, cb func(channel *DirectedChannel) error) error {

if c.graphCache != nil {
Expand All @@ -510,7 +508,7 @@ func (c *ChannelGraph) ForEachNodeDirectedChannelTx(tx kvdb.RTx,
toNodeCallback := func() route.Vertex {
return node
}
toNodeFeatures, err := c.FetchNodeFeaturesTx(tx, node)
toNodeFeatures, err := c.fetchNodeFeatures(tx, node)
if err != nil {
return err
}
Expand Down Expand Up @@ -554,12 +552,10 @@ func (c *ChannelGraph) ForEachNodeDirectedChannelTx(tx kvdb.RTx,
return nodeTraversal(tx, node[:], c.db, dbCallback)
}

// FetchNodeFeaturesTx returns the features of a given node. If no features are
// fetchNodeFeatures returns the features of a given node. If no features are
// known for the node, an empty feature vector is returned. An optional read
// transaction may be provided. If none is provided, a new one will be created.
//
// NOTE: this is part of the graphsession.graph interface.
func (c *ChannelGraph) FetchNodeFeaturesTx(tx kvdb.RTx,
func (c *ChannelGraph) fetchNodeFeatures(tx kvdb.RTx,
node route.Vertex) (*lnwire.FeatureVector, error) {

if c.graphCache != nil {
Expand Down Expand Up @@ -597,7 +593,7 @@ func (c *ChannelGraph) FetchNodeFeaturesTx(tx kvdb.RTx,
func (c *ChannelGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
cb func(channel *DirectedChannel) error) error {

return c.ForEachNodeDirectedChannelTx(nil, nodePub, cb)
return c.forEachNodeDirectedChannel(nil, nodePub, cb)
}

// FetchNodeFeatures returns the features of the given node. If no features are
Expand All @@ -609,7 +605,7 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
func (c *ChannelGraph) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {

return c.FetchNodeFeaturesTx(nil, nodePub)
return c.fetchNodeFeatures(nil, nodePub)
}

// ForEachNodeCached is similar to forEachNode, but it utilizes the channel
Expand Down Expand Up @@ -641,7 +637,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
toNodeCallback := func() route.Vertex {
return node.PubKeyBytes
}
toNodeFeatures, err := c.FetchNodeFeaturesTx(
toNodeFeatures, err := c.fetchNodeFeatures(
tx, node.PubKeyBytes,
)
if err != nil {
Expand Down Expand Up @@ -3942,7 +3938,7 @@ type cachedGraphSession struct {
func (c *cachedGraphSession) ForEachNodeDirectedChannel(nodePub route.Vertex,
cb func(channel *DirectedChannel) error) error {

return c.db.ForEachNodeDirectedChannelTx(c.tx, nodePub, cb)
return c.db.forEachNodeDirectedChannel(c.tx, nodePub, cb)
}

// FetchNodeFeatures returns the features of the given node. If the node is
Expand All @@ -3952,7 +3948,7 @@ func (c *cachedGraphSession) ForEachNodeDirectedChannel(nodePub route.Vertex,
func (c *cachedGraphSession) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {

return c.db.FetchNodeFeaturesTx(c.tx, nodePub)
return c.db.fetchNodeFeatures(c.tx, nodePub)
}

func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // nolint:dupl
Expand Down
4 changes: 2 additions & 2 deletions graph/db/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3915,7 +3915,7 @@ func BenchmarkForEachChannel(b *testing.B) {
}
}

// TestGraphCacheForEachNodeChannel tests that the ForEachNodeDirectedChannelTx
// TestGraphCacheForEachNodeChannel tests that the forEachNodeDirectedChannel
// method works as expected, and is able to handle nil self edges.
func TestGraphCacheForEachNodeChannel(t *testing.T) {
graph, err := MakeTestGraph(t)
Expand Down Expand Up @@ -3952,7 +3952,7 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) {

getSingleChannel := func() *DirectedChannel {
var ch *DirectedChannel
err = graph.ForEachNodeDirectedChannelTx(nil, node1.PubKeyBytes,
err = graph.forEachNodeDirectedChannel(nil, node1.PubKeyBytes,
func(c *DirectedChannel) error {
require.Nil(t, ch)
ch = c
Expand Down

0 comments on commit b8e6507

Please sign in to comment.