diff --git a/CHANGELOG.md b/CHANGELOG.md index 746a7e2380..fee04906c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,11 @@ The bid will be broadcasted either during the creation (`broadcastBid=true`) or (`broadcastBid=false`). The reveal will have to be broadcasted at a later time, during the REVEAL phase. The lockup must include a blind big enough to ensure the BID will be the only input of the REVEAL -transaction. +transaction. + +- Now parses option `--wallet-check-lookahead` (or `--check-lookahead` for standalone +wallet node) that will check every account of every wallet in the DB and ensure +the lookahead value is the current default and maximum of `200`. ### Node & Wallet API changes diff --git a/lib/wallet/node.js b/lib/wallet/node.js index a9725174e6..f751d98d4c 100644 --- a/lib/wallet/node.js +++ b/lib/wallet/node.js @@ -51,7 +51,8 @@ class WalletNode extends Node { cacheSize: this.config.mb('cache-size'), wipeNoReally: this.config.bool('wipe-no-really'), spv: this.config.bool('spv'), - migrate: this.config.uint('migrate') + migrate: this.config.uint('migrate'), + checkLookahead: this.config.bool('check-lookahead', false) }); this.rpc = new RPC(this); diff --git a/lib/wallet/plugin.js b/lib/wallet/plugin.js index 59ce7d184e..6f7b6f388a 100644 --- a/lib/wallet/plugin.js +++ b/lib/wallet/plugin.js @@ -52,7 +52,8 @@ class Plugin extends EventEmitter { cacheSize: this.config.mb('cache-size'), wipeNoReally: this.config.bool('wipe-no-really'), spv: node.spv, - migrate: this.config.uint('migrate') + migrate: this.config.uint('migrate'), + checkLookahead: this.config.bool('check-lookahead', false) }); this.rpc = new RPC(this); diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 4eba6f23da..d5d9ae5ad6 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -208,6 +208,8 @@ class WalletDB extends EventEmitter { this.primary = wallet; await this.migrateChange(); + + await this.checkLookahead(); } /** @@ -268,6 +270,40 @@ class WalletDB extends EventEmitter { } } + /** + * Update account lookahead & depth + * @returns {Promise} + */ + + async checkLookahead() { + if (!this.options.checkLookahead) + return; + + const b = this.db.batch(); + + 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) { + const wallet = await this.get(wid); + + for (let i = 0; i < wallet.accountDepth; i++) { + this.logger.warning( + 'Setting lookahead for wallet %s account %d', + wallet.id, + i + ); + const account = await wallet.getAccount(i); + await account.setLookahead(b, Account.MAX_LOOKAHEAD); + } + } + + await b.write(); + } + /** * Verify network. * @returns {Promise} @@ -2479,6 +2515,7 @@ class WalletOptions { this.spv = false; this.wipeNoReally = false; this.migrate = null; + this.checkLookahead = false; if (options) this.fromOptions(options); @@ -2561,6 +2598,11 @@ class WalletOptions { this.migrate = options.migrate; } + if (options.checkLookahead != null) { + assert(typeof options.checkLookahead === 'boolean'); + this.checkLookahead = options.checkLookahead; + } + return this; }