From 95bd78ca7f6e6fdc57e212ea5f24a26d528b45ff Mon Sep 17 00:00:00 2001 From: perl5577 Date: Tue, 6 Jan 2015 00:54:39 +0100 Subject: [PATCH] Detect new branch when reoganize Need more optimisation for more quickly test --- lib/pool.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index c464d1301..e520ff6a0 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -112,6 +112,8 @@ function BlockTemplate(template){ this.reserveOffset = template.reserved_offset; this.buffer = new Buffer(this.blob, 'hex'); instanceId.copy(this.buffer, this.reserveOffset + 4, 0, 3); + this.previous_hash = new Buffer(32); + this.buffer.copy(this.previous_hash,0,7,39); this.extraNonce = 0; } BlockTemplate.prototype = { @@ -141,7 +143,10 @@ function jobRefresh(loop, callback){ callback(false); return; } - if (!currentBlockTemplate || result.height > currentBlockTemplate.height){ + var buffer = new Buffer(result.blocktemplate_blob, 'hex'); + var previous_hash = new Buffer(32); + buffer.copy(previous_hash,0,7,39); + if (!currentBlockTemplate || ( previous_hash.toString('hex') != currentBlockTemplate.previous_hash.toString('hex') && result.height >= currentBlockTemplate.height )) log('info', logSystem, 'New block to mine at height %d w/ difficulty of %d', [result.height, result.difficulty]); processBlockTemplate(result); }