handshake-org / hsd

Handshake Daemon & Full Node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

should wdb.rescanning be set `true` earlier?

pinheadmz opened this issue · comments

The first step in a rescan process is the "rollback" essentially unconfirming every tx in the wallet's history and rewinding the wallet state back to the rescan point. In a wallet with a lot of TX history, this first step may take a long time. The log may have lots of "Reverting namestate without transaction" and it could take a few seconds before the walletDB height is actually changed. In addition, the flag wdb.rescanning does not get set until this point, meaning there are several seconds in which the wallet is actively reverting, but is not indicating a rescanning state, nor is it blocking conflicting actions.

I think we may want to set the flag right away when rescan() is called.

hsd/lib/wallet/walletdb.js

Lines 486 to 513 in 03a306b

/**
* Rescan blockchain from a given height.
* @private
* @param {Number?} height
* @returns {Promise}
*/
async scan(height) {
if (height == null)
height = this.state.startHeight;
assert((height >>> 0) === height, 'WDB: Must pass in a height.');
await this.rollback(height);
this.logger.info(
'WalletDB is scanning %d blocks.',
this.state.height - height + 1);
const tip = await this.getTip();
try {
this.rescanning = true;
await this.client.rescan(tip.hash);
} finally {
this.rescanning = false;
}
}