mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 22:21:18 +02:00
multi: make macaroon DB remote compatible
The macaroon root keys should also be stored to the remote database if a replicated backend such as etcd is used. This commit refactors the macaroons service and wallet unlocker to accept a kvdb backend directly instead of creating the bolt instance automatically.
This commit is contained in:
19
lnd.go
19
lnd.go
@@ -480,6 +480,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
||||
}
|
||||
|
||||
pwService.SetLoaderOpts([]btcwallet.LoaderOption{loaderOpt})
|
||||
pwService.SetMacaroonDB(dbs.macaroonDB)
|
||||
walletExists, err := pwService.WalletExists()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -584,8 +585,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
||||
if !cfg.NoMacaroons {
|
||||
// Create the macaroon authentication/authorization service.
|
||||
macaroonService, err = macaroons.NewService(
|
||||
cfg.networkDir, "lnd", walletInitParams.StatelessInit,
|
||||
cfg.DB.Bolt.DBTimeout, macaroons.IPLockChecker,
|
||||
dbs.macaroonDB, "lnd", walletInitParams.StatelessInit,
|
||||
macaroons.IPLockChecker,
|
||||
)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("unable to set up macaroon "+
|
||||
@@ -1326,11 +1327,6 @@ type WalletUnlockParams struct {
|
||||
// createWalletUnlockerService creates a WalletUnlockerService from the passed
|
||||
// config.
|
||||
func createWalletUnlockerService(cfg *Config) *walletunlocker.UnlockerService {
|
||||
chainConfig := cfg.Bitcoin
|
||||
if cfg.registeredChains.PrimaryChain() == chainreg.LitecoinChain {
|
||||
chainConfig = cfg.Litecoin
|
||||
}
|
||||
|
||||
// The macaroonFiles are passed to the wallet unlocker so they can be
|
||||
// deleted and recreated in case the root macaroon key is also changed
|
||||
// during the change password operation.
|
||||
@@ -1339,8 +1335,7 @@ func createWalletUnlockerService(cfg *Config) *walletunlocker.UnlockerService {
|
||||
}
|
||||
|
||||
return walletunlocker.New(
|
||||
chainConfig.ChainDir, cfg.ActiveNetParams.Params,
|
||||
!cfg.SyncFreelist, macaroonFiles, cfg.DB.Bolt.DBTimeout,
|
||||
cfg.ActiveNetParams.Params, macaroonFiles,
|
||||
cfg.ResetWalletTransactions, nil,
|
||||
)
|
||||
}
|
||||
@@ -1620,6 +1615,7 @@ type databaseInstances struct {
|
||||
graphDB *channeldb.DB
|
||||
chanStateDB *channeldb.DB
|
||||
heightHintDB kvdb.Backend
|
||||
macaroonDB kvdb.Backend
|
||||
}
|
||||
|
||||
// initializeDatabases extracts the current databases that we'll use for normal
|
||||
@@ -1639,7 +1635,9 @@ func initializeDatabases(ctx context.Context,
|
||||
|
||||
startOpenTime := time.Now()
|
||||
|
||||
databaseBackends, err := cfg.DB.GetBackends(ctx, cfg.graphDatabaseDir())
|
||||
databaseBackends, err := cfg.DB.GetBackends(
|
||||
ctx, cfg.graphDatabaseDir(), cfg.networkDir,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to obtain database "+
|
||||
"backends: %v", err)
|
||||
@@ -1650,6 +1648,7 @@ func initializeDatabases(ctx context.Context,
|
||||
// within that DB.
|
||||
dbs := &databaseInstances{
|
||||
heightHintDB: databaseBackends.HeightHintDB,
|
||||
macaroonDB: databaseBackends.MacaroonDB,
|
||||
}
|
||||
cleanUp := func() {
|
||||
// We can just close the returned close functions directly. Even
|
||||
|
Reference in New Issue
Block a user