Skip to content

Commit

Permalink
Merge PR #569 from 'pinheadmz/synclookahead1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Mar 15, 2021
2 parents 208d101 + 9428725 commit a69780e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/node.js
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/plugin.js
Expand Up @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions lib/wallet/walletdb.js
Expand Up @@ -208,6 +208,8 @@ class WalletDB extends EventEmitter {
this.primary = wallet;

await this.migrateChange();

await this.checkLookahead();
}

/**
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -2479,6 +2515,7 @@ class WalletOptions {
this.spv = false;
this.wipeNoReally = false;
this.migrate = null;
this.checkLookahead = false;

if (options)
this.fromOptions(options);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a69780e

Please sign in to comment.