X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fmain.cpp;h=306a7bf65d72368b2f51f7535464403f7ba77656;hb=59a5b3624068f152efe55968ba77eb10a8e8f945;hp=a0a2509f19473b0725ae4b32733c72b509d78823;hpb=e45b499e2f6f78923d9f6df7a839f091eeb9b6fd;p=novacoin.git diff --git a/src/main.cpp b/src/main.cpp index a0a2509..306a7bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4418,9 +4418,6 @@ static int nLimitProcessors = -1; void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) { - void *scratchbuf = scrypt_buffer_alloc(); - - printf("CPUMiner started for proof-of-%s\n", fProofOfStake? "stake" : "work"); SetThreadPriority(THREAD_PRIORITY_LOWEST); // Make this thread recognisable as the mining thread @@ -4430,7 +4427,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) CReserveKey reservekey(pwallet); unsigned int nExtraNonce = 0; - while (fGenerateBitcoins || fProofOfStake) + while (fProofOfStake) { if (fShutdown) return; @@ -4439,7 +4436,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) Sleep(1000); if (fShutdown) return; - if ((!fGenerateBitcoins) && !fProofOfStake) + if (!fProofOfStake) return; } @@ -4453,7 +4450,6 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) // // Create new block // - unsigned int nTransactionsUpdatedLast = nTransactionsUpdated; CBlockIndex* pindexPrev = pindexBest; auto_ptr pblock(CreateNewBlock(pwallet, fProofOfStake)); @@ -4472,7 +4468,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) continue; } strMintWarning = ""; - printf("CPUMiner : proof-of-stake block found %s\n", pblock->GetHash().ToString().c_str()); + printf("StakeMiner : proof-of-stake block found %s\n", pblock->GetHash().ToString().c_str()); SetThreadPriority(THREAD_PRIORITY_NORMAL); CheckWork(pblock.get(), *pwalletMain, reservekey); SetThreadPriority(THREAD_PRIORITY_LOWEST); @@ -4480,126 +4476,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) Sleep(500); continue; } - - printf("Running BitcoinMiner with %"PRIszu" transactions in block (%u bytes)\n", pblock->vtx.size(), - ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); - - // - // Pre-build hash buffers - // - char pmidstatebuf[32+16]; char* pmidstate = alignup<16>(pmidstatebuf); - char pdatabuf[128+16]; char* pdata = alignup<16>(pdatabuf); - char phash1buf[64+16]; char* phash1 = alignup<16>(phash1buf); - - FormatHashBuffers(pblock.get(), pmidstate, pdata, phash1); - - unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); - unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12); - - - // - // Search - // - int64 nStart = GetTime(); - uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); - - unsigned int max_nonce = 0xffff0000; - block_header res_header; - uint256 result; - - loop - { - unsigned int nHashesDone = 0; - unsigned int nNonceFound; - - nNonceFound = scanhash_scrypt( - (block_header *)&pblock->nVersion, - scratchbuf, - max_nonce, - nHashesDone, - UBEGIN(result), - &res_header - ); - - // Check if something found - if (nNonceFound != (unsigned int) -1) - { - if (result <= hashTarget) - { - // Found a solution - pblock->nNonce = nNonceFound; - assert(result == pblock->GetHash()); - if (!pblock->SignBlock(*pwalletMain)) - { -// strMintWarning = strMintMessage; - break; - } - strMintWarning = ""; - - SetThreadPriority(THREAD_PRIORITY_NORMAL); - CheckWork(pblock.get(), *pwalletMain, reservekey); - SetThreadPriority(THREAD_PRIORITY_LOWEST); - break; - } - } - - // Meter hashes/sec - static int64 nHashCounter; - if (nHPSTimerStart == 0) - { - nHPSTimerStart = GetTimeMillis(); - nHashCounter = 0; - } - else - nHashCounter += nHashesDone; - if (GetTimeMillis() - nHPSTimerStart > 4000) - { - static CCriticalSection cs; - { - LOCK(cs); - if (GetTimeMillis() - nHPSTimerStart > 4000) - { - dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart); - nHPSTimerStart = GetTimeMillis(); - nHashCounter = 0; - static int64 nLogTime; - if (GetTime() - nLogTime > 30 * 60) - { - nLogTime = GetTime(); - printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[THREAD_MINER], dHashesPerSec/1000.0); - } - } - } - } - - // Check for stop or if block needs to be rebuilt - if (fShutdown) - return; - if (!fGenerateBitcoins) - return; - if (fLimitProcessors && vnThreadsRunning[THREAD_MINER] > nLimitProcessors) - return; - if (vNodes.empty()) - break; - if (nBlockNonce >= 0xffff0000) - break; - if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60) - break; - if (pindexPrev != pindexBest) - break; - - // Update nTime every few seconds - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime()); - pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift); - pblock->UpdateTime(pindexPrev); - nBlockTime = ByteReverse(pblock->nTime); - - if (pblock->GetBlockTime() >= (int64)pblock->vtx[0].nTime + nMaxClockDrift) - break; // need to update coinbase timestamp - } } - - scrypt_buffer_free(scratchbuf); } void static ThreadBitcoinMiner(void* parg)