wallet: --check-lookahead to update old wallets
This commit is contained in:
parent
b66085ac0c
commit
9428725a71
4 changed files with 52 additions and 3 deletions
|
|
@ -21,7 +21,12 @@ 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`. A rescan is
|
||||
recommended after this action.
|
||||
|
||||
### Node & Wallet API changes
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue