diff --git a/channeldb/db.go b/channeldb/db.go index fed6dfa0..eace4997 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -114,7 +114,7 @@ type DB struct { // Open opens an existing channeldb. Any necessary schemas migrations due to // updates will take place as necessary. -func Open(dbPath string) (*DB, error) { +func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) { path := filepath.Join(dbPath, dbName) if !fileExists(path) { @@ -123,6 +123,11 @@ func Open(dbPath string) (*DB, error) { } } + opts := DefaultOptions() + for _, modifier := range modifiers { + modifier(&opts) + } + bdb, err := bbolt.Open(path, dbFilePermission, nil) if err != nil { return nil, err @@ -132,7 +137,9 @@ func Open(dbPath string) (*DB, error) { DB: bdb, dbPath: dbPath, } - chanDB.graph = newChannelGraph(chanDB) + chanDB.graph = newChannelGraph( + chanDB, opts.RejectCacheSize, opts.ChannelCacheSize, + ) // Synchronize the version of database and apply migrations if needed. if err := chanDB.syncVersions(dbVersions); err != nil { diff --git a/channeldb/graph.go b/channeldb/graph.go index 207e332e..4815a647 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -165,11 +165,11 @@ 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 *DB) *ChannelGraph { +func newChannelGraph(db *DB, rejectCacheSize, chanCacheSize int) *ChannelGraph { return &ChannelGraph{ db: db, - rejectCache: newRejectCache(50000), - chanCache: newChannelCache(20000), + rejectCache: newRejectCache(rejectCacheSize), + chanCache: newChannelCache(chanCacheSize), } }