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: preload all wallets before HTTP server is started. #76

Merged
merged 1 commit into from
Jan 25, 2023
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
3 changes: 2 additions & 1 deletion lib/wallet/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class WalletNode extends Node {
wipeNoReally: this.config.bool('wipe-no-really'),
spv: this.config.bool('spv'),
migrate: 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);
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class Plugin extends EventEmitter {
wipeNoReally: this.config.bool('wipe-no-really'),
spv: node.spv,
migrate: 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);
Expand Down
27 changes: 27 additions & 0 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class WalletDB extends EventEmitter {
await this.migrateChange();

await this.checkLookahead();
await this.preloadAll();
}

/**
Expand Down Expand Up @@ -304,6 +305,27 @@ class WalletDB extends EventEmitter {
await b.write();
}

/**
* Preload/open all wallets on open.
* @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}
Expand Down Expand Up @@ -2519,6 +2541,7 @@ class WalletOptions {
this.wipeNoReally = false;
this.migrate = null;
this.checkLookahead = false;
this.preloadAll = false;

if (options)
this.fromOptions(options);
Expand Down Expand Up @@ -2606,6 +2629,10 @@ class WalletOptions {
this.checkLookahead = options.checkLookahead;
}

if (options.preloadAll != null) {
assert(typeof options.preloadAll === 'boolean');
this.preloadAll = options.preloadAll;
}
return this;
}

Expand Down