Removed "txRefreshInterval" option as its function is now replaced with "jobRebroadcastTimeout"

This commit is contained in:
Matt 2014-05-07 11:56:16 -06:00
parent b24151729d
commit b4784b1d9f
3 changed files with 29 additions and 50 deletions

View File

@ -177,9 +177,6 @@ var pool = Stratum.createPool({
"blockRefreshInterval": 1000, //How often to poll RPC daemons for new blocks, in milliseconds "blockRefreshInterval": 1000, //How often to poll RPC daemons for new blocks, in milliseconds
/* How many milliseconds should have passed before new block transactions will trigger a new
job broadcast. */
"txRefreshInterval": 20000,
/* Some miner apps will consider the pool dead/offline if it doesn't receive anything new jobs /* 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 for around a minute, so every time we broadcast jobs, set a timeout to rebroadcast

View File

@ -64,8 +64,6 @@ var JobManager = module.exports = function JobManager(options){
this.currentJob; this.currentJob;
this.validJobs = {}; this.validJobs = {};
var lastTransactionUpdateCheck = Date.now();
var hashDigest = algos[options.coin.algorithm].hash(options.coin); var hashDigest = algos[options.coin.algorithm].hash(options.coin);
var coinbaseHasher = (function(){ var coinbaseHasher = (function(){
@ -109,10 +107,11 @@ var JobManager = module.exports = function JobManager(options){
} }
})(); })();
this.updateCurrentJob = function(){ this.updateCurrentJob = function(rpcData){
var tmpBlockTemplate = new blockTemplate( var tmpBlockTemplate = new blockTemplate(
jobCounter.next(), jobCounter.next(),
_this.currentJob.rpcData, rpcData,
options.poolAddressScript, options.poolAddressScript,
_this.extraNoncePlaceholder, _this.extraNoncePlaceholder,
options.coin.reward, options.coin.reward,
@ -139,50 +138,30 @@ var JobManager = module.exports = function JobManager(options){
//If new block is outdated/out-of-sync than return //If new block is outdated/out-of-sync than return
if (rpcData.height < _this.currentJob.rpcData.height) if (rpcData.height < _this.currentJob.rpcData.height)
return; return false;
} }
/* If block isn't new, lets see if the transactions have updated */ if (!isNewBlock) return false;
var updatedTransactions = !isNewBlock &&
(_this.currentJob.rpcData.transactions.length != rpcData.transactions.length);
if (updatedTransactions && (Date.now() - lastTransactionUpdateCheck <= options.txRefreshInterval)){ var tmpBlockTemplate = new blockTemplate(
updatedTransactions = false; jobCounter.next(),
} rpcData,
options.poolAddressScript,
_this.extraNoncePlaceholder,
options.coin.reward,
options.coin.txMessages,
options.recipients
);
this.currentJob = tmpBlockTemplate;
//Update current job if new block or new transactions this.validJobs = {};
if (isNewBlock || updatedTransactions){ _this.emit('newBlock', tmpBlockTemplate);
lastTransactionUpdateCheck = Date.now(); this.validJobs[tmpBlockTemplate.jobId] = tmpBlockTemplate;
var tmpBlockTemplate = new blockTemplate( return true;
jobCounter.next(),
rpcData,
options.poolAddressScript,
_this.extraNoncePlaceholder,
options.coin.reward,
options.coin.txMessages,
options.recipients
);
this.currentJob = tmpBlockTemplate;
if (isNewBlock){
//clear old jobs if new blocks
this.validJobs = {};
_this.emit('newBlock', tmpBlockTemplate);
}
else{
//emit when transactions have updated
_this.emit('updatedBlock', tmpBlockTemplate, true);
}
this.validJobs[tmpBlockTemplate.jobId] = tmpBlockTemplate;
}
return isNewBlock;
}; };

View File

@ -8,10 +8,10 @@ var stratum = require('./stratum.js');
var jobManager = require('./jobManager.js'); var jobManager = require('./jobManager.js');
var util = require('./util.js'); var util = require('./util.js');
process.on('uncaughtException', function(err) { /*process.on('uncaughtException', function(err) {
console.log(err.stack); console.log(err.stack);
throw err; throw err;
}); });*/
var pool = module.exports = function pool(options, authorizeFn){ var pool = module.exports = function pool(options, authorizeFn){
@ -112,7 +112,6 @@ var pool = module.exports = function pool(options, authorizeFn){
if (typeof options.blockRefreshInterval === "number" && options.blockRefreshInterval > 0) if (typeof options.blockRefreshInterval === "number" && options.blockRefreshInterval > 0)
infoLines.push('Block polling every:\t' + options.blockRefreshInterval + ' ms'); infoLines.push('Block polling every:\t' + options.blockRefreshInterval + ' ms');
emitSpecialLog(infoLines.join('\n\t\t\t\t\t\t')); emitSpecialLog(infoLines.join('\n\t\t\t\t\t\t'));
} }
@ -294,12 +293,12 @@ 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 (_this.stratumServer) {
_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 (_this.stratumServer) {
var job = blockTemplate.getJobParams(); var job = blockTemplate.getJobParams();
job[8] = false; job[8] = false;
_this.stratumServer.broadcastMiningJobs(job); _this.stratumServer.broadcastMiningJobs(job);
@ -459,8 +458,12 @@ var pool = module.exports = function pool(options, authorizeFn){
_this.emit('started'); _this.emit('started');
}).on('broadcastTimeout', function(){ }).on('broadcastTimeout', function(){
emitLog('No new work for ' + options.jobRebroadcastTimeout + ' seconds - updating & rebroadcasting current job'); emitLog('No new blocks for ' + options.jobRebroadcastTimeout + ' seconds - updating transactions & rebroadcasting work');
_this.jobManager.updateCurrentJob();
GetBlockTemplate(function(error, rpcData, processedBlock){
if (error || processedBlock) return;
_this.jobManager.updateCurrentJob(rpcData);
});
}).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') {