lnd: use native SQL invoice store if configured
This commit is contained in:
1 file changed
+28
-9
+28
-9
@@ -3,6 +3,7 @@ package lnd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -31,6 +32,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/chainreg"
|
"github.com/lightningnetwork/lnd/chainreg"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/invoices"
|
"github.com/lightningnetwork/lnd/invoices"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
@@ -42,6 +44,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/macaroons"
|
"github.com/lightningnetwork/lnd/macaroons"
|
||||||
"github.com/lightningnetwork/lnd/rpcperms"
|
"github.com/lightningnetwork/lnd/rpcperms"
|
||||||
"github.com/lightningnetwork/lnd/signal"
|
"github.com/lightningnetwork/lnd/signal"
|
||||||
|
"github.com/lightningnetwork/lnd/sqldb"
|
||||||
"github.com/lightningnetwork/lnd/walletunlocker"
|
"github.com/lightningnetwork/lnd/walletunlocker"
|
||||||
"github.com/lightningnetwork/lnd/watchtower"
|
"github.com/lightningnetwork/lnd/watchtower"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/wtclient"
|
"github.com/lightningnetwork/lnd/watchtower/wtclient"
|
||||||
@@ -869,6 +872,11 @@ type DatabaseInstances struct {
|
|||||||
// WalletDB is the configuration for loading the wallet database using
|
// WalletDB is the configuration for loading the wallet database using
|
||||||
// the btcwallet's loader.
|
// the btcwallet's loader.
|
||||||
WalletDB btcwallet.LoaderOption
|
WalletDB btcwallet.LoaderOption
|
||||||
|
|
||||||
|
// NativeSQLStore is a pointer to a native SQL store that can be used
|
||||||
|
// for native SQL queries for tables that already support it. This may
|
||||||
|
// be nil if the use-native-sql flag was not set.
|
||||||
|
NativeSQLStore *sqldb.BaseDB
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultDatabaseBuilder is a type that builds the default database backends
|
// DefaultDatabaseBuilder is a type that builds the default database backends
|
||||||
@@ -923,10 +931,11 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
|
|||||||
// state DB point to the same local or remote DB and the same namespace
|
// state DB point to the same local or remote DB and the same namespace
|
||||||
// within that DB.
|
// within that DB.
|
||||||
dbs := &DatabaseInstances{
|
dbs := &DatabaseInstances{
|
||||||
HeightHintDB: databaseBackends.HeightHintDB,
|
HeightHintDB: databaseBackends.HeightHintDB,
|
||||||
MacaroonDB: databaseBackends.MacaroonDB,
|
MacaroonDB: databaseBackends.MacaroonDB,
|
||||||
DecayedLogDB: databaseBackends.DecayedLogDB,
|
DecayedLogDB: databaseBackends.DecayedLogDB,
|
||||||
WalletDB: databaseBackends.WalletDB,
|
WalletDB: databaseBackends.WalletDB,
|
||||||
|
NativeSQLStore: databaseBackends.NativeSQLStore,
|
||||||
}
|
}
|
||||||
cleanUp := func() {
|
cleanUp := func() {
|
||||||
// We can just close the returned close functions directly. Even
|
// We can just close the returned close functions directly. Even
|
||||||
@@ -1011,11 +1020,21 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
|
|||||||
// using the same struct (and DB backend) instance.
|
// using the same struct (and DB backend) instance.
|
||||||
dbs.ChanStateDB = dbs.GraphDB
|
dbs.ChanStateDB = dbs.GraphDB
|
||||||
|
|
||||||
// For now the only InvoiceDB implementation is the *channeldb.DB.
|
// Instantiate a native SQL invoice store if the flag is set.
|
||||||
//
|
if d.cfg.DB.UseNativeSQL {
|
||||||
// TODO(positiveblue): use a sql first implementation for this
|
executor := sqldb.NewTransactionExecutor(
|
||||||
// interface.
|
dbs.NativeSQLStore,
|
||||||
dbs.InvoiceDB = dbs.GraphDB
|
func(tx *sql.Tx) sqldb.InvoiceQueries {
|
||||||
|
return dbs.NativeSQLStore.WithTx(tx)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
dbs.InvoiceDB = sqldb.NewInvoiceStore(
|
||||||
|
executor, clock.NewDefaultClock(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
dbs.InvoiceDB = dbs.GraphDB
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap the watchtower client DB and make sure we clean up.
|
// Wrap the watchtower client DB and make sure we clean up.
|
||||||
if cfg.WtClient.Active {
|
if cfg.WtClient.Active {
|
||||||
|
|||||||
Reference in new issue
Block a user