fixed scheduling/work promotion issue

master
Thomas Baumbach 2013-08-26 20:50:28 +02:00
parent aedb258905
commit 43962edddc
2 changed files with 26 additions and 9 deletions

View File

@ -4590,6 +4590,8 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int
bool fIncrementPrimorial = true; // increase or decrease primorial factor
CBlock *pblock = NULL;
uint256 old_hash;
unsigned int old_nonce = 0;
try { loop {
while (block_provider == NULL && vNodes.empty())
@ -4611,7 +4613,19 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int
} else if ((pblock = block_provider->getBlock(thread_id)) == NULL) { //server not reachable?
MilliSleep(2000);
continue;
} //else GOT_WORK_WOOHOO!
} else if (old_hash == pblock->GetHeaderHash()) {
if (old_nonce >= 0xffff0000) {
MilliSleep(50);
//TODO: FORCE a new getblock!
if (fDebug && GetBoolArg("-printmining"))
printf("Nothing to do --- uh ih uh ah ah bing bang!!\n");
continue;
} else
pblock->nNonce = old_nonce;
} else {
old_hash = pblock->GetHeaderHash();
old_nonce = 0;
}
if (fDebug && GetBoolArg("-printmining"))
printf("Running PrimecoinMiner with %"PRIszu" transactions in block (%u bytes)\n", pblock->vtx.size(),
@ -4652,8 +4666,10 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int
// Use the hash that passed the tests
break;
}
if (pblock->nNonce >= 0xffff0000)
if (pblock->nNonce >= 0xffff0000) {
old_nonce = 0xffff0000;
continue;
}
// Primecoin: primorial fixed multiplier
mpz_class mpzPrimorial;
unsigned int nRoundTests = 0;
@ -4692,6 +4708,7 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int
else
block_provider->submitBlock(pblock);
SetThreadPriority(THREAD_PRIORITY_LOWEST);
old_nonce = pblock->nNonce + 1;
break;
}
@ -4776,6 +4793,8 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int
}
}
}
old_nonce = pblock->nNonce;
// Check for stop or if block needs to be rebuilt
boost::this_thread::interruption_point();

View File

@ -246,21 +246,19 @@ public:
virtual CBlock* getBlock(unsigned int thread_id) {
if (_longpoll) {
CBlock* block = NULL;
{
boost::unique_lock<boost::shared_mutex> lock(_mutex_getwork);
block = new CBlock((_pblock+thread_id)->GetBlockHeader());
}
boost::unique_lock<boost::shared_mutex> lock(_mutex_getwork);
CBlock* block = NULL;
block = new CBlock((_pblock+thread_id)->GetBlockHeader());
block->nTime = GetAdjustedTime();
std::cout << "[WORKER" << thread_id << "] got_work block=" <<
block->GetHash().ToString().c_str() << std::endl;
block->GetHash().ToString().c_str() << std::endl;
return block;
} else {
if (_pblock != NULL) delete _pblock;
_pblock = new CBlock();
if (!getBlockFromServer(*_pblock, server, port)) return NULL;
std::cout << "[WORKER" << thread_id << "] got_work block=" <<
_pblock->GetHash().ToString().c_str() << std::endl;
_pblock->GetHash().ToString().c_str() << std::endl;
return _pblock;
}
return NULL;