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
/* 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
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.validJobs = {};
var lastTransactionUpdateCheck = Date.now();
var hashDigest = algos[options.coin.algorithm].hash(options.coin);
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(
jobCounter.next(),
_this.currentJob.rpcData,
rpcData,
options.poolAddressScript,
_this.extraNoncePlaceholder,
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 (rpcData.height < _this.currentJob.rpcData.height)
return;
return false;
}
/* If block isn't new, lets see if the transactions have updated */
var updatedTransactions = !isNewBlock &&
(_this.currentJob.rpcData.transactions.length != rpcData.transactions.length);
if (!isNewBlock) return false;
if (updatedTransactions && (Date.now() - lastTransactionUpdateCheck <= options.txRefreshInterval)){
updatedTransactions = false;
}
var tmpBlockTemplate = new blockTemplate(
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
if (isNewBlock || updatedTransactions){
this.validJobs = {};
_this.emit('newBlock', tmpBlockTemplate);
lastTransactionUpdateCheck = Date.now();
this.validJobs[tmpBlockTemplate.jobId] = tmpBlockTemplate;
var tmpBlockTemplate = new blockTemplate(
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;
return true;
};

View File

@ -8,10 +8,10 @@ var stratum = require('./stratum.js');
var jobManager = require('./jobManager.js');
var util = require('./util.js');
process.on('uncaughtException', function(err) {
/*process.on('uncaughtException', function(err) {
console.log(err.stack);
throw err;
});
});*/
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)
infoLines.push('Block polling every:\t' + options.blockRefreshInterval + ' ms');
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){
//Check if stratumServer has been initialized yet
if ( typeof(_this.stratumServer ) !== 'undefined') {
if (_this.stratumServer) {
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
}
}).on('updatedBlock', function(blockTemplate){
//Check if stratumServer has been initialized yet
if ( typeof(_this.stratumServer ) !== 'undefined') {
if (_this.stratumServer) {
var job = blockTemplate.getJobParams();
job[8] = false;
_this.stratumServer.broadcastMiningJobs(job);
@ -459,8 +458,12 @@ var pool = module.exports = function pool(options, authorizeFn){
_this.emit('started');
}).on('broadcastTimeout', function(){
emitLog('No new work for ' + options.jobRebroadcastTimeout + ' seconds - updating & rebroadcasting current job');
_this.jobManager.updateCurrentJob();
emitLog('No new blocks for ' + options.jobRebroadcastTimeout + ' seconds - updating transactions & rebroadcasting work');
GetBlockTemplate(function(error, rpcData, processedBlock){
if (error || processedBlock) return;
_this.jobManager.updateCurrentJob(rpcData);
});
}).on('client.connected', function(client){
if (typeof(_this.varDiff[client.socket.localPort]) !== 'undefined') {