Skip to content

Commit

Permalink
wallet: --preload-all option to load all wallet on open.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Jan 20, 2023
1 parent 008374c commit a1dd9a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# HSD Release Notes & Changelog

## Unreleased

### Wallet changes
- Add `--wallet-preload-all` (or `--preload-all` for standalone wallet node)
that will open all wallets before starting other services (e.g. HTTP).
By default this is set to `false`.

## v5.0.0

**When upgrading to this version of hsd, you must pass `--wallet-migrate=2` when
Expand Down
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'),
walletMigrate: 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 @@ -53,7 +53,8 @@ class Plugin extends EventEmitter {
wipeNoReally: this.config.bool('wipe-no-really'),
spv: node.spv,
walletMigrate: 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 @@ -226,6 +226,7 @@ class WalletDB extends EventEmitter {
}

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

/**
Expand Down Expand Up @@ -277,6 +278,26 @@ class WalletDB extends EventEmitter {
await b.write();
}

/**
* Preload all wallets.
* @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 @@ -2505,6 +2526,7 @@ class WalletOptions {
this.wipeNoReally = false;
this.walletMigrate = -1;
this.checkLookahead = false;
this.preloadAll = false;

if (options)
this.fromOptions(options);
Expand Down Expand Up @@ -2592,6 +2614,11 @@ class WalletOptions {
this.checkLookahead = options.checkLookahead;
}

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

return this;
}

Expand Down

0 comments on commit a1dd9a3

Please sign in to comment.