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)
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, graphDB.Start())
+8 -4
View File
@@ -1046,10 +1046,14 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
)
}
dbs.GraphDB, err = graphdb.NewChannelGraph(&graphdb.Config{
KVDB: databaseBackends.GraphDB,
KVStoreOpts: graphDBOptions,
}, chanGraphOpts...)
graphStore, err := graphdb.NewKVStore(
databaseBackends.GraphDB, graphDBOptions...,
)
if err != nil {
return nil, nil, err
}
dbs.GraphDB, err = graphdb.NewChannelGraph(graphStore, chanGraphOpts...)
if err != nil {
cleanUp()
+3 -21
View File
@@ -11,7 +11,6 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/batch"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)
@@ -20,18 +19,6 @@ import (
// busy 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.
//
// 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.
func NewChannelGraph(cfg *Config, options ...ChanGraphOption) (*ChannelGraph,
error) {
func NewChannelGraph(v1Store V1Store,
options ...ChanGraphOption) (*ChannelGraph, error) {
opts := defaultChanGraphOptions()
for _, o := range options {
o(opts)
}
store, err := NewKVStore(cfg.KVDB, cfg.KVStoreOpts...)
if err != nil {
return nil, err
}
g := &ChannelGraph{
V1Store: store,
V1Store: v1Store,
topologyManager: newTopologyManager(),
quit: make(chan struct{}),
}
+5 -2
View File
@@ -4084,7 +4084,10 @@ func TestGraphLoading(t *testing.T) {
defer backend.Close()
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, graph.Start())
t.Cleanup(func() {
@@ -4098,7 +4101,7 @@ func TestGraphLoading(t *testing.T) {
// Recreate the graph. This should cause the graph cache to be
// populated.
graphReloaded, err := NewChannelGraph(&Config{KVDB: backend})
graphReloaded, err := NewChannelGraph(graphStore)
require.NoError(t, err)
require.NoError(t, graphReloaded.Start())
t.Cleanup(func() {
+4 -4
View File
@@ -4725,10 +4725,10 @@ func MakeTestGraph(t testing.TB, modifiers ...KVStoreOptionModifier) (
return nil, err
}
graph, err := NewChannelGraph(&Config{
KVDB: backend,
KVStoreOpts: modifiers,
})
graphStore, err := NewKVStore(backend, modifiers...)
require.NoError(t, err)
graph, err := NewChannelGraph(graphStore)
if err != nil {
backendCleanup()
+4 -2
View File
@@ -1093,9 +1093,11 @@ func makeTestGraph(t *testing.T, useCache bool) *graphdb.ChannelGraph {
t.Cleanup(backendCleanup)
graphStore, err := graphdb.NewKVStore(backend)
require.NoError(t, err)
graph, err := graphdb.NewChannelGraph(
&graphdb.Config{KVDB: backend},
graphdb.WithUseGraphCache(useCache),
graphStore, graphdb.WithUseGraphCache(useCache),
)
require.NoError(t, err)
require.NoError(t, graph.Start())
+4 -3
View File
@@ -615,9 +615,10 @@ func createTestPeer(t *testing.T) *peerTestCtx {
})
require.NoError(t, err)
dbAliceGraph, err := graphdb.NewChannelGraph(&graphdb.Config{
KVDB: graphBackend,
})
graphStore, err := graphdb.NewKVStore(graphBackend)
require.NoError(t, err)
dbAliceGraph, err := graphdb.NewChannelGraph(graphStore)
require.NoError(t, err)
require.NoError(t, dbAliceGraph.Start())
t.Cleanup(func() {
+4 -2
View File
@@ -166,9 +166,11 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
t.Cleanup(backendCleanup)
graphStore, err := graphdb.NewKVStore(backend)
require.NoError(t, err)
graph, err := graphdb.NewChannelGraph(
&graphdb.Config{KVDB: backend},
graphdb.WithUseGraphCache(useCache),
graphStore, graphdb.WithUseGraphCache(useCache),
)
if err != nil {
return nil, nil, err