diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 1f3d1f68..8d0d839d 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -1766,7 +1766,13 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) { hash = this.orphan.bmap[hash].prevBlock; } - return root; + if (!root) + return; + + return { + root: root, + soil: this.orphan.bmap[root].prevBlock + }; }; Chain.prototype.getHeight = function getHeight(hash) { diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 496a7df2..0ed34012 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -262,35 +262,30 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan) { assert(orphan); this.chain.onFlush(function() { self.chain.getLocatorAsync(top, function(err, locator) { - var root, soil; - if (err) throw err; - root = self.chain.getOrphanRoot(orphan); + orphan = self.chain.getOrphanRoot(orphan); // Was probably resolved. - if (!root) { + if (!orphan) { utils.debug('Orphan root was already resolved.'); return; } - // Get the block that would resolve the chain. - soil = self.chain.getOrphan(root).prevBlock; - // If we're already processing the block // that would resolve this, ignore. - if (self.request.map[soil] || self.chain.hasPending(soil)) { + if (self.request.map[orphan.soil] || self.chain.hasPending(orphan.soil)) { utils.debug('Already processing orphan "soil".'); return; } - if (self.chain.has(soil)) { + if (self.chain.has(orphan.soil)) { utils.debug('Already have orphan "soil". Race condition?'); return; } - peer.getBlocks(locator, root); + peer.getBlocks(locator, orphan.root); }); }); };