diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index b8508308..9c8f6a8b 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -1437,15 +1437,6 @@ Chain.prototype.add = function add(block, callback, force) { height = !prev ? -1 : prev.height + 1; - // Update the best height based on the coinbase. - // We do this even for orphans (peers will send - // us their highest block during the initial - // getblocks sync, making it an orphan). - if (block.getCoinbaseHeight() > self.bestHeight) { - self.bestHeight = block.getCoinbaseHeight(); - network.height = self.bestHeight; - } - if (height > self.bestHeight) { self.bestHeight = height; network.height = height; @@ -1458,11 +1449,22 @@ Chain.prototype.add = function add(block, callback, force) { self.orphan.size += block.getSize(); self.orphan.map[prevHash] = block; self.orphan.bmap[hash] = block; + + // Update the best height based on the coinbase. + // We do this even for orphans (peers will send + // us their highest block during the initial + // getblocks sync, making it an orphan). + if (block.getCoinbaseHeight() > self.bestHeight) { + self.bestHeight = block.getCoinbaseHeight(); + network.height = self.bestHeight; + } + self.emit('orphan', block, { height: block.getCoinbaseHeight(), hash: hash, seen: false }); + return done(new VerifyError(block, 'invalid', 'bad-prevblk', 0)); }