mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-12 18:01:23 +02:00
lnd+lncfg: move wallet DB options into backend method
To have all the database backend related code in one place, we finally also move the initialization of the wallet DB loader option into the GetBackends() method.
This commit is contained in:
parent
75531455da
commit
57c7862eeb
25
lncfg/db.go
25
lncfg/db.go
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/kvdb/etcd"
|
"github.com/lightningnetwork/lnd/kvdb/etcd"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -135,6 +136,10 @@ type DatabaseBackends struct {
|
|||||||
// server data. This might be nil if the watchtower server is disabled.
|
// server data. This might be nil if the watchtower server is disabled.
|
||||||
TowerServerDB kvdb.Backend
|
TowerServerDB kvdb.Backend
|
||||||
|
|
||||||
|
// WalletDB is an option that instructs the wallet loader where to load
|
||||||
|
// the underlying wallet database from.
|
||||||
|
WalletDB btcwallet.LoaderOption
|
||||||
|
|
||||||
// Remote indicates whether the database backends are remote, possibly
|
// Remote indicates whether the database backends are remote, possibly
|
||||||
// replicated instances or local bbolt backed databases.
|
// replicated instances or local bbolt backed databases.
|
||||||
Remote bool
|
Remote bool
|
||||||
@ -185,8 +190,16 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
DecayedLogDB: etcdBackend,
|
DecayedLogDB: etcdBackend,
|
||||||
TowerClientDB: etcdBackend,
|
TowerClientDB: etcdBackend,
|
||||||
TowerServerDB: etcdBackend,
|
TowerServerDB: etcdBackend,
|
||||||
Remote: true,
|
// The wallet loader will attempt to use/create the
|
||||||
CloseFuncs: closeFuncs,
|
// wallet in the replicated remote DB if we're running
|
||||||
|
// in a clustered environment. This will ensure that all
|
||||||
|
// members of the cluster have access to the same wallet
|
||||||
|
// state.
|
||||||
|
WalletDB: btcwallet.LoaderWithExternalWalletDB(
|
||||||
|
etcdBackend,
|
||||||
|
),
|
||||||
|
Remote: true,
|
||||||
|
CloseFuncs: closeFuncs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +294,13 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
DecayedLogDB: decayedLogBackend,
|
DecayedLogDB: decayedLogBackend,
|
||||||
TowerClientDB: towerClientBackend,
|
TowerClientDB: towerClientBackend,
|
||||||
TowerServerDB: towerServerBackend,
|
TowerServerDB: towerServerBackend,
|
||||||
CloseFuncs: closeFuncs,
|
// When "running locally", LND will use the bbolt wallet.db to
|
||||||
|
// store the wallet located in the chain data dir, parametrized
|
||||||
|
// by the active network.
|
||||||
|
WalletDB: btcwallet.LoaderWithLocalWalletDB(
|
||||||
|
walletDBPath, !db.Bolt.SyncFreelist, db.Bolt.DBTimeout,
|
||||||
|
),
|
||||||
|
CloseFuncs: closeFuncs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
lnd.go
28
lnd.go
@ -462,25 +462,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
|
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
var loaderOpt btcwallet.LoaderOption
|
pwService.SetLoaderOpts([]btcwallet.LoaderOption{dbs.walletDB})
|
||||||
if cfg.Cluster.EnableLeaderElection {
|
|
||||||
// The wallet loader will attempt to use/create the wallet in
|
|
||||||
// the replicated remote DB if we're running in a clustered
|
|
||||||
// environment. This will ensure that all members of the cluster
|
|
||||||
// have access to the same wallet state.
|
|
||||||
loaderOpt = btcwallet.LoaderWithExternalWalletDB(
|
|
||||||
dbs.chanStateDB.Backend,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// When "running locally", LND will use the bbolt wallet.db to
|
|
||||||
// store the wallet located in the chain data dir, parametrized
|
|
||||||
// by the active network.
|
|
||||||
loaderOpt = btcwallet.LoaderWithLocalWalletDB(
|
|
||||||
cfg.networkDir, !cfg.SyncFreelist, cfg.DB.Bolt.DBTimeout,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pwService.SetLoaderOpts([]btcwallet.LoaderOption{loaderOpt})
|
|
||||||
pwService.SetMacaroonDB(dbs.macaroonDB)
|
pwService.SetMacaroonDB(dbs.macaroonDB)
|
||||||
walletExists, err := pwService.WalletExists()
|
walletExists, err := pwService.WalletExists()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -556,7 +538,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
// over RPC.
|
// over RPC.
|
||||||
default:
|
default:
|
||||||
params, err := waitForWalletPassword(
|
params, err := waitForWalletPassword(
|
||||||
cfg, pwService, []btcwallet.LoaderOption{loaderOpt},
|
cfg, pwService, []btcwallet.LoaderOption{dbs.walletDB},
|
||||||
interceptor.ShutdownChannel(),
|
interceptor.ShutdownChannel(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -715,9 +697,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
return cfg.net.Dial("tcp", addr, cfg.ConnectionTimeout)
|
return cfg.net.Dial("tcp", addr, cfg.ConnectionTimeout)
|
||||||
},
|
},
|
||||||
BlockCacheSize: cfg.BlockCacheSize,
|
BlockCacheSize: cfg.BlockCacheSize,
|
||||||
LoaderOptions: []btcwallet.LoaderOption{
|
LoaderOptions: []btcwallet.LoaderOption{dbs.walletDB},
|
||||||
loaderOpt,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse coin selection strategy.
|
// Parse coin selection strategy.
|
||||||
@ -1584,6 +1564,7 @@ type databaseInstances struct {
|
|||||||
decayedLogDB kvdb.Backend
|
decayedLogDB kvdb.Backend
|
||||||
towerClientDB wtclient.DB
|
towerClientDB wtclient.DB
|
||||||
towerServerDB watchtower.DB
|
towerServerDB watchtower.DB
|
||||||
|
walletDB btcwallet.LoaderOption
|
||||||
}
|
}
|
||||||
|
|
||||||
// initializeDatabases extracts the current databases that we'll use for normal
|
// initializeDatabases extracts the current databases that we'll use for normal
|
||||||
@ -1622,6 +1603,7 @@ func initializeDatabases(ctx context.Context,
|
|||||||
heightHintDB: databaseBackends.HeightHintDB,
|
heightHintDB: databaseBackends.HeightHintDB,
|
||||||
macaroonDB: databaseBackends.MacaroonDB,
|
macaroonDB: databaseBackends.MacaroonDB,
|
||||||
decayedLogDB: databaseBackends.DecayedLogDB,
|
decayedLogDB: databaseBackends.DecayedLogDB,
|
||||||
|
walletDB: databaseBackends.WalletDB,
|
||||||
}
|
}
|
||||||
cleanUp := func() {
|
cleanUp := func() {
|
||||||
// We can just close the returned close functions directly. Even
|
// We can just close the returned close functions directly. Even
|
||||||
|
Loading…
x
Reference in New Issue
Block a user