graph: temporarily rename some ChannelGraph methods

Add the `Tx` suffix to both ForEachNodeDirectedChannelTx and
FetchNodeFeatures temporarily so that we free up the original names for
other use. The renamed methods will be removed or unexported in an
upcoming commit. The aim is to have no exported methods on the
ChannelGraph that accept a kvdb.RTx as a parameter.
This commit is contained in:
Elle Mouton 2025-02-12 17:18:40 +02:00
parent 9068ffcd8b
commit 971832c792
No known key found for this signature in database
GPG Key ID: D7D916376026F177
4 changed files with 16 additions and 16 deletions

View File

@ -500,7 +500,7 @@ func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
}, func() {})
}
// ForEachNodeDirectedChannel iterates through all channels of a given node,
// ForEachNodeDirectedChannelTx 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
@ -509,7 +509,7 @@ func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
// Unknown policies are passed into the callback as nil values.
//
// NOTE: this is part of the graphsession.graph interface.
func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
func (c *ChannelGraph) ForEachNodeDirectedChannelTx(tx kvdb.RTx,
node route.Vertex, cb func(channel *DirectedChannel) error) error {
if c.graphCache != nil {
@ -520,7 +520,7 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
toNodeCallback := func() route.Vertex {
return node
}
toNodeFeatures, err := c.FetchNodeFeatures(tx, node)
toNodeFeatures, err := c.FetchNodeFeaturesTx(tx, node)
if err != nil {
return err
}
@ -564,12 +564,12 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
return nodeTraversal(tx, node[:], c.db, dbCallback)
}
// FetchNodeFeatures returns the features of a given node. If no features are
// FetchNodeFeaturesTx 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) FetchNodeFeatures(tx kvdb.RTx,
func (c *ChannelGraph) FetchNodeFeaturesTx(tx kvdb.RTx,
node route.Vertex) (*lnwire.FeatureVector, error) {
if c.graphCache != nil {
@ -623,7 +623,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
toNodeCallback := func() route.Vertex {
return node.PubKeyBytes
}
toNodeFeatures, err := c.FetchNodeFeatures(
toNodeFeatures, err := c.FetchNodeFeaturesTx(
tx, node.PubKeyBytes,
)
if err != nil {

View File

@ -3915,7 +3915,7 @@ func BenchmarkForEachChannel(b *testing.B) {
}
}
// TestGraphCacheForEachNodeChannel tests that the ForEachNodeDirectedChannel
// TestGraphCacheForEachNodeChannel tests that the ForEachNodeDirectedChannelTx
// method works as expected, and is able to handle nil self edges.
func TestGraphCacheForEachNodeChannel(t *testing.T) {
graph, err := MakeTestGraph(t)
@ -3952,7 +3952,7 @@ func TestGraphCacheForEachNodeChannel(t *testing.T) {
getSingleChannel := func() *DirectedChannel {
var ch *DirectedChannel
err = graph.ForEachNodeDirectedChannel(nil, node1.PubKeyBytes,
err = graph.ForEachNodeDirectedChannelTx(nil, node1.PubKeyBytes,
func(c *DirectedChannel) error {
require.Nil(t, ch)
ch = c

View File

@ -86,7 +86,7 @@ func (g *session) close() error {
func (g *session) ForEachNodeChannel(nodePub route.Vertex,
cb func(channel *graphdb.DirectedChannel) error) error {
return g.graph.ForEachNodeDirectedChannel(g.tx, nodePub, cb)
return g.graph.ForEachNodeDirectedChannelTx(g.tx, nodePub, cb)
}
// FetchNodeFeatures returns the features of the given node. If the node is
@ -96,7 +96,7 @@ func (g *session) ForEachNodeChannel(nodePub route.Vertex,
func (g *session) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {
return g.graph.FetchNodeFeatures(g.tx, nodePub)
return g.graph.FetchNodeFeaturesTx(g.tx, nodePub)
}
// A compile-time check to ensure that *session implements the
@ -118,7 +118,7 @@ type ReadOnlyGraph interface {
// database implementation, like channeldb.ChannelGraph, in order to be used by
// the Router for pathfinding.
type graph interface {
// ForEachNodeDirectedChannel iterates through all channels of a given
// ForEachNodeDirectedChannelTx 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
@ -128,15 +128,15 @@ type graph interface {
//
// NOTE: if a nil tx is provided, then it is expected that the
// implementation create a read only tx.
ForEachNodeDirectedChannel(tx kvdb.RTx, node route.Vertex,
ForEachNodeDirectedChannelTx(tx kvdb.RTx, node route.Vertex,
cb func(channel *graphdb.DirectedChannel) error) error
// FetchNodeFeatures returns the features of a given node. If no
// FetchNodeFeaturesTx returns the features of a given node. If no
// features are known for the node, an empty feature vector is returned.
//
// NOTE: if a nil tx is provided, then it is expected that the
// implementation create a read only tx.
FetchNodeFeatures(tx kvdb.RTx, node route.Vertex) (
FetchNodeFeaturesTx(tx kvdb.RTx, node route.Vertex) (
*lnwire.FeatureVector, error)
}

View File

@ -394,11 +394,11 @@ func (g *mockGraphSessionChanDB) close() error {
func (g *mockGraphSessionChanDB) ForEachNodeChannel(nodePub route.Vertex,
cb func(channel *graphdb.DirectedChannel) error) error {
return g.graph.ForEachNodeDirectedChannel(g.tx, nodePub, cb)
return g.graph.ForEachNodeDirectedChannelTx(g.tx, nodePub, cb)
}
func (g *mockGraphSessionChanDB) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {
return g.graph.FetchNodeFeatures(g.tx, nodePub)
return g.graph.FetchNodeFeaturesTx(g.tx, nodePub)
}