diff --git a/config.go b/config.go index de339da5..128e92a5 100644 --- a/config.go +++ b/config.go @@ -768,24 +768,28 @@ func loadConfig() (*config, error) { // At this point, we'll save the base data directory in order to ensure // we don't store the macaroon database within any of the chain // namespaced directories. - macaroonDatabaseDir = cfg.DataDir + networkDir = filepath.Join( + cfg.DataDir, defaultChainSubDirname, + registeredChains.PrimaryChain().String(), + normalizeNetwork(activeNetParams.Name), + ) // If a custom macaroon directory wasn't specified and the data // directory has changed from the default path, then we'll also update // the path for the macaroons to be generated. if cfg.DataDir != defaultDataDir && cfg.AdminMacPath == defaultAdminMacPath { cfg.AdminMacPath = filepath.Join( - cfg.DataDir, defaultAdminMacFilename, + networkDir, defaultAdminMacFilename, ) } if cfg.DataDir != defaultDataDir && cfg.ReadMacPath == defaultReadMacPath { cfg.ReadMacPath = filepath.Join( - cfg.DataDir, defaultReadMacFilename, + networkDir, defaultReadMacFilename, ) } if cfg.DataDir != defaultDataDir && cfg.InvoiceMacPath == defaultInvoiceMacPath { cfg.InvoiceMacPath = filepath.Join( - cfg.DataDir, defaultInvoiceMacFilename, + networkDir, defaultInvoiceMacFilename, ) } diff --git a/lnd.go b/lnd.go index ac3df4bf..aea8689a 100644 --- a/lnd.go +++ b/lnd.go @@ -54,14 +54,17 @@ const ( ) var ( - //Commit stores the current commit hash of this build. This should be - //set using -ldflags during compilation. + // Commit stores the current commit hash of this build. This should be + // set using -ldflags during compilation. Commit string cfg *config registeredChains = newChainRegistry() - macaroonDatabaseDir string + // 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 // End of ASN.1 time. endOfTime = time.Date(2049, 12, 31, 23, 59, 59, 0, time.UTC) @@ -234,8 +237,9 @@ func lndMain() error { var macaroonService *macaroons.Service if !cfg.NoMacaroons { // Create the macaroon authentication/authorization service. - macaroonService, err = macaroons.NewService(macaroonDatabaseDir, - macaroons.IPLockChecker) + macaroonService, err = macaroons.NewService( + networkDir, macaroons.IPLockChecker, + ) if err != nil { srvrLog.Errorf("unable to create macaroon service: %v", err) return err @@ -708,7 +712,7 @@ func waitForWalletPassword(grpcEndpoints, restEndpoints []net.Addr, // deleted within it and recreated when successfully changing the // wallet's password. macaroonFiles := []string{ - filepath.Join(macaroonDatabaseDir, macaroons.DBFilename), + filepath.Join(networkDir, macaroons.DBFilename), cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath, } pwService := walletunlocker.New(