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