graph/db: init KVStore outside of ChannelGraph

So that we can pass in the abstract V1Store in preparation for adding a
SQL implementation of the KVStore.
This commit is contained in:
Elle Mouton committed 2025-05-22 14:14:40 +02:00
1 parent 449684de87
commit 526fb7f181
8 files changed
+36 -39

No files matched your search

+4 -1
View File
@@ -47,7 +47,10 @@ func newDiskChanGraph(t *testing.T) (testGraph, error) {
}) })
require.NoError(t, err) require.NoError(t, err)
graphDB, err := graphdb.NewChannelGraph(&graphdb.Config{KVDB: backend}) graphStore, err := graphdb.NewKVStore(backend)
require.NoError(t, err)
graphDB, err := graphdb.NewChannelGraph(graphStore)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, graphDB.Start()) require.NoError(t, graphDB.Start())
+8 -4
View File
@@ -1046,10 +1046,14 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
) )
} }
dbs.GraphDB, err = graphdb.NewChannelGraph(&graphdb.Config{ graphStore, err := graphdb.NewKVStore(
KVDB: databaseBackends.GraphDB, databaseBackends.GraphDB, graphDBOptions...,
KVStoreOpts: graphDBOptions, )
}, chanGraphOpts...) if err != nil {
return nil, nil, err
}
dbs.GraphDB, err = graphdb.NewChannelGraph(graphStore, chanGraphOpts...)
if err != nil { if err != nil {
cleanUp() cleanUp()
+3 -21
View File
@@ -11,7 +11,6 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/batch" "github.com/lightningnetwork/lnd/batch"
"github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
) )
@@ -20,18 +19,6 @@ import (
// busy shutting down. // busy shutting down.
var ErrChanGraphShuttingDown = fmt.Errorf("ChannelGraph shutting down") var ErrChanGraphShuttingDown = fmt.Errorf("ChannelGraph shutting down")
// Config is a struct that holds all the necessary dependencies for a
// ChannelGraph.
type Config struct {
// KVDB is the kvdb.Backend that will be used for initializing the
// KVStore CRUD layer.
KVDB kvdb.Backend
// KVStoreOpts is a list of functional options that will be used when
// initializing the KVStore.
KVStoreOpts []KVStoreOptionModifier
}
// ChannelGraph is a layer above the graph's CRUD layer. // ChannelGraph is a layer above the graph's CRUD layer.
// //
// NOTE: currently, this is purely a pass-through layer directly to the backing // NOTE: currently, this is purely a pass-through layer directly to the backing
@@ -51,21 +38,16 @@ type ChannelGraph struct {
} }
// NewChannelGraph creates a new ChannelGraph instance with the given backend. // NewChannelGraph creates a new ChannelGraph instance with the given backend.
func NewChannelGraph(cfg *Config, options ...ChanGraphOption) (*ChannelGraph, func NewChannelGraph(v1Store V1Store,
error) { options ...ChanGraphOption) (*ChannelGraph, error) {
opts := defaultChanGraphOptions() opts := defaultChanGraphOptions()
for _, o := range options { for _, o := range options {
o(opts) o(opts)
} }
store, err := NewKVStore(cfg.KVDB, cfg.KVStoreOpts...)
if err != nil {
return nil, err
}
g := &ChannelGraph{ g := &ChannelGraph{
V1Store: store, V1Store: v1Store,
topologyManager: newTopologyManager(), topologyManager: newTopologyManager(),
quit: make(chan struct{}), quit: make(chan struct{}),
} }
+5 -2
View File
@@ -4084,7 +4084,10 @@ func TestGraphLoading(t *testing.T) {
defer backend.Close() defer backend.Close()
defer backendCleanup() defer backendCleanup()
graph, err := NewChannelGraph(&Config{KVDB: backend}) graphStore, err := NewKVStore(backend)
require.NoError(t, err)
graph, err := NewChannelGraph(graphStore)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, graph.Start()) require.NoError(t, graph.Start())
t.Cleanup(func() { t.Cleanup(func() {
@@ -4098,7 +4101,7 @@ func TestGraphLoading(t *testing.T) {
// Recreate the graph. This should cause the graph cache to be // Recreate the graph. This should cause the graph cache to be
// populated. // populated.
graphReloaded, err := NewChannelGraph(&Config{KVDB: backend}) graphReloaded, err := NewChannelGraph(graphStore)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, graphReloaded.Start()) require.NoError(t, graphReloaded.Start())
t.Cleanup(func() { t.Cleanup(func() {
+4 -4
View File
@@ -4725,10 +4725,10 @@ func MakeTestGraph(t testing.TB, modifiers ...KVStoreOptionModifier) (
return nil, err return nil, err
} }
graph, err := NewChannelGraph(&Config{ graphStore, err := NewKVStore(backend, modifiers...)
KVDB: backend, require.NoError(t, err)
KVStoreOpts: modifiers,
}) graph, err := NewChannelGraph(graphStore)
if err != nil { if err != nil {
backendCleanup() backendCleanup()
+4 -2
View File
@@ -1093,9 +1093,11 @@ func makeTestGraph(t *testing.T, useCache bool) *graphdb.ChannelGraph {
t.Cleanup(backendCleanup) t.Cleanup(backendCleanup)
graphStore, err := graphdb.NewKVStore(backend)
require.NoError(t, err)
graph, err := graphdb.NewChannelGraph( graph, err := graphdb.NewChannelGraph(
&graphdb.Config{KVDB: backend}, graphStore, graphdb.WithUseGraphCache(useCache),
graphdb.WithUseGraphCache(useCache),
) )
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, graph.Start()) require.NoError(t, graph.Start())
+4 -3
View File
@@ -615,9 +615,10 @@ func createTestPeer(t *testing.T) *peerTestCtx {
}) })
require.NoError(t, err) require.NoError(t, err)
dbAliceGraph, err := graphdb.NewChannelGraph(&graphdb.Config{ graphStore, err := graphdb.NewKVStore(graphBackend)
KVDB: graphBackend, require.NoError(t, err)
})
dbAliceGraph, err := graphdb.NewChannelGraph(graphStore)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, dbAliceGraph.Start()) require.NoError(t, dbAliceGraph.Start())
t.Cleanup(func() { t.Cleanup(func() {
+4 -2
View File
@@ -166,9 +166,11 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
t.Cleanup(backendCleanup) t.Cleanup(backendCleanup)
graphStore, err := graphdb.NewKVStore(backend)
require.NoError(t, err)
graph, err := graphdb.NewChannelGraph( graph, err := graphdb.NewChannelGraph(
&graphdb.Config{KVDB: backend}, graphStore, graphdb.WithUseGraphCache(useCache),
graphdb.WithUseGraphCache(useCache),
) )
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err