Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working Block Polling for difficulty change in current block #171

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ var JobManager = module.exports = function JobManager(options){

};

//returns true if processed a new block
//returns true if processed a new block OR the current block difficulty has changed
this.processTemplate = function(rpcData){

/* Block is new if A) its the first block we have seen so far or B) the blockhash is different and the
block height is greater than the one we have */
block height is greater than the one we have OR the current block difficulty has changed*/
var isNewBlock = typeof(_this.currentJob) === 'undefined';
if (!isNewBlock && _this.currentJob.rpcData.previousblockhash !== rpcData.previousblockhash){
if (!isNewBlock && ( _this.currentJob.rpcData.previousblockhash !== rpcData.previousblockhash || _this.currentJob.rpcData.bits !== rpcData.bits)){
isNewBlock = true;

//If new block is outdated/out-of-sync than return
Expand Down
5 changes: 4 additions & 1 deletion lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ var pool = module.exports = function pool(options, authorizeFn){
}).on('broadcastTimeout', function(){
emitLog('No new blocks for ' + options.jobRebroadcastTimeout + ' seconds - updating transactions & rebroadcasting work');

// send getblocktemplate to coin daemon to force the update of dynamic difficulty changes in DarkGravityWave algorithm...
_this.daemon.cmd('getblocktemplate', [], function(){});

GetBlockTemplate(function(error, rpcData, processedBlock){
if (error || processedBlock) return;
_this.jobManager.updateCurrentJob(rpcData);
Expand Down Expand Up @@ -568,7 +571,7 @@ var pool = module.exports = function pool(options, authorizeFn){
blockPollingIntervalId = setInterval(function () {
GetBlockTemplate(function(error, result, foundNewBlock){
if (foundNewBlock)
emitLog('Block notification via RPC polling');
emitLog('Block notification or Block difficulty change via RPC polling');
});
}, pollingInterval);
}
Expand Down