Job handler caching

Caches the last job sent down the wire, and ensures that we can return it, rather than blank.

Fixes #37
master
Alexander Blair 7 years ago
parent f89b709f93
commit 2a782cb3e8

@ -202,6 +202,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
this.valid_miner = true;
this.port = port;
this.portType = portType;
this.incremented = false;
switch (portType) {
case 'pplns':
this.poolTypeEnum = global.protos.POOLTYPE.PPLNS;
@ -320,6 +321,8 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
this.validJobs = global.support.circularBuffer(10);
this.cachedJob = null;
this.invalidShareProto = global.protos.InvalidShare.encode({
paymentAddress: this.address,
paymentID: this.paymentID,
@ -432,12 +435,8 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
};
this.getJob = function () {
if (this.lastBlockHeight === activeBlockTemplate.height && !this.newDiff) {
return {
blob: '',
job_id: '',
target: ''
};
if (this.lastBlockHeight === activeBlockTemplate.height && !this.newDiff && this.cachedJob !== null) {
return this.cachedJob;
}
let blob = activeBlockTemplate.nextBlob();
@ -455,12 +454,12 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
};
this.validJobs.enq(newJob);
return {
this.cachedJob = {
blob: blob,
job_id: newJob.id,
target: target
};
return this.cachedJob;
};
}
}
@ -522,7 +521,13 @@ function processShare(miner, job, blockTemplate, nonce, resultHash) {
}
if (hash.toString('hex') !== resultHash) {
console.error(threadName + "Bad hash from miner " + miner.logString);
miner.newDiff = miner.difficulty + 1;
if (miner.incremented === false){
miner.newDiff = miner.difficulty + 1;
miner.incremented = true;
} else {
miner.newDiff = miner.difficulty - 1;
miner.incremented = false;
}
miner.messageSender('job', miner.getJob());
return false;
}
@ -644,7 +649,13 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) {
if (!blockTemplate) {
console.warn(threadName + 'Block expired, Height: ' + job.height + ' from ' + miner.logString);
miner.newDiff = miner.difficulty + 1;
if (miner.incremented === false){
miner.newDiff = miner.difficulty + 1;
miner.incremented = true;
} else {
miner.newDiff = miner.difficulty - 1;
miner.incremented = false;
}
miner.messageSender('job', miner.getJob());
sendReply('Block expired');
global.database.storeInvalidShare(miner.invalidShareProto);

Loading…
Cancel
Save