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:
Oliver Gugger committed 2021-08-04 14:55:54 +02:00
1 parent 75531455da
commit 57c7862eeb
2 files changed
+27 -26

No files matched your search

+22 -3
View File
@@ -7,6 +7,7 @@ import (
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/kvdb/etcd"
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
)
const (
@@ -135,6 +136,10 @@ type DatabaseBackends struct {
// server data. This might be nil if the watchtower server is disabled.
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
// replicated instances or local bbolt backed databases.
Remote bool
@@ -185,8 +190,16 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
DecayedLogDB: etcdBackend,
TowerClientDB: etcdBackend,
TowerServerDB: etcdBackend,
Remote: true,
CloseFuncs: closeFuncs,
// 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.
WalletDB: btcwallet.LoaderWithExternalWalletDB(
etcdBackend,
),
Remote: true,
CloseFuncs: closeFuncs,
}, nil
}
@@ -281,7 +294,13 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
DecayedLogDB: decayedLogBackend,
TowerClientDB: towerClientBackend,
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
}