What changed, and why it matters
This commit is a routine code cleanup: it removes an unused Go interface called DB from the graph package and replaces its one remaining use with a direct pointer to the concrete ChannelGraph type. There is no change to program logic, data handling, or security behavior.
No security action needed; review as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff deletes the graph.DB interface (about 180 lines) from graph/interfaces.go, changes graph/builder.go to use graphdb.ChannelGraph directly in Config, and updates routing/router_test.go’s newMockGraphBuilder to accept graphdb.ChannelGraph instead of graph.DB. No functional behavior is altered; this is a pure refactoring to remove indirection.
Changed components
graph/builder.gograph/interfaces.gorouting/router_test.goInspect captured patch +2 / −187
diff --git a/graph/builder.go b/graph/builder.go
index 59e9b19..91040dd 100644
--- a/graph/builder.go
+++ b/graph/builder.go
@@ -55,7 +55,7 @@ type Config struct {
// Graph is the channel graph that the ChannelRouter will use to gather
// metrics from and also to carry out path finding queries.
- Graph DB
+ Graph *graphdb.ChannelGraph
// Chain is the router's source to the most up-to-date blockchain data.
// All incoming advertised channels will be checked against the chain
diff --git a/graph/interfaces.go b/graph/interfaces.go
index 0896a08..75f4755 100644
--- a/graph/interfaces.go
+++ b/graph/interfaces.go
@@ -2,13 +2,9 @@ package graph
import (
"context"
- "iter"
"time"
- "github.com/btcsuite/btcd/chaincfg/chainhash"
- "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/batch"
- graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
@@ -96,183 +92,3 @@ type ChannelGraphSource interface {
// currently marked as a zombie edge.
IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error)
}
-
-// DB is an interface describing a persisted Lightning Network graph.
-//
-//nolint:interfacebloat
-type DB interface {
- // PruneTip returns the block height and hash of the latest block that
- // has been used to prune channels in the graph. Knowing the "prune tip"
- // allows callers to tell if the graph is currently in sync with the
- // current best known UTXO state.
- PruneTip() (*chainhash.Hash, uint32, error)
-
- // PruneGraph prunes newly closed channels from the channel graph in
- // response to a new block being solved on the network. Any transactions
- // which spend the funding output of any known channels within the graph
- // will be deleted. Additionally, the "prune tip", or the last block
- // which has been used to prune the graph is stored so callers can
- // ensure the graph is fully in sync with the current UTXO state. A
- // slice of channels that have been closed by the target block are
- // returned if the function succeeds without error.
- PruneGraph(spentOutputs []*wire.OutPoint, blockHash *chainhash.Hash,
- blockHeight uint32) ([]*models.ChannelEdgeInfo, error)
-
- // ChannelView returns the verifiable edge information for each active
- // channel within the known channel graph. The set of UTXO's (along with
- // their scripts) returned are the ones that need to be watched on
- // chain to detect channel closes on the resident blockchain.
- ChannelView() ([]graphdb.EdgePoint, error)
-
- // PruneGraphNodes is a garbage collection method which attempts to
- // prune out any nodes from the channel graph that are currently
- // unconnected. This ensure that we only maintain a graph of reachable
- // nodes. In the event that a pruned node gains more channels, it will
- // be re-added back to the graph.
- PruneGraphNodes() error
-
- // SourceNode returns the source node of the graph. The source node is
- // treated as the center node within a star-graph. This method may be
- // used to kick off a path finding algorithm in order to explore the
- // reachability of another node based off the source node.
- SourceNode(ctx context.Context) (*models.Node, error)
-
- // DisabledChannelIDs returns the channel ids of disabled channels.
- // A channel is disabled when two of the associated ChanelEdgePolicies
- // have their disabled bit on.
- DisabledChannelIDs() ([]uint64, error)
-
- // 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.
- FetchChanInfos(chanIDs []uint64) ([]graphdb.ChannelEdge, error)
-
- // ChanUpdatesInHorizon returns all the known channel edges which have
- // at least one edge that has an update timestamp within the specified
- // horizon.
- ChanUpdatesInHorizon(startTime, endTime time.Time,
- opts ...graphdb.IteratorOption,
- ) iter.Seq2[graphdb.ChannelEdge, error]
-
- // DeleteChannelEdges removes edges with the given channel IDs from the
- // database and marks them as zombies. This ensures that we're unable to
- // re-add it to our database once again. If an edge does not exist
- // within the database, then ErrEdgeNotFound will be returned. If
- // strictZombiePruning is true, then when we mark these edges as
- // zombies, we'll set up the keys such that we require the node that
- // failed to send the fresh update to be the one that resurrects the
- // channel from its zombie state. The markZombie bool denotes whether
- // to mark the channel as a zombie.
- DeleteChannelEdges(strictZombiePruning, markZombie bool,
- chanIDs ...uint64) error
-
- // DisconnectBlockAtHeight is used to indicate that the block specified
- // by the passed height has been disconnected from the main chain. This
- // will "rewind" the graph back to the height below, deleting channels
- // that are no longer confirmed from the graph. The prune log will be
- // set to the last prune height valid for the remaining chain.
- // Channels that were removed from the graph resulting from the
- // disconnected block are returned.
- DisconnectBlockAtHeight(height uint32) ([]*models.ChannelEdgeInfo,
- error)
-
- // HasChannelEdge returns true if the database knows of a channel edge
- // with the passed channel ID, and false otherwise. If an edge with that
- // ID is found within the graph, then two time stamps representing the
- // last time the edge was updated for both directed edges are returned
- // along with the boolean. If it is not found, then the zombie index is
- // checked and its result is returned as the second boolean.
- HasChannelEdge(chanID uint64) (time.Time, time.Time, bool, bool, error)
-
- // FetchChannelEdgesByID attempts to lookup the two directed edges for
- // the channel identified by the channel ID. If the channel can't be
- // found, then ErrEdgeNotFound is returned. A struct which houses the
- // general information for the channel itself is returned as well as
- // two structs that contain the routing policies for the channel in
- // either direction.
- //
- // ErrZombieEdge an be returned if the edge is currently marked as a
- // zombie within the database. In this case, the ChannelEdgePolicy's
- // will be nil, and the ChannelEdgeInfo will only include the public
- // keys of each node.
- FetchChannelEdgesByID(chanID uint64) (*models.ChannelEdgeInfo,
- *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error)
-
- // AddNode adds a vertex/node to the graph database. If the
- // node is not in the database from before, this will add a new,
- // unconnected one to the graph. If it is present from before, this will
- // update that node's information. Note that this method is expected to
- // only be called to update an already present node from a node
- // announcement, or to insert a node found in a channel update.
- AddNode(ctx context.Context, node *models.Node,
- op ...batch.SchedulerOption) error
-
- // AddChannelEdge adds a new (undirected, blank) edge to the graph
- // database. An undirected edge from the two target nodes are created.
- // The information stored denotes the static attributes of the channel,
- // such as the channelID, the keys involved in creation of the channel,
- // and the set of features that the channel supports. The chanPoint and
- // chanID are used to uniquely identify the edge globally within the
- // database.
- AddChannelEdge(ctx context.Context, edge *models.ChannelEdgeInfo,
- op ...batch.SchedulerOption) error
-
- // MarkEdgeZombie attempts to mark a channel identified by its channel
- // ID as a zombie. This method is used on an ad-hoc basis, when channels
- // need to be marked as zombies outside the normal pruning cycle.
- MarkEdgeZombie(chanID uint64, pubKey1, pubKey2 [33]byte) error
-
- // UpdateEdgePolicy updates the edge routing policy for a single
- // directed edge within the database for the referenced channel. The
- // `flags` attribute within the ChannelEdgePolicy determines which of
- // the directed edges are being updated. If the flag is 1, then the
- // first node's information is being updated, otherwise it's the second
- // node's information. The node ordering is determined by the
- // lexicographical ordering of the identity public keys of the nodes on
- // either side of the channel.
- UpdateEdgePolicy(ctx context.Context, edge *models.ChannelEdgePolicy,
- op ...batch.SchedulerOption) error
-
- // HasNode determines if the graph has a vertex identified by
- // the target node identity public key. If the node exists in the
- // database, a timestamp of when the data for the node was lasted
- // updated is returned along with a true boolean. Otherwise, an empty
- // time.Time is returned with a false boolean.
- HasNode(ctx context.Context, nodePub [33]byte) (time.Time, bool, error)
-
- // FetchNode 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.
- FetchNode(ctx context.Context, nodePub route.Vertex) (*models.Node,
- error)
-
- // ForEachNodeChannel iterates through all channels of the given node,
- // executing the passed callback with an edge info structure and the
- // policies of each end of the channel. The first edge policy is the
- // outgoing edge *to* the connecting node, while the second is the
- // incoming edge *from* the connecting node. If the callback returns an
- // error, then the iteration is halted with the error propagated back up
- // to the caller.
- //
- // Unknown policies are passed into the callback as nil values.
- ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
- cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
- *models.ChannelEdgePolicy) error, reset func()) error
-
- // AddEdgeProof sets the proof of an existing edge in the graph
- // database.
- AddEdgeProof(chanID lnwire.ShortChannelID,
- proof *models.ChannelAuthProof) error
-
- // IsPublicNode is a helper method that determines whether the node with
- // the given public key is seen as a public node in the graph from the
- // graph's source node's point of view.
- IsPublicNode(pubKey [33]byte) (bool, error)
-
- // MarkEdgeLive clears an edge from our zombie index, deeming it as
- // live.
- MarkEdgeLive(chanID uint64) error
-}
diff --git a/routing/router_test.go b/routing/router_test.go
index d087e2d..9f08891 100644
--- a/routing/router_test.go
+++ b/routing/router_test.go
@@ -23,7 +23,6 @@ import (
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn/v2"
- "github.com/lightningnetwork/lnd/graph"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/htlcswitch"
@@ -2941,7 +2940,7 @@ type mockGraphBuilder struct {
updateEdge func(update *models.ChannelEdgePolicy) error
}
-func newMockGraphBuilder(graph graph.DB) *mockGraphBuilder {
+func newMockGraphBuilder(graph *graphdb.ChannelGraph) *mockGraphBuilder {
return &mockGraphBuilder{
updateEdge: func(update *models.ChannelEdgePolicy) error {
return graph.UpdateEdgePolicy(
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.