Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: --check-lookahead to update old wallets #569

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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