config+lnd: create macaroons files under the network dir

Co-Authored-By: Karl Ranna <karl@karlranna.com>
This commit is contained in:
Wilmer Paulino 2018-08-22 15:27:16 -04:00 committed by Olaoluwa Osuntokun
parent 6ddae25487
commit 9981fd8fa7
2 changed files with 18 additions and 10 deletions

View File

@ -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,
)
}

16
lnd.go
View File

@ -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(