multi: add ChannelGraph Config struct
And use this struct to pass NewChannelGraph anything it needs to be able to init the KVStore that it houses. This will allow us to add ChannelGraph specific options.
This commit is contained in:
8 files changed
+40
-18
No files matched your search
@@ -46,7 +46,7 @@ func newDiskChanGraph(t *testing.T) (testGraph, error) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
graphDB, err := graphdb.NewChannelGraph(backend)
|
graphDB, err := graphdb.NewChannelGraph(&graphdb.Config{KVDB: backend})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
return &testDBGraph{
|
return &testDBGraph{
|
||||||
|
|||||||
+4
-3
@@ -1043,9 +1043,10 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbs.GraphDB, err = graphdb.NewChannelGraph(
|
dbs.GraphDB, err = graphdb.NewChannelGraph(&graphdb.Config{
|
||||||
databaseBackends.GraphDB, graphDBOptions...,
|
KVDB: databaseBackends.GraphDB,
|
||||||
)
|
KVStoreOpts: graphDBOptions,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cleanUp()
|
cleanUp()
|
||||||
|
|
||||||
|
|||||||
+14
-4
@@ -2,6 +2,18 @@ package graphdb
|
|||||||
|
|
||||||
import "github.com/lightningnetwork/lnd/kvdb"
|
import "github.com/lightningnetwork/lnd/kvdb"
|
||||||
|
|
||||||
|
// 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
|
||||||
@@ -12,10 +24,8 @@ 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(db kvdb.Backend, options ...KVStoreOptionModifier) (
|
func NewChannelGraph(cfg *Config) (*ChannelGraph, error) {
|
||||||
*ChannelGraph, error) {
|
store, err := NewKVStore(cfg.KVDB, cfg.KVStoreOpts...)
|
||||||
|
|
||||||
store, err := NewKVStore(db, options...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4005,7 +4005,7 @@ func TestGraphLoading(t *testing.T) {
|
|||||||
defer backend.Close()
|
defer backend.Close()
|
||||||
defer backendCleanup()
|
defer backendCleanup()
|
||||||
|
|
||||||
graph, err := NewChannelGraph(backend)
|
graph, err := NewChannelGraph(&Config{KVDB: backend})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Populate the graph with test data.
|
// Populate the graph with test data.
|
||||||
@@ -4015,7 +4015,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(backend)
|
graphReloaded, err := NewChannelGraph(&Config{KVDB: backend})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Assert that the cache content is identical.
|
// Assert that the cache content is identical.
|
||||||
|
|||||||
@@ -4843,7 +4843,10 @@ func MakeTestGraph(t testing.TB, modifiers ...KVStoreOptionModifier) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
graph, err := NewChannelGraph(backend)
|
graph, err := NewChannelGraph(&Config{
|
||||||
|
KVDB: backend,
|
||||||
|
KVStoreOpts: modifiers,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
backendCleanup()
|
backendCleanup()
|
||||||
|
|
||||||
|
|||||||
@@ -1093,9 +1093,12 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
|||||||
|
|
||||||
t.Cleanup(backendCleanup)
|
t.Cleanup(backendCleanup)
|
||||||
|
|
||||||
graph, err := graphdb.NewChannelGraph(
|
graph, err := graphdb.NewChannelGraph(&graphdb.Config{
|
||||||
backend, graphdb.WithUseGraphCache(useCache),
|
KVDB: backend,
|
||||||
)
|
KVStoreOpts: []graphdb.KVStoreOptionModifier{
|
||||||
|
graphdb.WithUseGraphCache(useCache),
|
||||||
|
},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -615,7 +615,9 @@ func createTestPeer(t *testing.T) *peerTestCtx {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dbAliceGraph, err := graphdb.NewChannelGraph(graphBackend)
|
dbAliceGraph, err := graphdb.NewChannelGraph(&graphdb.Config{
|
||||||
|
KVDB: graphBackend,
|
||||||
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dbAliceChannel := channeldb.OpenForTesting(t, dbPath)
|
dbAliceChannel := channeldb.OpenForTesting(t, dbPath)
|
||||||
|
|||||||
@@ -166,9 +166,12 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
|||||||
|
|
||||||
t.Cleanup(backendCleanup)
|
t.Cleanup(backendCleanup)
|
||||||
|
|
||||||
graph, err := graphdb.NewChannelGraph(
|
graph, err := graphdb.NewChannelGraph(&graphdb.Config{
|
||||||
backend, graphdb.WithUseGraphCache(useCache),
|
KVDB: backend,
|
||||||
)
|
KVStoreOpts: []graphdb.KVStoreOptionModifier{
|
||||||
|
graphdb.WithUseGraphCache(useCache),
|
||||||
|
},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user