diff --git a/CHANGELOG.md b/CHANGELOG.md index f58b8c421..319e2136c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # HSD Release Notes & Changelog +## Unreleased + +### Wallet changes + - Add `--wallet-preload-all` (or `--preload-all` for standalone wallet node) + that will open all wallets before starting other services (e.g. HTTP). + By default this is set to `false`. + ## v5.0.0 **When upgrading to this version of hsd, you must pass `--wallet-migrate=2` when diff --git a/lib/wallet/node.js b/lib/wallet/node.js index e28894ef1..dcf762a5d 100644 --- a/lib/wallet/node.js +++ b/lib/wallet/node.js @@ -52,7 +52,8 @@ class WalletNode extends Node { wipeNoReally: this.config.bool('wipe-no-really'), spv: this.config.bool('spv'), walletMigrate: this.config.uint('migrate'), - checkLookahead: this.config.bool('check-lookahead', false) + checkLookahead: this.config.bool('check-lookahead', false), + preloadAll: this.config.bool('preload-all', false) }); this.rpc = new RPC(this); diff --git a/lib/wallet/plugin.js b/lib/wallet/plugin.js index f0a7b7434..017769556 100644 --- a/lib/wallet/plugin.js +++ b/lib/wallet/plugin.js @@ -53,7 +53,8 @@ class Plugin extends EventEmitter { wipeNoReally: this.config.bool('wipe-no-really'), spv: node.spv, walletMigrate: this.config.uint('migrate'), - checkLookahead: this.config.bool('check-lookahead', false) + checkLookahead: this.config.bool('check-lookahead', false), + preloadAll: this.config.bool('preload-all', false) }); this.rpc = new RPC(this); diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index bf65c048d..eb0224129 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -226,6 +226,7 @@ class WalletDB extends EventEmitter { } await this.checkLookahead(); + await this.preloadAll(); } /** @@ -277,6 +278,26 @@ class WalletDB extends EventEmitter { await b.write(); } + /** + * Preload all wallets. + * @returns {Promise} + */ + + async preloadAll() { + if (!this.options.preloadAll) + return; + + this.logger.info('Preloading all wallets...'); + const wids = await this.db.keys({ + gte: layout.W.min(), + lte: layout.W.max(), + parse: key => layout.W.decode(key)[0] + }); + + for (const wid of wids) + await this._get(wid); + } + /** * Verify network. * @returns {Promise} @@ -2505,6 +2526,7 @@ class WalletOptions { this.wipeNoReally = false; this.walletMigrate = -1; this.checkLookahead = false; + this.preloadAll = false; if (options) this.fromOptions(options); @@ -2592,6 +2614,11 @@ class WalletOptions { this.checkLookahead = options.checkLookahead; } + if (options.preloadAll != null) { + assert(typeof options.preloadAll === 'boolean'); + this.preloadAll = options.preloadAll; + } + return this; }