multi+refactor: let FetchChanInfos not take tx

In preparation for having a clean graph DB interface, refactor
FetchChanInfos so that no transaction can be provided.
This commit is contained in:
Elle Mouton committed 2024-07-15 15:13:57 +02:00
1 parent cf3de72503
commit 71e93526d6
4 files changed
+16 -7

No files matched your search

+13 -4
View File
@@ -2374,10 +2374,19 @@ func (c *ChannelGraph) FilterChannelRange(startHeight,
// skipped and the result will contain only those edges that exist at the time
// of the query. This can be used to respond to peer queries that are seeking to
// fill in gaps in their view of the channel graph.
func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
return c.fetchChanInfos(nil, chanIDs)
}
// fetchChanInfos returns the set of channel edges that correspond to the passed
// channel ID's. If an edge is the query is unknown to the database, it will
// skipped and the result will contain only those edges that exist at the time
// of the query. This can be used to respond to peer queries that are seeking to
// fill in gaps in their view of the channel graph.
//
// NOTE: An optional transaction may be provided. If none is provided, then a
// new one will be created.
func (c *ChannelGraph) FetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
func (c *ChannelGraph) fetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
[]ChannelEdge, error) {
// TODO(roasbeef): sort cids?
@@ -2958,8 +2967,8 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
// key. If the node isn't found in the database, then ErrGraphNodeNotFound is
// returned. An optional transaction may be provided. If none is provided, then
// a new one will be created.
func (c *ChannelGraph) FetchLightningNode(tx kvdb.RTx, nodePub route.Vertex) (
*LightningNode, error) {
func (c *ChannelGraph) FetchLightningNode(tx kvdb.RTx,
nodePub route.Vertex) (*LightningNode, error) {
var node *LightningNode
fetch := func(tx kvdb.RTx) error {
@@ -3705,7 +3714,7 @@ func (c *ChannelGraph) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
// We need to add the channel back into our graph cache, otherwise we
// won't use it for path finding.
if c.graphCache != nil {
edgeInfos, err := c.FetchChanInfos(tx, []uint64{chanID})
edgeInfos, err := c.fetchChanInfos(tx, []uint64{chanID})
if err != nil {
return err
}
+1 -1
View File
@@ -2685,7 +2685,7 @@ func TestFetchChanInfos(t *testing.T) {
// We'll now attempt to query for the range of channel ID's we just
// inserted into the database. We should get the exact same set of
// edges back.
resp, err := graph.FetchChanInfos(nil, edgeQuery)
resp, err := graph.FetchChanInfos(edgeQuery)
require.NoError(t, err, "unable to fetch chan edges")
if len(resp) != len(edges) {
t.Fatalf("expected %v edges, instead got %v", len(edges),