Skip to content

Commit 36d8bb2

Browse files
committed
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.
1 parent 9f79322 commit 36d8bb2

File tree

8 files changed

+36
-39
lines changed

8 files changed

+36
-39
lines changed

autopilot/prefattach_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ func newDiskChanGraph(t *testing.T) (testGraph, error) {
4747
})
4848
require.NoError(t, err)
4949

50-
graphDB, err := graphdb.NewChannelGraph(&graphdb.Config{KVDB: backend})
50+
graphStore, err := graphdb.NewKVStore(backend)
51+
require.NoError(t, err)
52+
53+
graphDB, err := graphdb.NewChannelGraph(graphStore)
5154
require.NoError(t, err)
5255

5356
require.NoError(t, graphDB.Start())

config_builder.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -1046,10 +1046,14 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
10461046
)
10471047
}
10481048

1049-
dbs.GraphDB, err = graphdb.NewChannelGraph(&graphdb.Config{
1050-
KVDB: databaseBackends.GraphDB,
1051-
KVStoreOpts: graphDBOptions,
1052-
}, chanGraphOpts...)
1049+
graphStore, err := graphdb.NewKVStore(
1050+
databaseBackends.GraphDB, graphDBOptions...,
1051+
)
1052+
if err != nil {
1053+
return nil, nil, err
1054+
}
1055+
1056+
dbs.GraphDB, err = graphdb.NewChannelGraph(graphStore, chanGraphOpts...)
10531057
if err != nil {
10541058
cleanUp()
10551059

graph/db/graph.go

+3-21
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/btcsuite/btcd/wire"
1212
"github.com/lightningnetwork/lnd/batch"
1313
"github.com/lightningnetwork/lnd/graph/db/models"
14-
"github.com/lightningnetwork/lnd/kvdb"
1514
"github.com/lightningnetwork/lnd/lnwire"
1615
"github.com/lightningnetwork/lnd/routing/route"
1716
)
@@ -20,18 +19,6 @@ import (
2019
// busy shutting down.
2120
var ErrChanGraphShuttingDown = fmt.Errorf("ChannelGraph shutting down")
2221

23-
// Config is a struct that holds all the necessary dependencies for a
24-
// ChannelGraph.
25-
type Config struct {
26-
// KVDB is the kvdb.Backend that will be used for initializing the
27-
// KVStore CRUD layer.
28-
KVDB kvdb.Backend
29-
30-
// KVStoreOpts is a list of functional options that will be used when
31-
// initializing the KVStore.
32-
KVStoreOpts []KVStoreOptionModifier
33-
}
34-
3522
// ChannelGraph is a layer above the graph's CRUD layer.
3623
//
3724
// NOTE: currently, this is purely a pass-through layer directly to the backing
@@ -56,21 +43,16 @@ type ChannelGraph struct {
5643
}
5744

5845
// NewChannelGraph creates a new ChannelGraph instance with the given backend.
59-
func NewChannelGraph(cfg *Config, options ...ChanGraphOption) (*ChannelGraph,
60-
error) {
46+
func NewChannelGraph(v1Store V1Store,
47+
options ...ChanGraphOption) (*ChannelGraph, error) {
6148

6249
opts := defaultChanGraphOptions()
6350
for _, o := range options {
6451
o(opts)
6552
}
6653

67-
store, err := NewKVStore(cfg.KVDB, cfg.KVStoreOpts...)
68-
if err != nil {
69-
return nil, err
70-
}
71-
7254
g := &ChannelGraph{
73-
V1Store: store,
55+
V1Store: v1Store,
7456
topologyManager: newTopologyManager(),
7557
quit: make(chan struct{}),
7658
}

graph/db/graph_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -4084,7 +4084,10 @@ func TestGraphLoading(t *testing.T) {
40844084
defer backend.Close()
40854085
defer backendCleanup()
40864086

4087-
graph, err := NewChannelGraph(&Config{KVDB: backend})
4087+
graphStore, err := NewKVStore(backend)
4088+
require.NoError(t, err)
4089+
4090+
graph, err := NewChannelGraph(graphStore)
40884091
require.NoError(t, err)
40894092
require.NoError(t, graph.Start())
40904093
t.Cleanup(func() {
@@ -4098,7 +4101,7 @@ func TestGraphLoading(t *testing.T) {
40984101

40994102
// Recreate the graph. This should cause the graph cache to be
41004103
// populated.
4101-
graphReloaded, err := NewChannelGraph(&Config{KVDB: backend})
4104+
graphReloaded, err := NewChannelGraph(graphStore)
41024105
require.NoError(t, err)
41034106
require.NoError(t, graphReloaded.Start())
41044107
t.Cleanup(func() {

graph/db/kv_store.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4725,10 +4725,10 @@ func MakeTestGraph(t testing.TB, modifiers ...KVStoreOptionModifier) (
47254725
return nil, err
47264726
}
47274727

4728-
graph, err := NewChannelGraph(&Config{
4729-
KVDB: backend,
4730-
KVStoreOpts: modifiers,
4731-
})
4728+
graphStore, err := NewKVStore(backend, modifiers...)
4729+
require.NoError(t, err)
4730+
4731+
graph, err := NewChannelGraph(graphStore)
47324732
if err != nil {
47334733
backendCleanup()
47344734

graph/notifications_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,11 @@ func makeTestGraph(t *testing.T, useCache bool) *graphdb.ChannelGraph {
10931093

10941094
t.Cleanup(backendCleanup)
10951095

1096+
graphStore, err := graphdb.NewKVStore(backend)
1097+
require.NoError(t, err)
1098+
10961099
graph, err := graphdb.NewChannelGraph(
1097-
&graphdb.Config{KVDB: backend},
1098-
graphdb.WithUseGraphCache(useCache),
1100+
graphStore, graphdb.WithUseGraphCache(useCache),
10991101
)
11001102
require.NoError(t, err)
11011103
require.NoError(t, graph.Start())

peer/test_utils.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,10 @@ func createTestPeer(t *testing.T) *peerTestCtx {
615615
})
616616
require.NoError(t, err)
617617

618-
dbAliceGraph, err := graphdb.NewChannelGraph(&graphdb.Config{
619-
KVDB: graphBackend,
620-
})
618+
graphStore, err := graphdb.NewKVStore(graphBackend)
619+
require.NoError(t, err)
620+
621+
dbAliceGraph, err := graphdb.NewChannelGraph(graphStore)
621622
require.NoError(t, err)
622623
require.NoError(t, dbAliceGraph.Start())
623624
t.Cleanup(func() {

routing/pathfind_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
166166

167167
t.Cleanup(backendCleanup)
168168

169+
graphStore, err := graphdb.NewKVStore(backend)
170+
require.NoError(t, err)
171+
169172
graph, err := graphdb.NewChannelGraph(
170-
&graphdb.Config{KVDB: backend},
171-
graphdb.WithUseGraphCache(useCache),
173+
graphStore, graphdb.WithUseGraphCache(useCache),
172174
)
173175
if err != nil {
174176
return nil, nil, err

0 commit comments

Comments
 (0)