@ -105,23 +105,18 @@ void EthashAux::killCache(h256 const& _s)
m_lights . erase ( _s ) ;
}
EthashAux : : LightType EthashAux : : light ( BlockInfo const & _header )
{
return light ( ( uint64_t ) _header . number ) ;
}
EthashAux : : LightType EthashAux : : light ( uint64_t _blockNumber )
EthashAux : : LightType EthashAux : : light ( h256 const & _seedHash )
{
RecursiveGuard l ( get ( ) - > x_lights ) ;
h256 seedHash = EthashAux : : seedHash ( _blockNumber ) ;
LightType ret = get ( ) - > m_lights [ seedHash ] ;
return ret ? ret : ( get ( ) - > m_lights [ seedHash ] = make_shared < LightAllocation > ( _blockNumber ) ) ;
LightType ret = get ( ) - > m_lights [ _seedHash ] ;
return ret ? ret : ( get ( ) - > m_lights [ _seedHash ] = make_shared < LightAllocation > ( _seedHash ) ) ;
}
EthashAux : : LightAllocation : : LightAllocation ( uint64_t _blockNumber )
EthashAux : : LightAllocation : : LightAllocation ( h256 const & _seedHash )
{
light = ethash_light_new ( _blockNumber ) ;
size = ethash_get_cachesize ( _blockNumber ) ;
uint64_t blockNumber = EthashAux : : number ( _seedHash ) ;
light = ethash_light_new ( blockNumber ) ;
size = ethash_get_cachesize ( blockNumber ) ;
}
EthashAux : : LightAllocation : : ~ LightAllocation ( )
@ -156,22 +151,19 @@ static int dagCallbackShim(unsigned _p)
return s_dagCallback ? s_dagCallback ( _p ) : 0 ;
}
EthashAux : : FullType EthashAux : : full ( uint64_t _blockNumber , function < int ( unsigned ) > const & _f , bool _createIfMissing )
EthashAux : : FullType EthashAux : : full ( h256 const & _seedHash , bool _createIfMissing , function < int ( unsigned ) > const & _f )
{
( void ) _createIfMissing ;
// TODO: implement
auto l = light ( _blockNumber ) ;
h256 seedHash = EthashAux : : seedHash ( _blockNumber ) ;
FullType ret ;
auto l = light ( _seedHash ) ;
DEV_GUARDED ( get ( ) - > x_fulls )
if ( ( ret = get ( ) - > m_fulls [ seedHash ] . lock ( ) ) )
if ( ( ret = get ( ) - > m_fulls [ _ seedHash] . lock ( ) ) )
{
get ( ) - > m_lastUsedFull = ret ;
return ret ;
}
if ( _createIfMissing | | computeFull ( _blockNumber ) = = 100 )
if ( _createIfMissing | | computeFull ( _seedHash ) = = 100 )
{
s_dagCallback = _f ;
cnote < < " Loading from libethash... " ;
@ -179,17 +171,17 @@ EthashAux::FullType EthashAux::full(uint64_t _blockNumber, function<int(unsigned
cnote < < " Done loading. " ;
DEV_GUARDED ( get ( ) - > x_fulls )
get ( ) - > m_fulls [ seedHash ] = get ( ) - > m_lastUsedFull = ret ;
get ( ) - > m_fulls [ _ seedHash] = get ( ) - > m_lastUsedFull = ret ;
}
return ret ;
}
unsigned EthashAux : : computeFull ( uint64_t _blockNumber )
unsigned EthashAux : : computeFull ( h256 const & _seedHash )
{
Guard l ( get ( ) - > x_fulls ) ;
h256 seedHash = EthashAux : : seedHash ( _blockNumber ) ;
if ( FullType ret = get ( ) - > m_fulls [ seedHash ] . lock ( ) )
uint64_t blockNumber = EthashAux : : number ( _seedHash ) ;
if ( FullType ret = get ( ) - > m_fulls [ _ seedHash] . lock ( ) )
{
get ( ) - > m_lastUsedFull = ret ;
return 100 ;
@ -198,17 +190,17 @@ unsigned EthashAux::computeFull(uint64_t _blockNumber)
if ( ! get ( ) - > m_fullGenerator | | ! get ( ) - > m_fullGenerator - > joinable ( ) )
{
get ( ) - > m_fullProgress = 0 ;
get ( ) - > m_generatingFullNumber = _ blockNumber / ETHASH_EPOCH_LENGTH * ETHASH_EPOCH_LENGTH ;
get ( ) - > m_generatingFullNumber = blockNumber / ETHASH_EPOCH_LENGTH * ETHASH_EPOCH_LENGTH ;
get ( ) - > m_fullGenerator = unique_ptr < thread > ( new thread ( [ = ] ( ) {
cnote < < " Loading full DAG of " < < _blockNumber ;
get ( ) - > full ( _blockNumber , [ ] ( unsigned p ) { get ( ) - > m_fullProgress = p ; return 0 ; } , true ) ;
cnote < < " Loading full DAG of seedhash: " < < _seedHash ;
get ( ) - > full ( _seedHash , true , [ ] ( unsigned p ) { get ( ) - > m_fullProgress = p ; return 0 ; } ) ;
cnote < < " Full DAG loaded " ;
get ( ) - > m_fullProgress = 0 ;
get ( ) - > m_generatingFullNumber = NotGenerating ;
} ) ) ;
}
return ( get ( ) - > m_generatingFullNumber = = _ blockNumber) ? get ( ) - > m_fullProgress : 0 ;
return ( get ( ) - > m_generatingFullNumber = = blockNumber ) ? get ( ) - > m_fullProgress : 0 ;
}
Ethash : : Result EthashAux : : FullAllocation : : compute ( h256 const & _headerHash , Nonce const & _nonce ) const
@ -229,13 +221,12 @@ Ethash::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonc
Ethash : : Result EthashAux : : eval ( BlockInfo const & _header , Nonce const & _nonce )
{
return eval ( ( uint64_t ) _header . number , _header . headerHash ( WithoutNonce ) , _nonce ) ;
return eval ( _header . seedHash ( ) , _header . headerHash ( WithoutNonce ) , _nonce ) ;
}
Ethash : : Result EthashAux : : eval ( uint64_t _blockNumber , h256 const & _headerHash , Nonce const & _nonce )
Ethash : : Result EthashAux : : eval ( h256 const & _seedHash , h256 const & _headerHash , Nonce const & _nonce )
{
h256 seedHash = EthashAux : : seedHash ( _blockNumber ) ;
if ( FullType dag = get ( ) - > m_fulls [ seedHash ] . lock ( ) )
if ( FullType dag = get ( ) - > m_fulls [ _seedHash ] . lock ( ) )
return dag - > compute ( _headerHash , _nonce ) ;
return EthashAux : : get ( ) - > light ( _blockNumber ) - > compute ( _headerHash , _nonce ) ;
return EthashAux : : get ( ) - > light ( _seedHash ) - > compute ( _headerHash , _nonce ) ;
}