Check for updates with block transactions
This commit is contained in:
parent
a8653e7357
commit
37ab36f776
@ -87,7 +87,8 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
|
|||||||
util.varIntBuffer(this.rpcData.transactions.length + 1),
|
util.varIntBuffer(this.rpcData.transactions.length + 1),
|
||||||
coinbase,
|
coinbase,
|
||||||
this.transactionData,
|
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] : [])
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -122,9 +122,14 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size;
|
this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size;
|
||||||
|
|
||||||
this.currentJob;
|
this.currentJob;
|
||||||
|
this.validJobs = {};
|
||||||
|
|
||||||
this.processTemplate = function(rpcData, publicKey){
|
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(
|
var tmpBlockTemplate = new blockTemplate(
|
||||||
jobCounter.next(),
|
jobCounter.next(),
|
||||||
@ -135,9 +140,18 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
options.txMessages
|
options.txMessages
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.currentJob = tmpBlockTemplate;
|
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)
|
if (extraNonce2.length / 2 !== _this.extraNonce2Size)
|
||||||
return shareError([20, 'incorrect size of extranonce2']);
|
return shareError([20, 'incorrect size of extranonce2']);
|
||||||
|
|
||||||
var job = this.currentJob;
|
var job = this.validJobs[jobId];
|
||||||
|
|
||||||
if (typeof job === 'undefined' || job.jobId != jobId ) {
|
if (typeof job === 'undefined' || job.jobId != jobId ) {
|
||||||
return shareError([21, 'job not found']);
|
return shareError([21, 'job not found']);
|
||||||
|
|||||||
@ -151,6 +151,14 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
emitLog('system', 'Detected new block');
|
emitLog('system', 'Detected new block');
|
||||||
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
_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){
|
}).on('share', function(shareData, blockHex){
|
||||||
var isValidShare = !shareData.error;
|
var isValidShare = !shareData.error;
|
||||||
var isValidBlock = !!blockHex;
|
var isValidBlock = !!blockHex;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user