From f3805002ff8ff0f8f9a6e978c9eab8e996ae57dc Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 13 Feb 2025 09:47:16 +0200 Subject: [PATCH] graph/db: unexport methods that take a transaction Unexport and rename the methods that were previously used by the graphsession package. --- docs/release-notes/release-notes-0.19.0.md | 5 ++++- graph/db/graph.go | 24 +++++++++------------- graph/db/graph_test.go | 4 ++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index acd47780b..b664800fd 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -248,13 +248,16 @@ The underlying functionality between those two options remain the same. * Graph abstraction work: - [Abstract autopilot access](https://github.com/lightningnetwork/lnd/pull/9480) - [Abstract invoicerpc server access](https://github.com/lightningnetwork/lnd/pull/9516) + - [Refactor to hide DB transactions](https://github.com/lightningnetwork/lnd/pull/9513) + +* [Golang was updated to + `v1.22.11`](https://github.com/lightningnetwork/lnd/pull/9462). * Move funding transaction validation to the gossiper [1](https://github.com/lightningnetwork/lnd/pull/9476) [2](https://github.com/lightningnetwork/lnd/pull/9477) [3](https://github.com/lightningnetwork/lnd/pull/9478). - ## Breaking Changes ## Performance Improvements diff --git a/graph/db/graph.go b/graph/db/graph.go index 315651a0d..8ee9e86fd 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -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 { @@ -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 } @@ -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 { @@ -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 @@ -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 @@ -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 { @@ -3942,7 +3938,7 @@ type nodeTraverserSession struct { func (c *nodeTraverserSession) 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 @@ -3952,7 +3948,7 @@ func (c *nodeTraverserSession) ForEachNodeDirectedChannel(nodePub route.Vertex, func (c *nodeTraverserSession) 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 diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index b4731fbd8..62b9cd4e1 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -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) @@ -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