mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
lnd+channeldb: add graph cache option to channeldb
With this commit we forward the config option for disabling the channel graph cache as a boolean to the channeldb. But we invert its meaning to make the flag easier to understand.
This commit is contained in:
parent
a2ad533136
commit
f216da32f3
@ -291,6 +291,7 @@ func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
|
||||
chanDB.graph, err = NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
opts.UseGraphCache,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -188,8 +188,8 @@ type ChannelGraph struct {
|
||||
// NewChannelGraph allocates a new ChannelGraph backed by a DB instance. The
|
||||
// returned instance has its own unique reject cache and channel cache.
|
||||
func NewChannelGraph(db kvdb.Backend, rejectCacheSize, chanCacheSize int,
|
||||
batchCommitInterval time.Duration,
|
||||
preAllocCacheNumNodes int) (*ChannelGraph, error) {
|
||||
batchCommitInterval time.Duration, preAllocCacheNumNodes int,
|
||||
useGraphCache bool) (*ChannelGraph, error) {
|
||||
|
||||
if err := initChannelGraph(db); err != nil {
|
||||
return nil, err
|
||||
|
@ -77,6 +77,7 @@ func MakeTestGraph(modifiers ...OptionModifier) (*ChannelGraph, func(), error) {
|
||||
graph, err := NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
backendCleanup()
|
||||
|
@ -45,6 +45,11 @@ type Options struct {
|
||||
// graph cache, so we can pre-allocate the map accordingly.
|
||||
PreAllocCacheNumNodes int
|
||||
|
||||
// UseGraphCache denotes whether the in-memory graph cache should be
|
||||
// used or a fallback version that uses the underlying database for
|
||||
// path finding.
|
||||
UseGraphCache bool
|
||||
|
||||
// clock is the time source used by the database.
|
||||
clock clock.Clock
|
||||
|
||||
@ -65,6 +70,7 @@ func DefaultOptions() Options {
|
||||
RejectCacheSize: DefaultRejectCacheSize,
|
||||
ChannelCacheSize: DefaultChannelCacheSize,
|
||||
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
|
||||
UseGraphCache: true,
|
||||
clock: clock.NewDefaultClock(),
|
||||
}
|
||||
}
|
||||
@ -93,6 +99,13 @@ func OptionSetPreAllocCacheNumNodes(n int) OptionModifier {
|
||||
}
|
||||
}
|
||||
|
||||
// OptionSetUseGraphCache sets the UseGraphCache option to the given value.
|
||||
func OptionSetUseGraphCache(use bool) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.UseGraphCache = use
|
||||
}
|
||||
}
|
||||
|
||||
// OptionSetSyncFreelist allows the database to sync its freelist.
|
||||
func OptionSetSyncFreelist(b bool) OptionModifier {
|
||||
return func(o *Options) {
|
||||
|
@ -847,6 +847,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
|
||||
channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize),
|
||||
channeldb.OptionSetBatchCommitInterval(cfg.DB.BatchCommitInterval),
|
||||
channeldb.OptionDryRunMigration(cfg.DryRunMigration),
|
||||
channeldb.OptionSetUseGraphCache(!cfg.DB.NoGraphCache),
|
||||
}
|
||||
|
||||
// We want to pre-allocate the channel graph cache according to what we
|
||||
|
@ -173,6 +173,7 @@ func makeTestGraph() (*channeldb.ChannelGraph, kvdb.Backend, func(), error) {
|
||||
graph, err := channeldb.NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
cleanUp()
|
||||
|
Loading…
Reference in New Issue
Block a user