cpuminer: fixes for job methods.

This commit is contained in:
Christopher Jeffrey 2017-03-11 19:36:59 -08:00
parent 2bd578fbe4
commit ccd89e4f2f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

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