@ -61,8 +61,8 @@ CScript COINBASE_FLAGS;
const string strMessageMagic = " Bitcoin Signed Message: \n " ;
const string strMessageMagic = " Bitcoin Signed Message: \n " ;
double dHashesPerSec ;
double dHashesPerSec = 0.0 ;
int64 nHPSTimerStart ;
int64 nHPSTimerStart = 0 ;
// Settings
// Settings
int64 nTransactionFee = 0 ;
int64 nTransactionFee = 0 ;
@ -4089,6 +4089,8 @@ unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1
nHashesDone = 0xffff + 1 ;
nHashesDone = 0xffff + 1 ;
return ( unsigned int ) - 1 ;
return ( unsigned int ) - 1 ;
}
}
if ( ( nNonce & 0xfff ) = = 0 )
boost : : this_thread : : interruption_point ( ) ;
}
}
}
}
@ -4506,37 +4508,19 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
return true ;
return true ;
}
}
void static ThreadBitcoinMiner ( void * parg ) ;
static bool fGenerateBitcoins = false ;
static bool fLimitProcessors = false ;
static int nLimitProcessors = - 1 ;
void static BitcoinMiner ( CWallet * pwallet )
void static BitcoinMiner ( CWallet * pwallet )
{
{
printf ( " BitcoinMiner started \n " ) ;
printf ( " BitcoinMiner started \n " ) ;
SetThreadPriority ( THREAD_PRIORITY_LOWEST ) ;
SetThreadPriority ( THREAD_PRIORITY_LOWEST ) ;
// Make this thread recognisable as the mining thread
RenameThread ( " bitcoin-miner " ) ;
RenameThread ( " bitcoin-miner " ) ;
// Each thread has its own key and counter
// Each thread has its own key and counter
CReserveKey reservekey ( pwallet ) ;
CReserveKey reservekey ( pwallet ) ;
unsigned int nExtraNonce = 0 ;
unsigned int nExtraNonce = 0 ;
while ( fGenerateBitcoins )
try { loop {
{
while ( vNodes . empty ( ) )
if ( fShutdown )
return ;
while ( vNodes . empty ( ) | | IsInitialBlockDownload ( ) )
{
Sleep ( 1000 ) ;
Sleep ( 1000 ) ;
if ( fShutdown )
return ;
if ( ! fGenerateBitcoins )
return ;
}
//
//
// Create new block
// Create new block
@ -4553,7 +4537,6 @@ void static BitcoinMiner(CWallet *pwallet)
printf ( " Running BitcoinMiner with % " PRIszu " transactions in block (%u bytes) \n " , pblock - > vtx . size ( ) ,
printf ( " Running BitcoinMiner with % " PRIszu " transactions in block (%u bytes) \n " , pblock - > vtx . size ( ) ,
: : GetSerializeSize ( * pblock , SER_NETWORK , PROTOCOL_VERSION ) ) ;
: : GetSerializeSize ( * pblock , SER_NETWORK , PROTOCOL_VERSION ) ) ;
//
//
// Pre-build hash buffers
// Pre-build hash buffers
//
//
@ -4626,19 +4609,14 @@ void static BitcoinMiner(CWallet *pwallet)
if ( GetTime ( ) - nLogTime > 30 * 60 )
if ( GetTime ( ) - nLogTime > 30 * 60 )
{
{
nLogTime = GetTime ( ) ;
nLogTime = GetTime ( ) ;
printf ( " hashmeter %3d CPUs % 6.0f khash/s \n " , vnThreadsRunning [ THREAD_MINER ] , dHashesPerSec / 1000.0 ) ;
printf ( " hashmeter %6.0f khash/s \n " , dHashesPerSec / 1000.0 ) ;
}
}
}
}
}
}
}
}
// Check for stop or if block needs to be rebuilt
// Check for stop or if block needs to be rebuilt
if ( fShutdown )
boost : : this_thread : : interruption_point ( ) ;
return ;
if ( ! fGenerateBitcoins )
return ;
if ( fLimitProcessors & & vnThreadsRunning [ THREAD_MINER ] > nLimitProcessors )
return ;
if ( vNodes . empty ( ) )
if ( vNodes . empty ( ) )
break ;
break ;
if ( nBlockNonce > = 0xffff0000 )
if ( nBlockNonce > = 0xffff0000 )
@ -4658,57 +4636,35 @@ void static BitcoinMiner(CWallet *pwallet)
hashTarget = CBigNum ( ) . SetCompact ( pblock - > nBits ) . getuint256 ( ) ;
hashTarget = CBigNum ( ) . SetCompact ( pblock - > nBits ) . getuint256 ( ) ;
}
}
}
}
}
} }
}
catch ( boost : : thread_interrupted )
void static ThreadBitcoinMiner ( void * parg )
{
CWallet * pwallet = ( CWallet * ) parg ;
try
{
{
vnThreadsRunning [ THREAD_MINER ] + + ;
printf ( " BitcoinMiner terminated \n " ) ;
BitcoinMiner ( pwallet ) ;
throw ;
vnThreadsRunning [ THREAD_MINER ] - - ;
}
}
catch ( std : : exception & e ) {
vnThreadsRunning [ THREAD_MINER ] - - ;
PrintException ( & e , " ThreadBitcoinMiner() " ) ;
} catch ( . . . ) {
vnThreadsRunning [ THREAD_MINER ] - - ;
PrintException ( NULL , " ThreadBitcoinMiner() " ) ;
}
nHPSTimerStart = 0 ;
if ( vnThreadsRunning [ THREAD_MINER ] = = 0 )
dHashesPerSec = 0 ;
printf ( " ThreadBitcoinMiner exiting, %d threads remaining \n " , vnThreadsRunning [ THREAD_MINER ] ) ;
}
}
void GenerateBitcoins ( bool fGenerate , CWallet * pwallet )
void GenerateBitcoins ( bool fGenerate , CWallet * pwallet )
{
{
fGenerateBitcoins = fGenerate ;
static boost : : thread_group * minerThreads = NULL ;
nLimitProcessors = GetArg ( " -genproclimit " , - 1 ) ;
if ( nLimitProcessors = = 0 )
int nThreads = GetArg ( " -genproclimit " , - 1 ) ;
fGenerateBitcoins = false ;
if ( nThreads < 0 )
fLimitProcessors = ( nLimitProcessors ! = - 1 ) ;
nThreads = boost : : thread : : hardware_concurrency ( ) ;
if ( fGenerate )
if ( minerThreads ! = NULL )
{
{
int nProcessors = boost : : thread : : hardware_concurrency ( ) ;
minerThreads - > interrupt_all ( ) ;
printf ( " %d processors \n " , nProcessors ) ;
delete minerThreads ;
if ( nProcessors < 1 )
minerThreads = NULL ;
nProcessors = 1 ;
if ( fLimitProcessors & & nProcessors > nLimitProcessors )
nProcessors = nLimitProcessors ;
int nAddThreads = nProcessors - vnThreadsRunning [ THREAD_MINER ] ;
printf ( " Starting %d BitcoinMiner threads \n " , nAddThreads ) ;
for ( int i = 0 ; i < nAddThreads ; i + + )
{
if ( ! NewThread ( ThreadBitcoinMiner , pwallet ) )
printf ( " Error: NewThread(ThreadBitcoinMiner) failed \n " ) ;
Sleep ( 10 ) ;
}
}
}
if ( nThreads = = 0 | | ! fGenerate )
return ;
minerThreads = new boost : : thread_group ( ) ;
for ( int i = 0 ; i < nThreads ; i + + )
minerThreads - > create_thread ( boost : : bind ( & BitcoinMiner , pwallet ) ) ;
}
}
// Amount compression:
// Amount compression: