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

View File

@ -1096,8 +1096,8 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// localDatabaseDir returns the default directory where the // localDatabaseDir returns the default directory where the
// local bolt db files are stored. // local bolt db files are stored.
func (c *config) localDatabaseDir() string { func (c *Config) localDatabaseDir() string {
return filepath.Join(cfg.DataDir, return filepath.Join(c.DataDir,
defaultGraphSubDirname, defaultGraphSubDirname,
normalizeNetwork(activeNetParams.Name)) normalizeNetwork(activeNetParams.Name))
} }

10
lnd.go
View File

@ -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 " + ltndLog.Infof("Opening the main database, this might take a few " +
"minutes...") "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 // Open the channeldb, which is dedicated to storing channel, and
// network related metadata. // network related metadata.
startOpenTime := time.Now() startOpenTime := time.Now()
chanDB, err := channeldb.Open( chanDB, err := channeldb.CreateWithBackend(
cfg.localDatabaseDir(), chanDbBackend,
channeldb.OptionSetRejectCacheSize(cfg.Caches.RejectCacheSize), channeldb.OptionSetRejectCacheSize(cfg.Caches.RejectCacheSize),
channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize), channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize),
channeldb.OptionSetSyncFreelist(cfg.SyncFreelist), channeldb.OptionSetSyncFreelist(cfg.SyncFreelist),

View File

@ -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 // Initialize the sphinx router, placing it's persistent replay log in
// the same directory as the channel graph database. // the same directory as the channel graph database.
graphDir := chanDB.Path() sharedSecretPath := filepath.Join(cfg.localDatabaseDir(), "sphinxreplay.db")
sharedSecretPath := filepath.Join(graphDir, "sphinxreplay.db")
replayLog := htlcswitch.NewDecayedLog(sharedSecretPath, cc.chainNotifier) replayLog := htlcswitch.NewDecayedLog(sharedSecretPath, cc.chainNotifier)
sphinxRouter := sphinx.NewRouter( sphinxRouter := sphinx.NewRouter(
nodeKeyECDH, activeNetParams.Params, replayLog, nodeKeyECDH, activeNetParams.Params, replayLog,