btcwallet: use db timeout param
This commit is contained in:
parent
86bc349c6e
commit
1cacaac9ea
4 changed files with 31 additions and 13 deletions
10
btcwallet.go
10
btcwallet.go
|
@ -69,7 +69,9 @@ func walletMain() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
||||||
loader := wallet.NewLoader(activeNet.Params, dbDir, true, 250)
|
loader := wallet.NewLoader(
|
||||||
|
activeNet.Params, dbDir, true, cfg.DBTimeout, 250,
|
||||||
|
)
|
||||||
|
|
||||||
// Create and start HTTP server to serve wallet client connections.
|
// Create and start HTTP server to serve wallet client connections.
|
||||||
// This will be updated with the wallet and chain server RPC client
|
// This will be updated with the wallet and chain server RPC client
|
||||||
|
@ -160,8 +162,10 @@ func rpcClientConnectLoop(legacyRPCServer *legacyrpc.Server, loader *wallet.Load
|
||||||
spvdb walletdb.DB
|
spvdb walletdb.DB
|
||||||
)
|
)
|
||||||
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
||||||
spvdb, err = walletdb.Create("bdb",
|
spvdb, err = walletdb.Create(
|
||||||
filepath.Join(netDir, "neutrino.db"), true)
|
"bdb", filepath.Join(netDir, "neutrino.db"),
|
||||||
|
true, cfg.DBTimeout,
|
||||||
|
)
|
||||||
defer spvdb.Close()
|
defer spvdb.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to create Neutrino DB: %s", err)
|
log.Errorf("Unable to create Neutrino DB: %s", err)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/wallet"
|
"github.com/btcsuite/btcwallet/wallet"
|
||||||
|
@ -19,16 +20,24 @@ import (
|
||||||
|
|
||||||
const defaultNet = "mainnet"
|
const defaultNet = "mainnet"
|
||||||
|
|
||||||
var datadir = btcutil.AppDataDir("btcwallet", false)
|
var (
|
||||||
|
datadir = btcutil.AppDataDir("btcwallet", false)
|
||||||
|
|
||||||
|
// defaultTimeout is the default timeout value when opening the wallet
|
||||||
|
// database.
|
||||||
|
defaultTimeout = 60 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// Flags.
|
// Flags.
|
||||||
var opts = struct {
|
var opts = struct {
|
||||||
Force bool `short:"f" description:"Force removal without prompt"`
|
Force bool `short:"f" description:"Force removal without prompt"`
|
||||||
DbPath string `long:"db" description:"Path to wallet database"`
|
DbPath string `long:"db" description:"Path to wallet database"`
|
||||||
DropLabels bool `long:"droplabels" description:"Drop transaction labels"`
|
DropLabels bool `long:"droplabels" description:"Drop transaction labels"`
|
||||||
|
Timeout time.Duration `long:"timeout" description:"Timeout value when opening the wallet database"`
|
||||||
}{
|
}{
|
||||||
Force: false,
|
Force: false,
|
||||||
DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
|
DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
|
||||||
|
Timeout: defaultTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -93,7 +102,7 @@ func mainInt() int {
|
||||||
fmt.Println("Enter yes or no.")
|
fmt.Println("Enter yes or no.")
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := walletdb.Open("bdb", opts.DbPath, true)
|
db, err := walletdb.Open("bdb", opts.DbPath, true, opts.Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to open database:", err)
|
fmt.Println("Failed to open database:", err)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -34,6 +34,7 @@ const (
|
||||||
defaultRPCMaxWebsockets = 25
|
defaultRPCMaxWebsockets = 25
|
||||||
|
|
||||||
walletDbName = "wallet.db"
|
walletDbName = "wallet.db"
|
||||||
|
defaultDBTimeout = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -58,6 +59,7 @@ type config struct {
|
||||||
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"`
|
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"`
|
||||||
LogDir string `long:"logdir" description:"Directory to log output."`
|
LogDir string `long:"logdir" description:"Directory to log output."`
|
||||||
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
|
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
|
||||||
|
DBTimeout time.Duration `long:"dbtimeout" description:"The timeout value to use when opening the wallet database."`
|
||||||
|
|
||||||
// Wallet options
|
// Wallet options
|
||||||
WalletPass string `long:"walletpass" default-mask:"-" description:"The public wallet password -- Only required if the wallet was created with one"`
|
WalletPass string `long:"walletpass" default-mask:"-" description:"The public wallet password -- Only required if the wallet was created with one"`
|
||||||
|
@ -273,6 +275,7 @@ func loadConfig() (*config, []string, error) {
|
||||||
MaxPeers: neutrino.MaxPeers,
|
MaxPeers: neutrino.MaxPeers,
|
||||||
BanDuration: neutrino.BanDuration,
|
BanDuration: neutrino.BanDuration,
|
||||||
BanThreshold: neutrino.BanThreshold,
|
BanThreshold: neutrino.BanThreshold,
|
||||||
|
DBTimeout: defaultDBTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pre-parse the command line options to see if an alternative config
|
// Pre-parse the command line options to see if an alternative config
|
||||||
|
|
|
@ -102,7 +102,9 @@ func convertLegacyKeystore(legacyKeyStore *keystore.Store, w *wallet.Wallet) err
|
||||||
// provided path.
|
// provided path.
|
||||||
func createWallet(cfg *config) error {
|
func createWallet(cfg *config) error {
|
||||||
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
||||||
loader := wallet.NewLoader(activeNet.Params, dbDir, true, 250)
|
loader := wallet.NewLoader(
|
||||||
|
activeNet.Params, dbDir, true, cfg.DBTimeout, 250,
|
||||||
|
)
|
||||||
|
|
||||||
// When there is a legacy keystore, open it now to ensure any errors
|
// When there is a legacy keystore, open it now to ensure any errors
|
||||||
// don't end up exiting the process after the user has spent time
|
// don't end up exiting the process after the user has spent time
|
||||||
|
@ -219,7 +221,7 @@ func createSimulationWallet(cfg *config) error {
|
||||||
fmt.Println("Creating the wallet...")
|
fmt.Println("Creating the wallet...")
|
||||||
|
|
||||||
// Create the wallet database backed by bolt db.
|
// Create the wallet database backed by bolt db.
|
||||||
db, err := walletdb.Create("bdb", dbPath, true)
|
db, err := walletdb.Create("bdb", dbPath, true, cfg.DBTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue