From 52f00c8fe2640676352d24dda55aa9357f5f8951 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 22 Aug 2016 18:00:38 -0700 Subject: [PATCH] walletdb: lock during rescan. --- lib/bcoin/chaindb.js | 3 --- lib/bcoin/walletdb.js | 13 +++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index 4e9906e2..5f51d13a 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -1372,9 +1372,6 @@ ChainDB.prototype.scan = function scan(start, filter, iter, callback) { } } - if (txs.length === 0) - return self.getNextHash(entry.hash, next); - iter(entry, txs, function(err) { if (err) return next(err); diff --git a/lib/bcoin/walletdb.js b/lib/bcoin/walletdb.js index a5a97226..c7a13550 100644 --- a/lib/bcoin/walletdb.js +++ b/lib/bcoin/walletdb.js @@ -1135,7 +1135,12 @@ WalletDB.prototype.rescan = function rescan(chaindb, height, callback) { } if (height == null) - height = self.height; + height = this.height; + + callback = this._lockTX(rescan, [chaindb, height, callback]); + + if (!callback) + return; this.getAddressHashes(function(err, hashes) { if (err) @@ -1144,7 +1149,7 @@ WalletDB.prototype.rescan = function rescan(chaindb, height, callback) { self.logger.info('Scanning for %d addresses.', hashes.length); chaindb.scan(height, hashes, function(block, txs, next) { - self.addBlock(block, txs, next); + self.addBlock(block, txs, next, true); }, callback); }); }; @@ -1395,11 +1400,11 @@ WalletDB.prototype.getWalletsByTX = function getWalletsByTX(hash, callback) { * @param {Function} callback */ -WalletDB.prototype.addBlock = function addBlock(entry, txs, callback) { +WalletDB.prototype.addBlock = function addBlock(entry, txs, callback, force) { var self = this; var block, matches, hash; - callback = this._lockTX(addBlock, [entry, txs, callback]); + callback = this._lockTX(addBlock, [entry, txs, callback], force); if (!callback) return;