diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 2c6bface..ac7726b4 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -1500,8 +1500,6 @@ Chain.prototype.add = function add(block, callback, force) { } } - assert(prev); - // Explanation: we try to keep as much data // off the javascript heap as possible. Blocks // in the future may be 8mb or 20mb, who knows. @@ -1882,15 +1880,15 @@ Chain.prototype.getHashRange = function getHashRange(start, end, callback) { if (!start || !end) return callback(null, hashes); - utils.forRange(start.height, end.height + 1, function(i, next) { - self.db.get(i, function(err, entry) { + utils.forRangeSerial(start.height, end.height + 1, function(i, next) { + self.db.getHash(i, function(err, hash) { if (err) return next(err); - if (!entry) + if (!hash) return next(new Error('No entry for hash range.')); - hashes[i - start.height] = entry.hash; + hashes.push(hash); next(); }); @@ -1923,24 +1921,6 @@ Chain.prototype.getLocator = function getLocator(start, callback, force) { callback = utils.wrap(callback, unlock); - function getAncestor(entry, height, main, callback) { - if (height === 0) - return callback(null, { hash: network.genesis.hash, height: 0 }); - - if (!main) - return entry.getAncestorByHeight(height, callback); - - return self.db.getHash(height, function(err, hash) { - if (err) - return callback(err); - - if (!hash) - return callback(); - - return callback(null, { hash: hash, height: height }); - }); - } - if (start == null) start = this.tip.hash; @@ -1980,7 +1960,21 @@ Chain.prototype.getLocator = function getLocator(start, callback, force) { if (hashes.length > 10) step *= 2; - getAncestor(entry, height, main, next); + if (height === 0) + return next(null, { hash: network.genesis.hash, height: 0 }); + + if (!main) + return entry.getAncestorByHeight(height, next); + + self.db.getHash(height, function(err, hash) { + if (err) + return next(err); + + if (!hash) + return next(); + + next(null, { hash: hash, height: height }); + }); })(null, entry); }); });