diff --git a/lib/mining/cpuminer.js b/lib/mining/cpuminer.js index 13511f47..f65e4d9a 100644 --- a/lib/mining/cpuminer.js +++ b/lib/mining/cpuminer.js @@ -74,14 +74,17 @@ CPUMiner.prototype._init = function _init() { self.logger.debug('Raw: %s', block.toRaw().toString('hex')); }); - this.on('status', function(stat) { + this.on('status', function(job, hashes, hashrate) { + var attempt = job.attempt; + var tip = util.revHex(attempt.prevBlock); + self.logger.info( - 'CPUMiner: hashrate=%dkhs hashes=%d target=%d height=%d best=%s', - stat.hashrate / 1000 | 0, - stat.hashes, - stat.target, - stat.height, - stat.best); + 'Miner: hashrate=%dkhs hashes=%d target=%d height=%d best=%s', + Math.floor(hashrate / 1000), + hashes, + attempt.bits, + attempt.height, + tip); }); }; @@ -123,7 +126,7 @@ CPUMiner.prototype._close = co(function* close() { CPUMiner.prototype.start = co(function* start() { var block, entry; - assert(!this.running, 'CPUMiner is already running.'); + assert(!this.running, 'Miner is already running.'); this.running = true; this.stopping = false; @@ -188,8 +191,8 @@ CPUMiner.prototype.start = co(function* start() { */ CPUMiner.prototype.stop = co(function* stop() { - assert(this.running, 'CPUMiner is not running.'); - assert(!this.stopping, 'CPUMiner is already stopping.'); + assert(this.running, 'Miner is not running.'); + assert(!this.stopping, 'Miner is already stopping.'); this.stopping = true; @@ -404,13 +407,7 @@ CPUMiner.prototype.iterate = function iterate(job) { */ CPUMiner.prototype.sendStatus = function sendStatus(job, nonce) { - this.emit('status', { - target: job.attempt.bits, - hashes: job.getHashes(), - hashrate: job.getRate(nonce), - height: job.attempt.height, - best: util.revHex(job.attempt.prevBlock) - }); + this.emit('status', job, job.getHashes(nonce), job.getRate(nonce)); }; /** @@ -500,14 +497,11 @@ CPUJob.prototype.refresh = function refresh() { * Increment the extraNonce. */ -CPUJob.prototype.updateNonce = function() { - // Overflow the nonce and increment the extraNonce. - this.nonce1++; - - // Wrap at 4 bytes. - if (this.nonce1 === 0xffffffff) { - this.nonce1 = 0; - this.nonce2++; +CPUJob.prototype.updateNonce = function updateNonce() { + this.nonce2++; + if (this.nonce2 === 0x100000000) { + this.nonce2 = 0; + this.nonce1++; } }; @@ -515,7 +509,7 @@ CPUJob.prototype.updateNonce = function() { * Destroy the job. */ -CPUJob.prototype.destroy = function() { +CPUJob.prototype.destroy = function destroy() { assert(!this.destroyed, 'Job already destroyed.'); this.destroyed = true; }; @@ -525,8 +519,8 @@ CPUJob.prototype.destroy = function() { * @returns {Number} */ -CPUJob.prototype.getHashes = function() { - return this.iterations * 0xffffffff + this.block.nonce; +CPUJob.prototype.getHashes = function getHashes(nonce) { + return this.iterations * 0xffffffff + nonce; }; /** @@ -534,8 +528,8 @@ CPUJob.prototype.getHashes = function() { * @returns {Number} */ -CPUJob.prototype.getRate = function(nonce) { - return (nonce / (util.now() - this.begin)) | 0; +CPUJob.prototype.getRate = function getRate(nonce) { + return Math.floor(nonce / (util.now() - this.begin)); }; /** @@ -544,7 +538,7 @@ CPUJob.prototype.getRate = function(nonce) { * @param {CoinView} view */ -CPUJob.prototype.addTX = function(tx, view) { +CPUJob.prototype.addTX = function addTX(tx, view) { return this.attempt.addTX(tx, view); }; @@ -555,7 +549,7 @@ CPUJob.prototype.addTX = function(tx, view) { * @param {CoinView?} view */ -CPUJob.prototype.pushTX = function(tx, view) { +CPUJob.prototype.pushTX = function pushTX(tx, view) { return this.attempt.pushTX(tx, view); };