Check for updates with block transactions

This commit is contained in:
Matt 2014-02-25 14:19:11 -07:00
parent a8653e7357
commit 37ab36f776
3 changed files with 28 additions and 5 deletions

View File

@ -87,7 +87,8 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
util.varIntBuffer(this.rpcData.transactions.length + 1),
coinbase,
this.transactionData,
new Buffer(reward === 'POS' ? [0] : []) //POS coins require a zero byte appended to block which the daemon replaces with the signature
//POS coins require a zero byte appended to block which the daemon replaces with the signature
new Buffer(reward === 'POS' ? [0] : [])
]);
};

View File

@ -122,9 +122,14 @@ var JobManager = module.exports = function JobManager(options){
this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size;
this.currentJob;
this.validJobs = {};
this.processTemplate = function(rpcData, publicKey){
if (CheckNewIfNewBlock(rpcData.previousblockhash)){
var isNewBlock = CheckNewIfNewBlock(rpcData.previousblockhash);
//Update current job if new block or new transactions
if (isNewBlock || _this.currentJob.rpcData.transactions.length != rpcData.transactions.length){
var tmpBlockTemplate = new blockTemplate(
jobCounter.next(),
@ -135,9 +140,18 @@ var JobManager = module.exports = function JobManager(options){
options.txMessages
);
this.currentJob = tmpBlockTemplate;
_this.emit('newBlock', tmpBlockTemplate);
if (isNewBlock){
//clear old jobs if new blocks
this.validJobs = {};
_this.emit('newBlock', tmpBlockTemplate);
}
else
_this.emit('updatedBlock', tmpBlockTemplate, true);
this.validJobs[tmpBlockTemplate.jobId] = tmpBlockTemplate;
}
};
@ -158,7 +172,7 @@ var JobManager = module.exports = function JobManager(options){
if (extraNonce2.length / 2 !== _this.extraNonce2Size)
return shareError([20, 'incorrect size of extranonce2']);
var job = this.currentJob;
var job = this.validJobs[jobId];
if (typeof job === 'undefined' || job.jobId != jobId ) {
return shareError([21, 'job not found']);

View File

@ -151,6 +151,14 @@ var pool = module.exports = function pool(options, authorizeFn){
emitLog('system', '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('system', 'Detected updated block transactions');
var job = blockTemplate.getJobParams();
job[8] = false;
_this.stratumServer.broadcastMiningJobs(job);
}
}).on('share', function(shareData, blockHex){
var isValidShare = !shareData.error;
var isValidBlock = !!blockHex;