From 36671d02ed0d4ba6d84548653c43b985fe246ace Mon Sep 17 00:00:00 2001 From: ohryan Date: Fri, 17 Jul 2020 20:03:07 -0700 Subject: [PATCH] pull loop variable outside for reassignment --- lib/blockchain/chain.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 }