@@ -468,41 +468,6 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
468468double dHashesPerSec = 0.0 ;
469469int64_t nHPSTimerStart = 0 ;
470470
471- //
472- // ScanHash scans nonces looking for a hash with at least some zero bits.
473- // It operates on big endian data. Caller does the byte reversing.
474- // All input buffers are 16-byte aligned. nNonce is usually preserved
475- // between calls, but periodically or if nNonce is 0xffff0000 or above,
476- // the block is rebuilt and nNonce starts over at zero.
477- //
478- unsigned int static ScanHash_CryptoPP (char * pmidstate, char * pdata, char * phash1, char * phash, unsigned int & nHashesDone)
479- {
480- unsigned int & nNonce = *(unsigned int *)(pdata + 12 );
481- for (;;)
482- {
483- // Crypto++ SHA256
484- // Hash pdata using pmidstate as the starting state into
485- // pre-formatted buffer phash1, then hash phash1 into phash
486- nNonce++;
487- SHA256Transform (phash1, pdata, pmidstate);
488- SHA256Transform (phash, phash1, pSHA256InitState);
489-
490- // Return the nonce if the hash has at least some zero bits,
491- // caller will check if it has enough to reach the target
492- if (((unsigned short *)phash)[14 ] == 0 )
493- return nNonce;
494-
495- // If nothing found after trying for a while, return -1
496- if ((nNonce & 0xffff ) == 0 )
497- {
498- nHashesDone = 0xffff +1 ;
499- return (unsigned int ) -1 ;
500- }
501- if ((nNonce & 0xfff ) == 0 )
502- boost::this_thread::interruption_point ();
503- }
504- }
505-
506471CBlockTemplate* CreateNewBlockWithKey (CReserveKey& reservekey)
507472{
508473 CPubKey pubkey;
@@ -595,37 +560,23 @@ void static BitcoinMiner(CWallet *pwallet)
595560
596561 unsigned int & nBlockTime = *(unsigned int *)(pdata + 64 + 4 );
597562 unsigned int & nBlockBits = *(unsigned int *)(pdata + 64 + 8 );
598- unsigned int & nBlockNonce = *(unsigned int *)(pdata + 64 + 12 );
599-
600563
601564 //
602565 // Search
603566 //
604567 int64_t nStart = GetTime ();
605568 uint256 hashTarget = CBigNum ().SetCompact (pblock->nBits ).getuint256 ();
606- uint256 hashbuf[2 ];
607- uint256& hash = *alignup<16 >(hashbuf);
608569 while (true )
609570 {
610571 unsigned int nHashesDone = 0 ;
611- unsigned int nNonceFound;
612-
613- // Crypto++ SHA256
614- nNonceFound = ScanHash_CryptoPP (pmidstate, pdata + 64 , phash1,
615- (char *)&hash, nHashesDone);
616572
617- // Check if something found
618- if (nNonceFound != ( unsigned int ) - 1 )
573+ uint256 hash;
574+ while ( true )
619575 {
620- for (unsigned int i = 0 ; i < sizeof (hash)/4 ; i++)
621- ((unsigned int *)&hash)[i] = ByteReverse (((unsigned int *)&hash)[i]);
622-
576+ hash = pblock->GetHash ();
623577 if (hash <= hashTarget)
624578 {
625579 // Found a solution
626- pblock->nNonce = ByteReverse (nNonceFound);
627- assert (hash == pblock->GetHash ());
628-
629580 SetThreadPriority (THREAD_PRIORITY_NORMAL);
630581 CheckWork (pblock, *pwallet, reservekey);
631582 SetThreadPriority (THREAD_PRIORITY_LOWEST);
@@ -637,6 +588,10 @@ void static BitcoinMiner(CWallet *pwallet)
637588
638589 break ;
639590 }
591+ pblock->nNonce += 1 ;
592+ nHashesDone += 1 ;
593+ if ((pblock->nNonce & 0xFF ) == 0 )
594+ break ;
640595 }
641596
642597 // Meter hashes/sec
@@ -672,7 +627,7 @@ void static BitcoinMiner(CWallet *pwallet)
672627 boost::this_thread::interruption_point ();
673628 if (vNodes.empty () && Params ().NetworkID () != CChainParams::REGTEST)
674629 break ;
675- if (nBlockNonce >= 0xffff0000 )
630+ if (pblock-> nNonce >= 0xffff0000 )
676631 break ;
677632 if (mempool.GetTransactionsUpdated () != nTransactionsUpdatedLast && GetTime () - nStart > 60 )
678633 break ;
0 commit comments