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. */
|
job broadcast. */
|
||||||
"txRefreshInterval": 20000,
|
"txRefreshInterval": 20000,
|
||||||
|
|
||||||
/* Some miner software is bugged and will consider the pool offline if it doesn't receive
|
/* Some miner apps will consider the pool dead/offline if it doesn't receive anything new jobs
|
||||||
anything for around a minute, so every time we broadcast jobs, set a timeout to rebroadcast
|
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. */
|
in this many seconds unless we find a new job. Set to zero or remove to disable this. */
|
||||||
"jobRebroadcastTimeout": 55,
|
"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
|
//returns true if processed a new block
|
||||||
this.processTemplate = function(rpcData, publicKey){
|
this.processTemplate = function(rpcData, publicKey){
|
||||||
|
|
||||||
|
|||||||
@ -268,13 +268,11 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
_this.jobManager.on('newBlock', function(blockTemplate){
|
_this.jobManager.on('newBlock', function(blockTemplate){
|
||||||
//Check if stratumServer has been initialized yet
|
//Check if stratumServer has been initialized yet
|
||||||
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
||||||
//emitLog('Detected new block');
|
|
||||||
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
||||||
}
|
}
|
||||||
}).on('updatedBlock', function(blockTemplate){
|
}).on('updatedBlock', function(blockTemplate){
|
||||||
//Check if stratumServer has been initialized yet
|
//Check if stratumServer has been initialized yet
|
||||||
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
||||||
//emitLog('Detected updated block transactions');
|
|
||||||
var job = blockTemplate.getJobParams();
|
var job = blockTemplate.getJobParams();
|
||||||
job[8] = false;
|
job[8] = false;
|
||||||
_this.stratumServer.broadcastMiningJobs(job);
|
_this.stratumServer.broadcastMiningJobs(job);
|
||||||
@ -532,15 +530,19 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function StartStratumServer(finishedCallback){
|
function StartStratumServer(finishedCallback){
|
||||||
_this.stratumServer = new stratum.Server(options, authorizeFn);
|
_this.stratumServer = new stratum.Server(options, authorizeFn);
|
||||||
|
|
||||||
_this.stratumServer.on('started', function(){
|
_this.stratumServer.on('started', function(){
|
||||||
options.initStats.stratumPorts = Object.keys(options.ports);
|
options.initStats.stratumPorts = Object.keys(options.ports);
|
||||||
|
_this.stratumServer.broadcastMiningJobs(_this.jobManager.currentJob.getJobParams());
|
||||||
finishedCallback();
|
finishedCallback();
|
||||||
_this.emit('started');
|
_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){
|
}).on('client.connected', function(client){
|
||||||
if (typeof(_this.varDiff[client.socket.localPort]) !== 'undefined') {
|
if (typeof(_this.varDiff[client.socket.localPort]) !== 'undefined') {
|
||||||
_this.varDiff[client.socket.localPort].manageClient(client);
|
_this.varDiff[client.socket.localPort].manageClient(client);
|
||||||
|
|||||||
@ -380,33 +380,19 @@ var StratumServer = exports.Server = function StratumServer(options, authorizeFn
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.broadcastMiningJobs = function(jobParams){
|
||||||
function SetupBroadcasting(){
|
for (var clientId in stratumClients) {
|
||||||
|
var client = stratumClients[clientId];
|
||||||
var broadcastJobs = function(jobParams){
|
client.sendMiningJob(jobParams);
|
||||||
for (var clientId in stratumClients) {
|
|
||||||
var client = stratumClients[clientId];
|
|
||||||
client.sendMiningJob(jobParams);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (isNaN(options.jobRebroadcastTimeout) || options.jobRebroadcastTimeout <= 0){
|
|
||||||
_this.broadcastMiningJobs = broadcastJobs;
|
|
||||||
}
|
}
|
||||||
else{
|
/* Some miners will consider the pool dead if it doesn't receive a job for around a minute.
|
||||||
/* 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. */
|
||||||
So every time we broadcast jobs, set a timeout to rebroadcast in X seconds unless cleared. */
|
clearTimeout(rebroadcastTimeout);
|
||||||
_this.broadcastMiningJobs = function(jobParams){
|
rebroadcastTimeout = setTimeout(function(){
|
||||||
broadcastJobs(jobParams);
|
_this.emit('broadcastTimeout');
|
||||||
clearTimeout(rebroadcastTimeout);
|
}, options.jobRebroadcastTimeout * 1000);
|
||||||
rebroadcastTimeout = setTimeout(function(){
|
};
|
||||||
var resendParams = jobParams;
|
|
||||||
resendParams[8] = false;
|
|
||||||
_this.broadcastMiningJobs(resendParams);
|
|
||||||
}, options.jobRebroadcastTimeout * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
(function init(){
|
(function init(){
|
||||||
@ -423,7 +409,7 @@ var StratumServer = exports.Server = function StratumServer(options, authorizeFn
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SetupBroadcasting();
|
//SetupBroadcasting();
|
||||||
|
|
||||||
|
|
||||||
var serversStarted = 0;
|
var serversStarted = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user