refactor: move graph related DB code to graph/db from channeldb

This is a pure refactor commit. It moves over all the graph related CRUD
code from `channeldb` to `graph/db`.
This commit is contained in:
Elle Mouton committed 2024-11-28 13:36:13 +02:00
1 parent 9f54ec90aa
commit 74a4b1922b
57 files changed
+512 -299

No files matched your search

+8 -7
View File
@@ -50,6 +50,7 @@ import (
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/graph"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
@@ -3037,7 +3038,7 @@ func createRPCCloseUpdate(
// abandonChanFromGraph attempts to remove a channel from the channel graph. If
// we can't find the chanID in the graph, then we assume it has already been
// removed, and will return a nop.
func abandonChanFromGraph(chanGraph *channeldb.ChannelGraph,
func abandonChanFromGraph(chanGraph *graphdb.ChannelGraph,
chanPoint *wire.OutPoint) error {
// First, we'll obtain the channel ID. If we can't locate this, then
@@ -3045,7 +3046,7 @@ func abandonChanFromGraph(chanGraph *channeldb.ChannelGraph,
// the graph, so we'll return a nil error.
chanID, err := chanGraph.ChannelID(chanPoint)
switch {
case errors.Is(err, channeldb.ErrEdgeNotFound):
case errors.Is(err, graphdb.ErrEdgeNotFound):
return nil
case err != nil:
return err
@@ -6532,7 +6533,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
// First iterate through all the known nodes (connected or unconnected
// within the graph), collating their current state into the RPC
// response.
err := graph.ForEachNode(func(_ kvdb.RTx, node *channeldb.LightningNode) error {
err := graph.ForEachNode(func(_ kvdb.RTx, node *graphdb.LightningNode) error {
lnNode := marshalNode(node)
resp.Nodes = append(resp.Nodes, lnNode)
@@ -6562,7 +6563,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
return nil
})
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
return nil, err
}
@@ -6808,7 +6809,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
// be returned.
node, err := graph.FetchLightningNode(pubKey)
switch {
case err == channeldb.ErrGraphNodeNotFound:
case err == graphdb.ErrGraphNodeNotFound:
return nil, status.Error(codes.NotFound, err.Error())
case err != nil:
return nil, err
@@ -6860,7 +6861,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
}, nil
}
func marshalNode(node *channeldb.LightningNode) *lnrpc.LightningNode {
func marshalNode(node *graphdb.LightningNode) *lnrpc.LightningNode {
nodeAddrs := make([]*lnrpc.NodeAddress, len(node.Addresses))
for i, addr := range node.Addresses {
nodeAddr := &lnrpc.NodeAddress{
@@ -6931,7 +6932,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
// each node so we can measure the graph diameter and degree stats
// below.
err := graph.ForEachNodeCached(func(node route.Vertex,
edges map[uint64]*channeldb.DirectedChannel) error {
edges map[uint64]*graphdb.DirectedChannel) error {
// Increment the total number of nodes with each iteration.
numNodes++