Staking and mining timeing improvements

This commit is contained in:
Michael Toutonghi
2018-08-09 18:04:19 -07:00
parent 049e890a79
commit bf9c36f4ed

View File

@@ -850,10 +850,14 @@ void static VerusStaker(CWallet *pwallet)
break; break;
} }
SetThreadPriority(THREAD_PRIORITY_LOWEST);
// try a nice clean peer connection to start // try a nice clean peer connection to start
waitForPeers(chainparams); CBlockIndex *pindexPrev, *pindexCur;
do {
pindexPrev = chainActive.LastTip();
MilliSleep(5000 + rand() % 5000);
waitForPeers(chainparams);
pindexCur = chainActive.LastTip();
} while (pindexPrev != pindexCur);
{ {
LOCK(cs_main); LOCK(cs_main);
@@ -861,14 +865,10 @@ void static VerusStaker(CWallet *pwallet)
//fprintf(stderr,"Staking height %d for %s\n", chainActive.Tip()->nHeight + 1, ASSETCHAINS_SYMBOL); //fprintf(stderr,"Staking height %d for %s\n", chainActive.Tip()->nHeight + 1, ASSETCHAINS_SYMBOL);
} }
miningTimer.start();
try { try {
while (true) while (true)
{ {
miningTimer.stop();
waitForPeers(chainparams); waitForPeers(chainparams);
miningTimer.start();
// Create new block // Create new block
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
@@ -944,8 +944,6 @@ void static VerusStaker(CWallet *pwallet)
continue; continue;
} }
SetThreadPriority(THREAD_PRIORITY_NORMAL);
int32_t unlockTime = komodo_block_unlocktime(Mining_height); int32_t unlockTime = komodo_block_unlocktime(Mining_height);
int64_t subsidy = (int64_t)(pblock->vtx[0].vout[0].nValue); int64_t subsidy = (int64_t)(pblock->vtx[0].vout[0].nValue);
@@ -973,9 +971,8 @@ void static VerusStaker(CWallet *pwallet)
// Check for stop or if block needs to be rebuilt // Check for stop or if block needs to be rebuilt
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
SetThreadPriority(THREAD_PRIORITY_LOWEST);
sleep(5); sleep(3);
// In regression test mode, stop mining after a block is found. // In regression test mode, stop mining after a block is found.
if (chainparams.MineBlocksOnDemand()) { if (chainparams.MineBlocksOnDemand()) {
@@ -985,17 +982,14 @@ void static VerusStaker(CWallet *pwallet)
} }
catch (const boost::thread_interrupted&) catch (const boost::thread_interrupted&)
{ {
miningTimer.stop();
LogPrintf("VerusStaker terminated\n"); LogPrintf("VerusStaker terminated\n");
throw; throw;
} }
catch (const std::runtime_error &e) catch (const std::runtime_error &e)
{ {
miningTimer.stop();
LogPrintf("VerusStaker runtime error: %s\n", e.what()); LogPrintf("VerusStaker runtime error: %s\n", e.what());
return; return;
} }
miningTimer.stop();
} }
void static BitcoinMiner_noeq(CWallet *pwallet) void static BitcoinMiner_noeq(CWallet *pwallet)
@@ -1028,11 +1022,11 @@ void static BitcoinMiner_noeq()
SetThreadPriority(THREAD_PRIORITY_LOWEST); SetThreadPriority(THREAD_PRIORITY_LOWEST);
// try a nice clean peer connection to start // try a nice clean peer connection to start
waitForPeers(chainparams);
CBlockIndex *pindexPrev, *pindexCur; CBlockIndex *pindexPrev, *pindexCur;
do { do {
pindexPrev = chainActive.LastTip(); pindexPrev = chainActive.LastTip();
MilliSleep(5000 + rand() % 5000); MilliSleep(5000 + rand() % 5000);
waitForPeers(chainparams);
pindexCur = chainActive.LastTip(); pindexCur = chainActive.LastTip();
} while (pindexPrev != pindexCur); } while (pindexPrev != pindexCur);