mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 18:10:48 +02:00
lncfg: use the sqldb config types instead of the kvdb counterparts
This commit is contained in:
@ -1298,8 +1298,9 @@ func initNeutrinoBackend(ctx context.Context, cfg *Config, chainDir string,
|
|||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
case cfg.DB.Backend == kvdb.SqliteBackendName:
|
case cfg.DB.Backend == kvdb.SqliteBackendName:
|
||||||
|
sqliteConfig := lncfg.GetSqliteConfigKVDB(cfg.DB.Sqlite)
|
||||||
db, err = kvdb.Open(
|
db, err = kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, cfg.DB.Sqlite, dbPath,
|
kvdb.SqliteBackendName, ctx, sqliteConfig, dbPath,
|
||||||
lncfg.SqliteNeutrinoDBName, lncfg.NSNeutrinoDB,
|
lncfg.SqliteNeutrinoDBName, lncfg.NSNeutrinoDB,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
67
lncfg/db.go
67
lncfg/db.go
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/kvdb/sqlite"
|
"github.com/lightningnetwork/lnd/kvdb/sqlite"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||||
|
"github.com/lightningnetwork/lnd/sqldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -78,9 +79,9 @@ type DB struct {
|
|||||||
|
|
||||||
Bolt *kvdb.BoltConfig `group:"bolt" namespace:"bolt" description:"Bolt settings."`
|
Bolt *kvdb.BoltConfig `group:"bolt" namespace:"bolt" description:"Bolt settings."`
|
||||||
|
|
||||||
Postgres *postgres.Config `group:"postgres" namespace:"postgres" description:"Postgres settings."`
|
Postgres *sqldb.PostgresConfig `group:"postgres" namespace:"postgres" description:"Postgres settings."`
|
||||||
|
|
||||||
Sqlite *sqlite.Config `group:"sqlite" namespace:"sqlite" description:"Sqlite settings."`
|
Sqlite *sqldb.SqliteConfig `group:"sqlite" namespace:"sqlite" description:"Sqlite settings."`
|
||||||
|
|
||||||
NoGraphCache bool `long:"no-graph-cache" description:"Don't use the in-memory graph cache for path finding. Much slower but uses less RAM. Can only be used with a bolt database backend."`
|
NoGraphCache bool `long:"no-graph-cache" description:"Don't use the in-memory graph cache for path finding. Much slower but uses less RAM. Can only be used with a bolt database backend."`
|
||||||
|
|
||||||
@ -103,10 +104,10 @@ func DefaultDB() *DB {
|
|||||||
// Allow at most 32 MiB messages by default.
|
// Allow at most 32 MiB messages by default.
|
||||||
MaxMsgSize: 32768 * 1024,
|
MaxMsgSize: 32768 * 1024,
|
||||||
},
|
},
|
||||||
Postgres: &postgres.Config{
|
Postgres: &sqldb.PostgresConfig{
|
||||||
MaxConnections: defaultPostgresMaxConnections,
|
MaxConnections: defaultPostgresMaxConnections,
|
||||||
},
|
},
|
||||||
Sqlite: &sqlite.Config{
|
Sqlite: &sqldb.SqliteConfig{
|
||||||
MaxConnections: defaultSqliteMaxConnections,
|
MaxConnections: defaultSqliteMaxConnections,
|
||||||
BusyTimeout: defaultSqliteBusyTimeout,
|
BusyTimeout: defaultSqliteBusyTimeout,
|
||||||
},
|
},
|
||||||
@ -118,8 +119,8 @@ func (db *DB) Validate() error {
|
|||||||
switch db.Backend {
|
switch db.Backend {
|
||||||
case BoltBackend, SqliteBackend:
|
case BoltBackend, SqliteBackend:
|
||||||
case PostgresBackend:
|
case PostgresBackend:
|
||||||
if db.Postgres.Dsn == "" {
|
if err := db.Postgres.Validate(); err != nil {
|
||||||
return fmt.Errorf("postgres dsn must be set")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
case EtcdBackend:
|
case EtcdBackend:
|
||||||
@ -223,6 +224,26 @@ type DatabaseBackends struct {
|
|||||||
CloseFuncs map[string]func() error
|
CloseFuncs map[string]func() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPostgresConfigKVDB converts a sqldb.PostgresConfig to a kvdb
|
||||||
|
// postgres.Config.
|
||||||
|
func GetPostgresConfigKVDB(cfg *sqldb.PostgresConfig) *postgres.Config {
|
||||||
|
return &postgres.Config{
|
||||||
|
Dsn: cfg.Dsn,
|
||||||
|
Timeout: cfg.Timeout,
|
||||||
|
MaxConnections: cfg.MaxConnections,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSqliteConfigKVDB converts a sqldb.SqliteConfig to a kvdb sqlite.Config.
|
||||||
|
func GetSqliteConfigKVDB(cfg *sqldb.SqliteConfig) *sqlite.Config {
|
||||||
|
return &sqlite.Config{
|
||||||
|
Timeout: cfg.Timeout,
|
||||||
|
BusyTimeout: cfg.BusyTimeout,
|
||||||
|
MaxConnections: cfg.MaxConnections,
|
||||||
|
PragmaOptions: cfg.PragmaOptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetBackends returns a set of kvdb.Backends as set in the DB config.
|
// GetBackends returns a set of kvdb.Backends as set in the DB config.
|
||||||
func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
||||||
walletDBPath, towerServerDBPath string, towerClientEnabled,
|
walletDBPath, towerServerDBPath string, towerClientEnabled,
|
||||||
@ -342,9 +363,14 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case PostgresBackend:
|
case PostgresBackend:
|
||||||
|
// Convert the sqldb PostgresConfig to a kvdb postgres.Config.
|
||||||
|
// This is a temporary measure until we migrate all kvdb SQL
|
||||||
|
// users to native SQL.
|
||||||
|
postgresConfig := GetPostgresConfigKVDB(db.Postgres)
|
||||||
|
|
||||||
postgresBackend, err := kvdb.Open(
|
postgresBackend, err := kvdb.Open(
|
||||||
kvdb.PostgresBackendName, ctx,
|
kvdb.PostgresBackendName, ctx,
|
||||||
db.Postgres, NSChannelDB,
|
postgresConfig, NSChannelDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening postgres graph "+
|
return nil, fmt.Errorf("error opening postgres graph "+
|
||||||
@ -354,7 +380,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
|
|
||||||
postgresMacaroonBackend, err := kvdb.Open(
|
postgresMacaroonBackend, err := kvdb.Open(
|
||||||
kvdb.PostgresBackendName, ctx,
|
kvdb.PostgresBackendName, ctx,
|
||||||
db.Postgres, NSMacaroonDB,
|
postgresConfig, NSMacaroonDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening postgres "+
|
return nil, fmt.Errorf("error opening postgres "+
|
||||||
@ -364,7 +390,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
|
|
||||||
postgresDecayedLogBackend, err := kvdb.Open(
|
postgresDecayedLogBackend, err := kvdb.Open(
|
||||||
kvdb.PostgresBackendName, ctx,
|
kvdb.PostgresBackendName, ctx,
|
||||||
db.Postgres, NSDecayedLogDB,
|
postgresConfig, NSDecayedLogDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening postgres "+
|
return nil, fmt.Errorf("error opening postgres "+
|
||||||
@ -374,7 +400,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
|
|
||||||
postgresTowerClientBackend, err := kvdb.Open(
|
postgresTowerClientBackend, err := kvdb.Open(
|
||||||
kvdb.PostgresBackendName, ctx,
|
kvdb.PostgresBackendName, ctx,
|
||||||
db.Postgres, NSTowerClientDB,
|
postgresConfig, NSTowerClientDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening postgres tower "+
|
return nil, fmt.Errorf("error opening postgres tower "+
|
||||||
@ -384,7 +410,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
|
|
||||||
postgresTowerServerBackend, err := kvdb.Open(
|
postgresTowerServerBackend, err := kvdb.Open(
|
||||||
kvdb.PostgresBackendName, ctx,
|
kvdb.PostgresBackendName, ctx,
|
||||||
db.Postgres, NSTowerServerDB,
|
postgresConfig, NSTowerServerDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening postgres tower "+
|
return nil, fmt.Errorf("error opening postgres tower "+
|
||||||
@ -394,7 +420,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
|
|
||||||
postgresWalletBackend, err := kvdb.Open(
|
postgresWalletBackend, err := kvdb.Open(
|
||||||
kvdb.PostgresBackendName, ctx,
|
kvdb.PostgresBackendName, ctx,
|
||||||
db.Postgres, NSWalletDB,
|
postgresConfig, NSWalletDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening postgres macaroon "+
|
return nil, fmt.Errorf("error opening postgres macaroon "+
|
||||||
@ -434,6 +460,11 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case SqliteBackend:
|
case SqliteBackend:
|
||||||
|
// Convert the sqldb SqliteConfig to a kvdb sqlite.Config.
|
||||||
|
// This is a temporary measure until we migrate all kvdb SQL
|
||||||
|
// users to native SQL.
|
||||||
|
sqliteConfig := GetSqliteConfigKVDB(db.Sqlite)
|
||||||
|
|
||||||
// Note that for sqlite, we put kv tables for the channel.db,
|
// Note that for sqlite, we put kv tables for the channel.db,
|
||||||
// wtclient.db and sphinxreplay.db all in the channel.sqlite db.
|
// wtclient.db and sphinxreplay.db all in the channel.sqlite db.
|
||||||
// The tables for wallet.db and macaroon.db are in the
|
// The tables for wallet.db and macaroon.db are in the
|
||||||
@ -445,7 +476,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
// would cause deadlocks in the code due to the wallet db often
|
// would cause deadlocks in the code due to the wallet db often
|
||||||
// being accessed during a write to another db.
|
// being accessed during a write to another db.
|
||||||
sqliteBackend, err := kvdb.Open(
|
sqliteBackend, err := kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, db.Sqlite, chanDBPath,
|
kvdb.SqliteBackendName, ctx, sqliteConfig, chanDBPath,
|
||||||
SqliteChannelDBName, NSChannelDB,
|
SqliteChannelDBName, NSChannelDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -455,7 +486,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
closeFuncs[NSChannelDB] = sqliteBackend.Close
|
closeFuncs[NSChannelDB] = sqliteBackend.Close
|
||||||
|
|
||||||
sqliteMacaroonBackend, err := kvdb.Open(
|
sqliteMacaroonBackend, err := kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, db.Sqlite, walletDBPath,
|
kvdb.SqliteBackendName, ctx, sqliteConfig, walletDBPath,
|
||||||
SqliteChainDBName, NSMacaroonDB,
|
SqliteChainDBName, NSMacaroonDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -465,7 +496,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
closeFuncs[NSMacaroonDB] = sqliteMacaroonBackend.Close
|
closeFuncs[NSMacaroonDB] = sqliteMacaroonBackend.Close
|
||||||
|
|
||||||
sqliteDecayedLogBackend, err := kvdb.Open(
|
sqliteDecayedLogBackend, err := kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, db.Sqlite, chanDBPath,
|
kvdb.SqliteBackendName, ctx, sqliteConfig, chanDBPath,
|
||||||
SqliteChannelDBName, NSDecayedLogDB,
|
SqliteChannelDBName, NSDecayedLogDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -475,7 +506,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
closeFuncs[NSDecayedLogDB] = sqliteDecayedLogBackend.Close
|
closeFuncs[NSDecayedLogDB] = sqliteDecayedLogBackend.Close
|
||||||
|
|
||||||
sqliteTowerClientBackend, err := kvdb.Open(
|
sqliteTowerClientBackend, err := kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, db.Sqlite, chanDBPath,
|
kvdb.SqliteBackendName, ctx, sqliteConfig, chanDBPath,
|
||||||
SqliteChannelDBName, NSTowerClientDB,
|
SqliteChannelDBName, NSTowerClientDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -485,7 +516,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
closeFuncs[NSTowerClientDB] = sqliteTowerClientBackend.Close
|
closeFuncs[NSTowerClientDB] = sqliteTowerClientBackend.Close
|
||||||
|
|
||||||
sqliteTowerServerBackend, err := kvdb.Open(
|
sqliteTowerServerBackend, err := kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, db.Sqlite,
|
kvdb.SqliteBackendName, ctx, sqliteConfig,
|
||||||
towerServerDBPath, SqliteTowerDBName, NSTowerServerDB,
|
towerServerDBPath, SqliteTowerDBName, NSTowerServerDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -495,7 +526,7 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
|
|||||||
closeFuncs[NSTowerServerDB] = sqliteTowerServerBackend.Close
|
closeFuncs[NSTowerServerDB] = sqliteTowerServerBackend.Close
|
||||||
|
|
||||||
sqliteWalletBackend, err := kvdb.Open(
|
sqliteWalletBackend, err := kvdb.Open(
|
||||||
kvdb.SqliteBackendName, ctx, db.Sqlite, walletDBPath,
|
kvdb.SqliteBackendName, ctx, sqliteConfig, walletDBPath,
|
||||||
SqliteChainDBName, NSWalletDB,
|
SqliteChainDBName, NSWalletDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user