Fixed job rebroadcast sending duplicate jobs. Rebroadcasting should work with miners such as bfgminer now.
This commit is contained in:
parent
a4b087cec4
commit
1dee4a5a0a
@ -157,8 +157,8 @@ var pool = Stratum.createPool({
|
||||
job broadcast. */
|
||||
"txRefreshInterval": 20000,
|
||||
|
||||
/* Some miner software is bugged and will consider the pool offline if it doesn't receive
|
||||
anything for around a minute, so every time we broadcast jobs, set a timeout to rebroadcast
|
||||
/* Some miner apps will consider the pool dead/offline if it doesn't receive anything new jobs
|
||||
for around a minute, so every time we broadcast jobs, set a timeout to rebroadcast
|
||||
in this many seconds unless we find a new job. Set to zero or remove to disable this. */
|
||||
"jobRebroadcastTimeout": 55,
|
||||
|
||||
|
||||
@ -94,6 +94,25 @@ var JobManager = module.exports = function JobManager(maxDifficulty, options){
|
||||
}
|
||||
})();
|
||||
|
||||
this.updateCurrentJob = function(publicKey){
|
||||
var tmpBlockTemplate = new blockTemplate(
|
||||
maxDifficulty,
|
||||
jobCounter.next(),
|
||||
_this.currentJob.rpcData,
|
||||
publicKey,
|
||||
_this.extraNoncePlaceholder,
|
||||
options.coin.reward,
|
||||
options.coin.txMessages
|
||||
);
|
||||
|
||||
_this.currentJob = tmpBlockTemplate;
|
||||
|
||||
_this.emit('updatedBlock', tmpBlockTemplate, true);
|
||||
|
||||
_this.validJobs[tmpBlockTemplate.jobId] = tmpBlockTemplate;
|
||||
|
||||
};
|
||||
|
||||
//returns true if processed a new block
|
||||
this.processTemplate = function(rpcData, publicKey){
|
||||
|
||||
|
||||
@ -268,13 +268,11 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
_this.jobManager.on('newBlock', function(blockTemplate){
|
||||
//Check if stratumServer has been initialized yet
|
||||
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
||||
//emitLog('Detected new block');
|
||||
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
||||
}
|
||||
}).on('updatedBlock', function(blockTemplate){
|
||||
//Check if stratumServer has been initialized yet
|
||||
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
||||
//emitLog('Detected updated block transactions');
|
||||
var job = blockTemplate.getJobParams();
|
||||
job[8] = false;
|
||||
_this.stratumServer.broadcastMiningJobs(job);
|
||||
@ -532,15 +530,19 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
|
||||
|
||||
|
||||
|
||||
function StartStratumServer(finishedCallback){
|
||||
_this.stratumServer = new stratum.Server(options, authorizeFn);
|
||||
|
||||
_this.stratumServer.on('started', function(){
|
||||
options.initStats.stratumPorts = Object.keys(options.ports);
|
||||
_this.stratumServer.broadcastMiningJobs(_this.jobManager.currentJob.getJobParams());
|
||||
finishedCallback();
|
||||
_this.emit('started');
|
||||
|
||||
}).on('broadcastTimeout', function(){
|
||||
emitLog('No new work for ' + options.jobRebroadcastTimeout + ' seconds - updating & rebroadcasting current job');
|
||||
_this.jobManager.updateCurrentJob(options.publicKeyBuffer);
|
||||
|
||||
}).on('client.connected', function(client){
|
||||
if (typeof(_this.varDiff[client.socket.localPort]) !== 'undefined') {
|
||||
_this.varDiff[client.socket.localPort].manageClient(client);
|
||||
|
||||
@ -380,33 +380,19 @@ var StratumServer = exports.Server = function StratumServer(options, authorizeFn
|
||||
};
|
||||
|
||||
|
||||
|
||||
function SetupBroadcasting(){
|
||||
|
||||
var broadcastJobs = function(jobParams){
|
||||
for (var clientId in stratumClients) {
|
||||
var client = stratumClients[clientId];
|
||||
client.sendMiningJob(jobParams);
|
||||
}
|
||||
};
|
||||
|
||||
if (isNaN(options.jobRebroadcastTimeout) || options.jobRebroadcastTimeout <= 0){
|
||||
_this.broadcastMiningJobs = broadcastJobs;
|
||||
this.broadcastMiningJobs = function(jobParams){
|
||||
for (var clientId in stratumClients) {
|
||||
var client = stratumClients[clientId];
|
||||
client.sendMiningJob(jobParams);
|
||||
}
|
||||
else{
|
||||
/* Some miners will consider the pool dead if it doesn't receive a job for around a minute.
|
||||
So every time we broadcast jobs, set a timeout to rebroadcast in X seconds unless cleared. */
|
||||
_this.broadcastMiningJobs = function(jobParams){
|
||||
broadcastJobs(jobParams);
|
||||
clearTimeout(rebroadcastTimeout);
|
||||
rebroadcastTimeout = setTimeout(function(){
|
||||
var resendParams = jobParams;
|
||||
resendParams[8] = false;
|
||||
_this.broadcastMiningJobs(resendParams);
|
||||
}, options.jobRebroadcastTimeout * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Some miners will consider the pool dead if it doesn't receive a job for around a minute.
|
||||
So every time we broadcast jobs, set a timeout to rebroadcast in X seconds unless cleared. */
|
||||
clearTimeout(rebroadcastTimeout);
|
||||
rebroadcastTimeout = setTimeout(function(){
|
||||
_this.emit('broadcastTimeout');
|
||||
}, options.jobRebroadcastTimeout * 1000);
|
||||
};
|
||||
|
||||
|
||||
|
||||
(function init(){
|
||||
@ -423,7 +409,7 @@ var StratumServer = exports.Server = function StratumServer(options, authorizeFn
|
||||
}
|
||||
|
||||
|
||||
SetupBroadcasting();
|
||||
//SetupBroadcasting();
|
||||
|
||||
|
||||
var serversStarted = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user