From 0e3629e2c705bdf0d89e8ae87cac9588eb503274 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Fri, 13 Mar 2020 17:06:58 +0100 Subject: [PATCH] channeldb+lnd: make channeldb backend configurable This commit adds support for user configured channeldb backend. --- config.go | 4 ++-- lnd.go | 10 ++++++++-- server.go | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 840f2765c..7e746989c 100644 --- a/config.go +++ b/config.go @@ -1096,8 +1096,8 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) { // localDatabaseDir returns the default directory where the // local bolt db files are stored. -func (c *config) localDatabaseDir() string { - return filepath.Join(cfg.DataDir, +func (c *Config) localDatabaseDir() string { + return filepath.Join(c.DataDir, defaultGraphSubDirname, normalizeNetwork(activeNetParams.Name)) } diff --git a/lnd.go b/lnd.go index 125990a28..f0a6e5e42 100644 --- a/lnd.go +++ b/lnd.go @@ -250,11 +250,17 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { ltndLog.Infof("Opening the main database, this might take a few " + "minutes...") + chanDbBackend, err := cfg.DB.GetBackend(cfg.localDatabaseDir()) + if err != nil { + ltndLog.Error(err) + return err + } + // Open the channeldb, which is dedicated to storing channel, and // network related metadata. startOpenTime := time.Now() - chanDB, err := channeldb.Open( - cfg.localDatabaseDir(), + chanDB, err := channeldb.CreateWithBackend( + chanDbBackend, channeldb.OptionSetRejectCacheSize(cfg.Caches.RejectCacheSize), channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize), channeldb.OptionSetSyncFreelist(cfg.SyncFreelist), diff --git a/server.go b/server.go index b0f00c5a4..1f3b196fb 100644 --- a/server.go +++ b/server.go @@ -377,8 +377,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, chanDB *channeldb.DB, // Initialize the sphinx router, placing it's persistent replay log in // the same directory as the channel graph database. - graphDir := chanDB.Path() - sharedSecretPath := filepath.Join(graphDir, "sphinxreplay.db") + sharedSecretPath := filepath.Join(cfg.localDatabaseDir(), "sphinxreplay.db") replayLog := htlcswitch.NewDecayedLog(sharedSecretPath, cc.chainNotifier) sphinxRouter := sphinx.NewRouter( nodeKeyECDH, activeNetParams.Params, replayLog,