lnd+lncfg: move normalizeNetwork to lncfg

This commit is contained in:
Eugene 2020-10-06 11:17:14 -07:00 committed by eugene
parent 4d238cfa2f
commit 46ef212de4
4 changed files with 17 additions and 18 deletions

@ -1048,7 +1048,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
cfg.networkDir = filepath.Join(
cfg.DataDir, defaultChainSubDirname,
cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(cfg.ActiveNetParams.Name),
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
)
// If a custom macaroon directory wasn't specified and the data
@ -1082,7 +1082,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// per network in the same fashion as the data directory.
cfg.LogDir = filepath.Join(cfg.LogDir,
cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(cfg.ActiveNetParams.Name))
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name))
// A log writer must be passed in, otherwise we can't function and would
// run into a panic later on.
@ -1280,11 +1280,11 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
func (c *Config) localDatabaseDir() string {
return filepath.Join(c.DataDir,
defaultGraphSubDirname,
normalizeNetwork(c.ActiveNetParams.Name))
lncfg.NormalizeNetwork(c.ActiveNetParams.Name))
}
func (c *Config) networkName() string {
return normalizeNetwork(c.ActiveNetParams.Name)
return lncfg.NormalizeNetwork(c.ActiveNetParams.Name)
}
// CleanAndExpandPath expands environment variables and leading ~ in the
@ -1619,13 +1619,3 @@ func checkEstimateMode(estimateMode string) error {
return fmt.Errorf("estimatemode must be one of the following: %v",
bitcoindEstimateModes[:])
}
// normalizeNetwork returns the common name of a network type used to create
// file paths. This allows differently versioned networks to use the same path.
func normalizeNetwork(network string) string {
if strings.HasPrefix(network, "testnet") {
return "testnet"
}
return network
}

@ -87,3 +87,13 @@ func CleanAndExpandPath(path string) string {
// but the variables can still be expanded via POSIX-style $VARIABLE.
return filepath.Clean(os.ExpandEnv(path))
}
// NormalizeNetwork returns the common name of a network type used to create
// file paths. This allows differently versioned networks to use the same path.
func NormalizeNetwork(network string) string {
if strings.HasPrefix(network, "testnet") {
return "testnet"
}
return network
}

5
lnd.go

@ -547,7 +547,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
towerDBDir := filepath.Join(
cfg.Watchtower.TowerDir,
cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(cfg.ActiveNetParams.Name),
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
)
towerDB, err := wtdb.OpenTowerDB(towerDBDir)
@ -1344,8 +1344,7 @@ func initNeutrinoBackend(cfg *Config, chainDir string) (*neutrino.ChainService,
// database if needed. We append the normalized network name here to
// match the behavior of btcwallet.
dbPath := filepath.Join(
chainDir,
normalizeNetwork(cfg.ActiveNetParams.Name),
chainDir, lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
)
// Ensure that the neutrino db path exists.

@ -2533,7 +2533,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
"with current best block in the main chain: %v", err)
}
network := normalizeNetwork(r.cfg.ActiveNetParams.Name)
network := lncfg.NormalizeNetwork(r.cfg.ActiveNetParams.Name)
activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains())
for i, chain := range r.cfg.registeredChains.ActiveChains() {
activeChains[i] = &lnrpc.Chain{