diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 4e5f53e8..a86e3055 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -969,24 +969,27 @@ class Chain extends AsyncEmitter { if (tip.height - fork.height >= this.network.nlrLimit) { if (this.network.nlrLimit !== 0) { this.logger.warning( - 'NLR Activated. Preventing reorganization: current=%h(%d) competitor=%h(%d) fork=%h(%d) reorg_size=%d', + 'NLR Activated. Preventing reorganization: current=%h(%d) competitor=%h(%d) fork=%h(%d) reorg_size=%d nlr=%d', tip.hash, tip.height, competitor.hash, competitor.height, fork.hash, fork.height, - tip.height - fork.height + tip.height - fork.height, + this.network.nlrLimit ); + let indexWalk = competitor + // mark invalid_child from tip of fork to first block of fork - while (competitor.height !== fork.height + 1) { - const previous = await this.getPrevious(competitor) - await this.invalidate(previous.hash) + while (indexWalk.height !== fork.height + 1) { + indexWalk = await this.getPrevious(indexWalk) + await this.invalidate(indexWalk.hash) } // check - assert.equal(await this.getPrevious(competitor), fork, 'nlr invalidation down to the fork') + assert.equal(await this.getPrevious(indexWalk), fork, 'nlr invalidation down to the fork') return true }