From d44f205e3f2bbdfc6d117b0ce25ca77111a87d37 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 14 May 2020 13:40:18 +0200 Subject: [PATCH] multi: move global networkDir to cfg --- config.go | 15 ++++++++++----- lnd.go | 9 ++------- rpcserver.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/config.go b/config.go index 05424661..3fe0059f 100644 --- a/config.go +++ b/config.go @@ -251,6 +251,11 @@ type Config struct { // registeredChains keeps track of all chains that have been registered // with the daemon. 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. @@ -881,7 +886,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) { // We'll now construct the network directory which will be where we // store all the data specific to this chain/network. - networkDir = filepath.Join( + cfg.networkDir = filepath.Join( cfg.DataDir, defaultChainSubDirname, cfg.registeredChains.PrimaryChain().String(), normalizeNetwork(activeNetParams.Name), @@ -892,17 +897,17 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) { // the path for the macaroons to be generated. if cfg.AdminMacPath == "" { cfg.AdminMacPath = filepath.Join( - networkDir, defaultAdminMacFilename, + cfg.networkDir, defaultAdminMacFilename, ) } if cfg.ReadMacPath == "" { cfg.ReadMacPath = filepath.Join( - networkDir, defaultReadMacFilename, + cfg.networkDir, defaultReadMacFilename, ) } if cfg.InvoiceMacPath == "" { 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. if cfg.BackupFilePath == "" { cfg.BackupFilePath = filepath.Join( - networkDir, chanbackup.DefaultBackupFileName, + cfg.networkDir, chanbackup.DefaultBackupFileName, ) } diff --git a/lnd.go b/lnd.go index b2b2f5d0..c6bd7b09 100644 --- a/lnd.go +++ b/lnd.go @@ -53,11 +53,6 @@ import ( var ( 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 @@ -428,7 +423,7 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro if !cfg.NoMacaroons { // Create the macaroon authentication/authorization service. macaroonService, err = macaroons.NewService( - networkDir, macaroons.IPLockChecker, + cfg.networkDir, macaroons.IPLockChecker, ) if err != nil { 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 // wallet's password. macaroonFiles := []string{ - filepath.Join(networkDir, macaroons.DBFilename), + filepath.Join(cfg.networkDir, macaroons.DBFilename), cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath, } pwService := walletunlocker.New( diff --git a/rpcserver.go b/rpcserver.go index d2879dc2..22c0561f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -585,7 +585,7 @@ func newRPCServer(s *server, macService *macaroons.Service, // the dependencies they need are properly populated within each sub // server configuration struct. err = subServerCgs.PopulateDependencies( - s.cc, networkDir, macService, atpl, invoiceRegistry, + s.cc, cfg.networkDir, macService, atpl, invoiceRegistry, s.htlcSwitch, activeNetParams.Params, s.chanRouter, routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower, s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures,