Merge pull request #102 from miketout/dev

Staking and mining improvements
This commit is contained in:
miketout
2018-08-09 18:05:45 -07:00
committed by GitHub
2 changed files with 7 additions and 29 deletions

View File

@@ -760,7 +760,7 @@ uint32_t komodo_chainactive_timestamp()
CBlockIndex *komodo_chainactive(int32_t height) CBlockIndex *komodo_chainactive(int32_t height)
{ {
if ( chainActive.Tip() != 0 ) if ( chainActive.LastTip() != 0 )
{ {
if ( height <= chainActive.LastTip()->nHeight ) if ( height <= chainActive.LastTip()->nHeight )
return(chainActive[height]); return(chainActive[height]);

View File

@@ -850,41 +850,25 @@ 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;
// try a nice clean peer connection to start
waitForPeers(chainparams);
CBlockIndex* pindexPrev, *pindexCur;
do { do {
{ pindexPrev = chainActive.LastTip();
LOCK(cs_main);
pindexPrev = chainActive.Tip();
}
MilliSleep(5000 + rand() % 5000); MilliSleep(5000 + rand() % 5000);
{ waitForPeers(chainparams);
LOCK(cs_main); pindexCur = chainActive.LastTip();
pindexCur = chainActive.Tip();
}
} while (pindexPrev != pindexCur); } while (pindexPrev != pindexCur);
sleep(5);
{ {
LOCK(cs_main); LOCK(cs_main);
printf("Staking height %d for %s\n", chainActive.Tip()->nHeight + 1, ASSETCHAINS_SYMBOL); printf("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); //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();
@@ -960,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);
@@ -989,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()) {
@@ -1001,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)
@@ -1044,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);