Browse Source

start mining from randon nonce

pull/5/head
orignal 7 years ago
parent
commit
b2efd40551
  1. 184
      src/main.cpp

184
src/main.cpp

@ -4704,96 +4704,100 @@ void static GostcoinMiner(CWallet *pwallet)
CReserveKey reservekey(pwallet); CReserveKey reservekey(pwallet);
unsigned int nExtraNonce = 0; unsigned int nExtraNonce = 0;
try { loop { try
// TODO: {
/* while (vNodes.empty()) loop
MilliSleep(1000);*/ {
// while (vNodes.empty())
// Create new block MilliSleep(1000);
//
unsigned int nTransactionsUpdatedLast = nTransactionsUpdated; //
CBlockIndex* pindexPrev = pindexBest; // Create new block
//
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey)); unsigned int nTransactionsUpdatedLast = nTransactionsUpdated;
if (!pblocktemplate.get()) CBlockIndex* pindexPrev = pindexBest;
return;
CBlock *pblock = &pblocktemplate->block; auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); if (!pblocktemplate.get())
return;
printf("Running GostcoinMiner with %" PRIszu " transactions in block (%u bytes)\n", pblock->vtx.size(), CBlock *pblock = &pblocktemplate->block;
::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); RAND_bytes ((uint8_t *)&pblock->nNonce, 4);
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
//
// Solve printf("Running GostcoinMiner with %" PRIszu " transactions in block (%u bytes)\n", pblock->vtx.size(),
// ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));
int64 nStart = GetTime();
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); //
loop // Solve
{ //
unsigned int nHashesDone = 0; int64 nStart = GetTime();
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
loop loop
{ {
if (pblock->GetHash() <= hashTarget) unsigned int nHashesDone = 0;
{
// Found a solution loop
SetThreadPriority(THREAD_PRIORITY_NORMAL); {
CheckWork(pblock, *pwallet, reservekey); if (pblock->GetHash() <= hashTarget)
SetThreadPriority(THREAD_PRIORITY_LOWEST); {
break; // Found a solution
} SetThreadPriority(THREAD_PRIORITY_NORMAL);
pblock->nNonce += 1; CheckWork(pblock, *pwallet, reservekey);
nHashesDone += 1; SetThreadPriority(THREAD_PRIORITY_LOWEST);
if ((pblock->nNonce & 0xFF) == 0) break;
break; }
} pblock->nNonce += 1;
nHashesDone += 1;
// Meter hashes/sec if ((pblock->nNonce & 0xFF) == 0)
static int64 nHashCounter; break;
if (nHPSTimerStart == 0) }
{
nHPSTimerStart = GetTimeMillis(); // Meter hashes/sec
nHashCounter = 0; static int64 nHashCounter;
} if (nHPSTimerStart == 0)
else {
nHashCounter += nHashesDone; nHPSTimerStart = GetTimeMillis();
if (GetTimeMillis() - nHPSTimerStart > 4000) nHashCounter = 0;
{ }
static CCriticalSection cs; else
{ nHashCounter += nHashesDone;
LOCK(cs); if (GetTimeMillis() - nHPSTimerStart > 4000)
if (GetTimeMillis() - nHPSTimerStart > 4000) {
{ static CCriticalSection cs;
dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart); {
nHPSTimerStart = GetTimeMillis(); LOCK(cs);
nHashCounter = 0; if (GetTimeMillis() - nHPSTimerStart > 4000)
static int64 nLogTime; {
if (GetTime() - nLogTime > 30 * 60) dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart);
{ nHPSTimerStart = GetTimeMillis();
nLogTime = GetTime(); nHashCounter = 0;
printf("hashmeter %6.0f khash/s\n", dHashesPerSec/1000.0); static int64 nLogTime;
} if (GetTime() - nLogTime > 30 * 60)
} {
} nLogTime = GetTime();
} printf("hashmeter %6.0f khash/s\n", dHashesPerSec/1000.0);
}
// Check for stop or if block needs to be rebuilt }
boost::this_thread::interruption_point(); }
// TODO: }
/* if (vNodes.empty())
break;*/ // Check for stop or if block needs to be rebuilt
if (pblock->nNonce >= 0xffff0000) boost::this_thread::interruption_point();
break; if (vNodes.empty())
if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60) break;
break; if (pblock->nNonce >= 0xffff0000)
if (pindexPrev != pindexBest) break;
break; if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)
break;
// Update nTime every few seconds if (pindexPrev != pindexBest)
pblock->UpdateTime(pindexPrev); break;
}
} } // Update nTime every few seconds
pblock->UpdateTime(pindexPrev);
}
}
}
catch (boost::thread_interrupted) catch (boost::thread_interrupted)
{ {
printf("GostcoinMiner terminated\n"); printf("GostcoinMiner terminated\n");

Loading…
Cancel
Save