chain: improve locatorHashes.

This commit is contained in:
Christopher Jeffrey 2016-01-04 16:33:52 -08:00
parent 74b1562a87
commit 2c3edd50aa
3 changed files with 20 additions and 10 deletions

View File

@ -641,16 +641,19 @@ Chain.prototype.locatorHashes = function locatorHashes(obj) {
if (obj != null) {
if (typeof obj === 'string') {
start = this.byHash(obj);
if (!start)
return [obj];
if (start) {
start = start.index;
} else {
// return [obj];
start = obj;
}
} else if (typeof obj === 'number') {
start = this.byHeight(obj);
if (start)
start = start.index;
}
assert(start);
if (start)
start = start.index;
assert(start != null);
}
return bcoin.fullChain.prototype.locatorHashes.call(this, start);

View File

@ -432,8 +432,11 @@ Chain.prototype.locatorHashes = function locatorHashes(start) {
if (typeof start === 'string') {
top = this.index.heights[start];
if (top == null)
return [start];
if (top == null) {
// return [start];
hashes.push(start);
top = chain.length - 1;
}
} else if (typeof start === 'number') {
top = start;
}

View File

@ -353,8 +353,12 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
}
// Restart the getheaders process
// chain.locatorHashes will return [last.hash('hex')] here for now because
// the headers have not been added to the chain in non-headers-first mode.
// Technically `last` is not indexed yet so
// the locator hashes will not be entirely
// accurate. However, it shouldn't matter
// that much since FindForkInGlobalIndex
// simply tries to find the latest block in
// the peer's chain.
if (last && headers.length === 2000)
peer.loadHeaders(this.chain.locatorHashes(last), null);