refactor: create FetchLightningNode with no tx param

In preparation for adding a clean Graph DB interface, we create a
version of FetchLightningNode that doesnt allow a caller to provide in a
transaction.
This commit is contained in:
Elle Mouton committed 2024-07-15 15:13:57 +02:00
1 parent 71e93526d6
commit c20d759d41
8 files changed
+39 -18

No files matched your search

+1 -1
View File
@@ -1351,7 +1351,7 @@ func (d *DB) AddrsForNode(nodePub *btcec.PublicKey) ([]net.Addr,
if err != nil {
return nil, err
}
graphNode, err := d.graph.FetchLightningNode(nil, pubKey)
graphNode, err := d.graph.FetchLightningNode(pubKey)
if err != nil && err != ErrGraphNodeNotFound {
return nil, err
} else if err == ErrGraphNodeNotFound {
+21 -2
View File
@@ -529,7 +529,7 @@ func (c *ChannelGraph) FetchNodeFeatures(
}
// Fallback that uses the database.
targetNode, err := c.FetchLightningNode(nil, node)
targetNode, err := c.FetchLightningNode(node)
switch err {
// If the node exists and has features, return them directly.
case nil:
@@ -2963,11 +2963,30 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
return nodeIsPublic, nil
}
// FetchLightningNodeTx attempts to look up a target node by its identity
// public 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) FetchLightningNodeTx(tx kvdb.RTx, nodePub route.Vertex) (
*LightningNode, error) {
return c.fetchLightningNode(tx, nodePub)
}
// FetchLightningNode attempts to look up a target node by its identity public
// key. If the node isn't found in the database, then ErrGraphNodeNotFound is
// returned.
func (c *ChannelGraph) FetchLightningNode(nodePub route.Vertex) (*LightningNode,
error) {
return c.fetchLightningNode(nil, nodePub)
}
// fetchLightningNode attempts to look up a target node by its identity public
// 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,
func (c *ChannelGraph) fetchLightningNode(tx kvdb.RTx,
nodePub route.Vertex) (*LightningNode, error) {
var node *LightningNode
+7 -7
View File
@@ -141,7 +141,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// Next, fetch the node from the database to ensure everything was
// serialized properly.
dbNode, err := graph.FetchLightningNode(nil, testPub)
dbNode, err := graph.FetchLightningNode(testPub)
require.NoError(t, err, "unable to locate node")
if _, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes); err != nil {
@@ -164,7 +164,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// Finally, attempt to fetch the node again. This should fail as the
// node should have been deleted from the database.
_, err = graph.FetchLightningNode(nil, testPub)
_, err = graph.FetchLightningNode(testPub)
if err != ErrGraphNodeNotFound {
t.Fatalf("fetch after delete should fail!")
}
@@ -192,7 +192,7 @@ func TestPartialNode(t *testing.T) {
// Next, fetch the node from the database to ensure everything was
// serialized properly.
dbNode, err := graph.FetchLightningNode(nil, testPub)
dbNode, err := graph.FetchLightningNode(testPub)
require.NoError(t, err, "unable to locate node")
if _, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes); err != nil {
@@ -222,7 +222,7 @@ func TestPartialNode(t *testing.T) {
// Finally, attempt to fetch the node again. This should fail as the
// node should have been deleted from the database.
_, err = graph.FetchLightningNode(nil, testPub)
_, err = graph.FetchLightningNode(testPub)
if err != ErrGraphNodeNotFound {
t.Fatalf("fetch after delete should fail!")
}
@@ -3014,7 +3014,7 @@ func TestPruneGraphNodes(t *testing.T) {
// Finally, we'll ensure that node3, the only fully unconnected node as
// properly deleted from the graph and not another node in its place.
_, err = graph.FetchLightningNode(nil, node3.PubKeyBytes)
_, err = graph.FetchLightningNode(node3.PubKeyBytes)
if err == nil {
t.Fatalf("node 3 should have been deleted!")
}
@@ -3048,13 +3048,13 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
// Ensure that node1 was inserted as a full node, while node2 only has
// a shell node present.
node1, err = graph.FetchLightningNode(nil, node1.PubKeyBytes)
node1, err = graph.FetchLightningNode(node1.PubKeyBytes)
require.NoError(t, err, "unable to fetch node1")
if !node1.HaveNodeAnnouncement {
t.Fatalf("have shell announcement for node1, shouldn't")
}
node2, err = graph.FetchLightningNode(nil, node2.PubKeyBytes)
node2, err = graph.FetchLightningNode(node2.PubKeyBytes)
require.NoError(t, err, "unable to fetch node2")
if node2.HaveNodeAnnouncement {
t.Fatalf("should have shell announcement for node2, but is full")