config: use a single global macaroon database, scope macaroons in datadir

This commit modifies the way that we create the macaroon database, and
also create the initial macaroons themselves. Rather than creating a
new macaroon DB for each chain, we instead create a single instance for
all chains. Additionally, if the datadir has been modified, and the
macaroon paths haven’t been modified, the macaroons are now scoped to
those paths.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-22 00:03:03 -07:00
parent f5d221012d
commit e0bed8bc27
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 23 additions and 7 deletions

View File

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

14
lnd.go
View File

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