channeldb+lnd: make channeldb backend configurable

This commit adds support for user configured channeldb backend.
This commit is contained in:
Andras Banki-Horvath 2020-03-13 17:06:58 +01:00
parent 9d57c1a6b4
commit 0e3629e2c7
3 changed files with 11 additions and 6 deletions

@ -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))
}

10
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),

@ -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,