diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index f579b044..199a47d8 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -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); diff --git a/lib/bcoin/fullchain.js b/lib/bcoin/fullchain.js index 6d585354..8350010e 100644 --- a/lib/bcoin/fullchain.js +++ b/lib/bcoin/fullchain.js @@ -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; } diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 9b5dd87b..67f5882b 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -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);