lncfg: add configuration for user specified db backend

This commit extends lncfg to support user specified database backend.
This supports configuration for both bolt and etcd (while only allowing
one or the other).
This commit is contained in:
Andras Banki-Horvath
2020-03-13 17:05:28 +01:00
parent 859a457e48
commit 9d57c1a6b4
3 changed files with 99 additions and 6 deletions

View File

@@ -248,6 +248,8 @@ type Config struct {
AllowCircularRoute bool `long:"allow-circular-route" description:"If true, our node will allow htlc forwards that arrive and depart on the same channel."`
DB *lncfg.DB `group:"db" namespace:"db"`
// registeredChains keeps track of all chains that have been registered
// with the daemon.
registeredChains *chainRegistry
@@ -358,6 +360,7 @@ func DefaultConfig() Config {
},
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
DB: lncfg.DefaultDB(),
registeredChains: newChainRegistry(),
}
}
@@ -1073,6 +1076,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
cfg.Workers,
cfg.Caches,
cfg.WtClient,
cfg.DB,
)
if err != nil {
return nil, err
@@ -1090,6 +1094,14 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
return &cfg, err
}
// localDatabaseDir returns the default directory where the
// local bolt db files are stored.
func (c *config) localDatabaseDir() string {
return filepath.Join(cfg.DataDir,
defaultGraphSubDirname,
normalizeNetwork(activeNetParams.Name))
}
// CleanAndExpandPath expands environment variables and leading ~ in the
// passed path, cleans the result, and returns it.
// This function is taken from https://github.com/btcsuite/btcd