diff --git a/btcwallet.go b/btcwallet.go index 4a96fef..72728fb 100644 --- a/btcwallet.go +++ b/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) diff --git a/cmd/dropwtxmgr/main.go b/cmd/dropwtxmgr/main.go index e1e3a1c..72552f3 100644 --- a/cmd/dropwtxmgr/main.go +++ b/cmd/dropwtxmgr/main.go @@ -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"` + 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"), + 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 diff --git a/config.go b/config.go index 2b9e7ea..54575cb 100644 --- a/config.go +++ b/config.go @@ -33,7 +33,8 @@ const ( defaultRPCMaxClients = 10 defaultRPCMaxWebsockets = 25 - walletDbName = "wallet.db" + 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 diff --git a/walletsetup.go b/walletsetup.go index de63415..3723abe 100644 --- a/walletsetup.go +++ b/walletsetup.go @@ -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 }