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)
|
||||
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.
|
||||
// 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
|
||||
)
|
||||
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
||||
spvdb, err = walletdb.Create("bdb",
|
||||
filepath.Join(netDir, "neutrino.db"), true)
|
||||
spvdb, err = walletdb.Create(
|
||||
"bdb", filepath.Join(netDir, "neutrino.db"),
|
||||
true, cfg.DBTimeout,
|
||||
)
|
||||
defer spvdb.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Unable to create Neutrino DB: %s", err)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/wallet"
|
||||
|
@ -19,16 +20,24 @@ import (
|
|||
|
||||
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.
|
||||
var opts = struct {
|
||||
Force bool `short:"f" description:"Force removal without prompt"`
|
||||
DbPath string `long:"db" description:"Path to wallet database"`
|
||||
DropLabels bool `long:"droplabels" description:"Drop transaction labels"`
|
||||
Timeout time.Duration `long:"timeout" description:"Timeout value when opening the wallet database"`
|
||||
}{
|
||||
Force: false,
|
||||
DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
|
||||
Timeout: defaultTimeout,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -93,7 +102,7 @@ func mainInt() int {
|
|||
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 {
|
||||
fmt.Println("Failed to open database:", err)
|
||||
return 1
|
||||
|
|
|
@ -34,6 +34,7 @@ const (
|
|||
defaultRPCMaxWebsockets = 25
|
||||
|
||||
walletDbName = "wallet.db"
|
||||
defaultDBTimeout = 60 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -58,6 +59,7 @@ type config struct {
|
|||
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"`
|
||||
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"`
|
||||
DBTimeout time.Duration `long:"dbtimeout" description:"The timeout value to use when opening the wallet database."`
|
||||
|
||||
// Wallet options
|
||||
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,
|
||||
BanDuration: neutrino.BanDuration,
|
||||
BanThreshold: neutrino.BanThreshold,
|
||||
DBTimeout: defaultDBTimeout,
|
||||
}
|
||||
|
||||
// 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.
|
||||
func createWallet(cfg *config) error {
|
||||
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
|
||||
// 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...")
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue