multi: move global networkDir to cfg

This commit is contained in:
Oliver Gugger 2020-05-14 13:40:18 +02:00
parent 85d5cdfbfd
commit d44f205e3f
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
3 changed files with 13 additions and 13 deletions

@ -251,6 +251,11 @@ type Config struct {
// registeredChains keeps track of all chains that have been registered // registeredChains keeps track of all chains that have been registered
// with the daemon. // with the daemon.
registeredChains *chainRegistry registeredChains *chainRegistry
// networkDir is the path to the directory of the currently active
// network. This path will hold the files related to each different
// network.
networkDir string
} }
// DefaultConfig returns all default values for the Config struct. // DefaultConfig returns all default values for the Config struct.
@ -881,7 +886,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// We'll now construct the network directory which will be where we // We'll now construct the network directory which will be where we
// store all the data specific to this chain/network. // store all the data specific to this chain/network.
networkDir = filepath.Join( cfg.networkDir = filepath.Join(
cfg.DataDir, defaultChainSubDirname, cfg.DataDir, defaultChainSubDirname,
cfg.registeredChains.PrimaryChain().String(), cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(activeNetParams.Name), normalizeNetwork(activeNetParams.Name),
@ -892,17 +897,17 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// the path for the macaroons to be generated. // the path for the macaroons to be generated.
if cfg.AdminMacPath == "" { if cfg.AdminMacPath == "" {
cfg.AdminMacPath = filepath.Join( cfg.AdminMacPath = filepath.Join(
networkDir, defaultAdminMacFilename, cfg.networkDir, defaultAdminMacFilename,
) )
} }
if cfg.ReadMacPath == "" { if cfg.ReadMacPath == "" {
cfg.ReadMacPath = filepath.Join( cfg.ReadMacPath = filepath.Join(
networkDir, defaultReadMacFilename, cfg.networkDir, defaultReadMacFilename,
) )
} }
if cfg.InvoiceMacPath == "" { if cfg.InvoiceMacPath == "" {
cfg.InvoiceMacPath = filepath.Join( cfg.InvoiceMacPath = filepath.Join(
networkDir, defaultInvoiceMacFilename, cfg.networkDir, defaultInvoiceMacFilename,
) )
} }
@ -910,7 +915,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// we'll update the file location to match our set network directory. // we'll update the file location to match our set network directory.
if cfg.BackupFilePath == "" { if cfg.BackupFilePath == "" {
cfg.BackupFilePath = filepath.Join( cfg.BackupFilePath = filepath.Join(
networkDir, chanbackup.DefaultBackupFileName, cfg.networkDir, chanbackup.DefaultBackupFileName,
) )
} }

9
lnd.go

@ -53,11 +53,6 @@ import (
var ( var (
cfg *Config cfg *Config
// networkDir is the path to the directory of the currently active
// network. This path will hold the files related to each different
// network.
networkDir string
) )
// WalletUnlockerAuthOptions returns a list of DialOptions that can be used to // WalletUnlockerAuthOptions returns a list of DialOptions that can be used to
@ -428,7 +423,7 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro
if !cfg.NoMacaroons { if !cfg.NoMacaroons {
// Create the macaroon authentication/authorization service. // Create the macaroon authentication/authorization service.
macaroonService, err = macaroons.NewService( macaroonService, err = macaroons.NewService(
networkDir, macaroons.IPLockChecker, cfg.networkDir, macaroons.IPLockChecker,
) )
if err != nil { if err != nil {
err := fmt.Errorf("unable to set up macaroon "+ err := fmt.Errorf("unable to set up macaroon "+
@ -1000,7 +995,7 @@ func waitForWalletPassword(restEndpoints []net.Addr,
// deleted within it and recreated when successfully changing the // deleted within it and recreated when successfully changing the
// wallet's password. // wallet's password.
macaroonFiles := []string{ macaroonFiles := []string{
filepath.Join(networkDir, macaroons.DBFilename), filepath.Join(cfg.networkDir, macaroons.DBFilename),
cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath, cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath,
} }
pwService := walletunlocker.New( pwService := walletunlocker.New(

@ -585,7 +585,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
// the dependencies they need are properly populated within each sub // the dependencies they need are properly populated within each sub
// server configuration struct. // server configuration struct.
err = subServerCgs.PopulateDependencies( err = subServerCgs.PopulateDependencies(
s.cc, networkDir, macService, atpl, invoiceRegistry, s.cc, cfg.networkDir, macService, atpl, invoiceRegistry,
s.htlcSwitch, activeNetParams.Params, s.chanRouter, s.htlcSwitch, activeNetParams.Params, s.chanRouter,
routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower, routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower,
s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures, s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures,