mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
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:
parent
71e93526d6
commit
c20d759d41
@ -105,7 +105,9 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
node, err := d.db.FetchLightningNode(tx, ep.ToNode)
|
||||
node, err := d.db.FetchLightningNodeTx(
|
||||
tx, ep.ToNode,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -164,7 +166,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dbNode, err := d.db.FetchLightningNode(nil, vertex)
|
||||
dbNode, err := d.db.FetchLightningNode(vertex)
|
||||
switch {
|
||||
case err == channeldb.ErrGraphNodeNotFound:
|
||||
fallthrough
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -2915,7 +2915,7 @@ func (r *ChannelRouter) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
func (r *ChannelRouter) FetchLightningNode(
|
||||
node route.Vertex) (*channeldb.LightningNode, error) {
|
||||
|
||||
return r.cfg.Graph.FetchLightningNode(nil, node)
|
||||
return r.cfg.Graph.FetchLightningNode(node)
|
||||
}
|
||||
|
||||
// ForEachNode is used to iterate over every node in router topology.
|
||||
|
@ -1596,14 +1596,14 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
||||
_, _, err = ctx.router.FindRoute(req)
|
||||
require.NoError(t, err, "unable to find any routes")
|
||||
|
||||
copy1, err := ctx.graph.FetchLightningNode(nil, pub1)
|
||||
copy1, err := ctx.graph.FetchLightningNode(pub1)
|
||||
require.NoError(t, err, "unable to fetch node")
|
||||
|
||||
if copy1.Alias != n1.Alias {
|
||||
t.Fatalf("fetched node not equal to original")
|
||||
}
|
||||
|
||||
copy2, err := ctx.graph.FetchLightningNode(nil, pub2)
|
||||
copy2, err := ctx.graph.FetchLightningNode(pub2)
|
||||
require.NoError(t, err, "unable to fetch node")
|
||||
|
||||
if copy2.Alias != n2.Alias {
|
||||
|
@ -6345,7 +6345,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
||||
// With the public key decoded, attempt to fetch the node corresponding
|
||||
// to this public key. If the node cannot be found, then an error will
|
||||
// be returned.
|
||||
node, err := graph.FetchLightningNode(nil, pubKey)
|
||||
node, err := graph.FetchLightningNode(pubKey)
|
||||
switch {
|
||||
case err == channeldb.ErrGraphNodeNotFound:
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
@ -7393,7 +7393,7 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context,
|
||||
return "", err
|
||||
}
|
||||
|
||||
peer, err := r.server.graphDB.FetchLightningNode(nil, vertex)
|
||||
peer, err := r.server.graphDB.FetchLightningNode(vertex)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user