From b4784b1d9fa1a4e23146aa188f95e24f676c0b45 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 7 May 2014 11:56:16 -0600 Subject: [PATCH] Removed "txRefreshInterval" option as its function is now replaced with "jobRebroadcastTimeout" --- README.md | 3 --- lib/jobManager.js | 59 +++++++++++++++-------------------------------- lib/pool.js | 17 ++++++++------ 3 files changed, 29 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 1f95100..7e16e18 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/jobManager.js b/lib/jobManager.js index af27bc0..3c9aab2 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -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; }; diff --git a/lib/pool.js b/lib/pool.js index 50efab7..d9d7cf5 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -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') {