getLocator again.

This commit is contained in:
Christopher Jeffrey 2016-05-06 13:07:58 -07:00
parent c5181c272b
commit 9301cf89a2
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1500,8 +1500,6 @@ Chain.prototype.add = function add(block, callback, force) {
} }
} }
assert(prev);
// Explanation: we try to keep as much data // Explanation: we try to keep as much data
// off the javascript heap as possible. Blocks // off the javascript heap as possible. Blocks
// in the future may be 8mb or 20mb, who knows. // 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) if (!start || !end)
return callback(null, hashes); return callback(null, hashes);
utils.forRange(start.height, end.height + 1, function(i, next) { utils.forRangeSerial(start.height, end.height + 1, function(i, next) {
self.db.get(i, function(err, entry) { self.db.getHash(i, function(err, hash) {
if (err) if (err)
return next(err); return next(err);
if (!entry) if (!hash)
return next(new Error('No entry for hash range.')); return next(new Error('No entry for hash range.'));
hashes[i - start.height] = entry.hash; hashes.push(hash);
next(); next();
}); });
@ -1923,24 +1921,6 @@ Chain.prototype.getLocator = function getLocator(start, callback, force) {
callback = utils.wrap(callback, unlock); 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) if (start == null)
start = this.tip.hash; start = this.tip.hash;
@ -1980,7 +1960,21 @@ Chain.prototype.getLocator = function getLocator(start, callback, force) {
if (hashes.length > 10) if (hashes.length > 10)
step *= 2; 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); })(null, entry);
}); });
}); });