diff --git a/config.go b/config.go index 7bce9cc5..50ad9942 100644 --- a/config.go +++ b/config.go @@ -38,6 +38,7 @@ const ( ) var ( + // TODO(roasbeef): base off of datadir instead? lndHomeDir = btcutil.AppDataDir("lnd", false) defaultConfigFile = filepath.Join(lndHomeDir, defaultConfigFilename) defaultDataDir = filepath.Join(lndHomeDir, defaultDataDirname) @@ -310,6 +311,21 @@ 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 + + // 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) + } + if cfg.DataDir != defaultDataDir && cfg.ReadMacPath == defaultReadMacPath { + cfg.ReadMacPath = filepath.Join(cfg.DataDir, defaultReadMacFilename) + } + // Append the network type to the data directory so it is "namespaced" // per network. In addition to the block database, there are other // pieces of data that are saved to disk such as address manager state. diff --git a/lnd.go b/lnd.go index 2b490381..485bf97d 100644 --- a/lnd.go +++ b/lnd.go @@ -49,6 +49,8 @@ var ( shutdownChannel = make(chan struct{}) registeredChains = newChainRegistry() + macaroonDatabaseDir string + // End of ASN.1 time. endOfTime = time.Date(2049, 12, 31, 23, 59, 59, 0, time.UTC) @@ -100,16 +102,14 @@ func lndMain() error { var macaroonService *bakery.Service if !cfg.NoMacaroons { // Create the macaroon authentication/authorization service. - macaroonService, err = macaroons.NewService(cfg.DataDir) + macaroonService, err = macaroons.NewService(macaroonDatabaseDir) if err != nil { - srvrLog.Errorf("unable to create macaroon service: %v", - err) + srvrLog.Errorf("unable to create macaroon service: %v", err) return err } // Create macaroon files for lncli to use if they don't exist. - if !fileExists(cfg.AdminMacPath) && - !fileExists(cfg.ReadMacPath) { + if !fileExists(cfg.AdminMacPath) && !fileExists(cfg.ReadMacPath) { err = genMacaroons(macaroonService, cfg.AdminMacPath, cfg.ReadMacPath) if err != nil { @@ -121,7 +121,7 @@ func lndMain() error { } // With the information parsed from the configuration, create valid - // instances of the paertinent interfaces required to operate the + // instances of the pertinent interfaces required to operate the // Lightning Network Daemon. activeChainControl, chainCleanUp, err := newChainControlFromConfig(cfg, chanDB) if err != nil { @@ -183,7 +183,7 @@ func lndMain() error { return server.genNodeAnnouncement(true) }, SendAnnouncement: func(msg lnwire.Message) error { - errChan := server.discoverSrv.ProcessLocalAnnouncement(msg, + errChan := server.authGossiper.ProcessLocalAnnouncement(msg, idPrivKey.PubKey()) return <-errChan },