@ -17,32 +17,14 @@
extern " C " void cn_slow_hash ( const void * data , size_t length , char * hash , int variant , int prehashed , uint64_t height ) ;
extern " C " void cn_slow_hash ( const void * data , size_t length , char * hash , int variant , int prehashed , uint64_t height ) ;
extern " C " void cn_fast_hash ( const void * data , size_t length , char * hash ) ;
extern " C " void cn_fast_hash ( const void * data , size_t length , char * hash ) ;
namespace
{
boost : : mutex max_concurrency_lock ;
unsigned max_concurrency = boost : : thread : : hardware_concurrency ( ) ;
}
void set_max_concurrency ( unsigned n )
{
if ( n < 1 )
n = boost : : thread : : hardware_concurrency ( ) ;
unsigned hwc = boost : : thread : : hardware_concurrency ( ) ;
if ( n > hwc )
n = hwc ;
boost : : lock_guard < boost : : mutex > lock ( max_concurrency_lock ) ;
max_concurrency = n ;
}
unsigned get_max_concurrency ( )
{
boost : : lock_guard < boost : : mutex > lock ( max_concurrency_lock ) ;
return max_concurrency ;
}
static uint256 cn_get_block_hash_by_height ( uint64_t seed_height , char cnHash [ 32 ] )
static uint256 cn_get_block_hash_by_height ( uint64_t seed_height , char cnHash [ 32 ] )
{
{
CBlockIndex * pblockindex = chainActive [ seed_height ] ;
CBlockIndex * pblockindex = chainActive [ seed_height ] ;
if ( pblockindex = = NULL ) {
// This will only happens during initial block download.
pblockindex = mapBlockSeedHeight . find ( seed_height ) - > second ;
}
assert ( pblockindex ! = NULL ) ;
uint256 blockHash = pblockindex - > GetBlockHash ( ) ;
uint256 blockHash = pblockindex - > GetBlockHash ( ) ;
const unsigned char * pHash = blockHash . begin ( ) ;
const unsigned char * pHash = blockHash . begin ( ) ;
for ( int j = 31 ; j > = 0 ; j - - ) {
for ( int j = 31 ; j > = 0 ; j - - ) {
@ -91,7 +73,7 @@ uint256 CBlockHeader::GetPoWHash() const
char cnHash [ 32 ] ;
char cnHash [ 32 ] ;
seed_height = crypto : : rx_seedheight ( height ) ;
seed_height = crypto : : rx_seedheight ( height ) ;
cn_get_block_hash_by_height ( seed_height , cnHash ) ;
cn_get_block_hash_by_height ( seed_height , cnHash ) ;
crypto : : rx_slow_hash ( height , seed_height , cnHash , blob . data ( ) , blob . size ( ) , BEGIN ( thash ) , get_max_concurrency ( ) , 0 ) ;
crypto : : rx_slow_hash ( height , seed_height , cnHash , blob . data ( ) , blob . size ( ) , BEGIN ( thash ) , 0 , 0 ) ;
} else {
} else {
cn_slow_hash ( blob . data ( ) , blob . size ( ) , BEGIN ( thash ) , cnHeader . major_version - 6 , 0 , height ) ;
cn_slow_hash ( blob . data ( ) , blob . size ( ) , BEGIN ( thash ) , cnHeader . major_version - 6 , 0 , height ) ;
}
}