@ -26,7 +26,6 @@
# include <libethcore/Common.h>
# include <libethcore/Common.h>
# include <libethcore/Params.h>
# include <libethcore/Params.h>
# include "EthashAux.h"
# include "EthashAux.h"
# include "ProofOfWork.h"
# include "Exceptions.h"
# include "Exceptions.h"
# include "BlockInfo.h"
# include "BlockInfo.h"
using namespace std ;
using namespace std ;
@ -57,22 +56,21 @@ void BlockInfo::clear()
gasUsed = 0 ;
gasUsed = 0 ;
timestamp = 0 ;
timestamp = 0 ;
extraData . clear ( ) ;
extraData . clear ( ) ;
mixHash = h256 ( ) ;
proof = ProofOfWork : : Solution ( ) ;
nonce = Nonc e( ) ;
m_proofCache = ProofOfWork : : HeaderCach e( ) ;
m_hash = m_seedHash = h256 ( ) ;
m_hash = h256 ( ) ;
}
}
h256 const & BlockInfo : : seedHash ( ) const
ProofOfWork : : HeaderCache const & BlockInfo : : proofCache ( ) const
{
{
if ( ! m_seedHash )
ProofOfWork : : ensureHeaderCacheValid ( m_proofCache , * this ) ;
m_seedHash = EthashAux : : seedHash ( ( unsigned ) number ) ;
return m_proofCache ;
return m_seedHash ;
}
}
h256 const & BlockInfo : : hash ( ) const
h256 const & BlockInfo : : hash ( ) const
{
{
if ( ! m_hash )
if ( ! m_hash )
m_hash = headerHash ( WithNonce ) ;
m_hash = headerHash ( WithProof ) ;
return m_hash ;
return m_hash ;
}
}
@ -90,20 +88,20 @@ BlockInfo BlockInfo::fromHeader(bytesConstRef _header, Strictness _s, h256 const
return ret ;
return ret ;
}
}
h256 BlockInfo : : headerHash ( IncludeNonce _n ) const
h256 BlockInfo : : headerHash ( IncludeProof _n ) const
{
{
RLPStream s ;
RLPStream s ;
streamRLP ( s , _n ) ;
streamRLP ( s , _n ) ;
return sha3 ( s . out ( ) ) ;
return sha3 ( s . out ( ) ) ;
}
}
void BlockInfo : : streamRLP ( RLPStream & _s , IncludeNonce _n ) const
void BlockInfo : : streamRLP ( RLPStream & _s , IncludeProof _n ) const
{
{
_s . appendList ( _n = = WithNonce ? 15 : 13 )
_s . appendList ( _n = = WithProof ? 13 + ProofOfWork : : Solution : : Fields : 13 )
< < parentHash < < sha3Uncles < < coinbaseAddress < < stateRoot < < transactionsRoot < < receiptsRoot < < logBloom
< < parentHash < < sha3Uncles < < coinbaseAddress < < stateRoot < < transactionsRoot < < receiptsRoot < < logBloom
< < difficulty < < number < < gasLimit < < gasUsed < < timestamp < < extraData ;
< < difficulty < < number < < gasLimit < < gasUsed < < timestamp < < extraData ;
if ( _n = = WithNonce )
if ( _n = = WithProof )
_s < < mixHash < < nonce ;
proof . streamRLP ( _s ) ;
}
}
h256 BlockInfo : : headerHash ( bytesConstRef _block )
h256 BlockInfo : : headerHash ( bytesConstRef _block )
@ -116,12 +114,12 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s, h256 const
m_hash = _h ;
m_hash = _h ;
if ( _h )
if ( _h )
assert ( _h = = dev : : sha3 ( _header . data ( ) ) ) ;
assert ( _h = = dev : : sha3 ( _header . data ( ) ) ) ;
m_seedHash = h256 ( ) ;
m_proofCache = ProofOfWork : : HeaderCache ( ) ;
int field = 0 ;
int field = 0 ;
try
try
{
{
if ( _header . itemCount ( ) ! = 15 )
if ( _header . itemCount ( ) ! = 13 + ProofOfWork : : Solution : : Fields )
BOOST_THROW_EXCEPTION ( InvalidBlockHeaderItemCount ( ) ) ;
BOOST_THROW_EXCEPTION ( InvalidBlockHeaderItemCount ( ) ) ;
parentHash = _header [ field = 0 ] . toHash < h256 > ( RLP : : VeryStrict ) ;
parentHash = _header [ field = 0 ] . toHash < h256 > ( RLP : : VeryStrict ) ;
sha3Uncles = _header [ field = 1 ] . toHash < h256 > ( RLP : : VeryStrict ) ;
sha3Uncles = _header [ field = 1 ] . toHash < h256 > ( RLP : : VeryStrict ) ;
@ -136,8 +134,7 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s, h256 const
gasUsed = _header [ field = 10 ] . toInt < u256 > ( ) ;
gasUsed = _header [ field = 10 ] . toInt < u256 > ( ) ;
timestamp = _header [ field = 11 ] . toInt < u256 > ( ) ;
timestamp = _header [ field = 11 ] . toInt < u256 > ( ) ;
extraData = _header [ field = 12 ] . toBytes ( ) ;
extraData = _header [ field = 12 ] . toBytes ( ) ;
mixHash = _header [ field = 13 ] . toHash < h256 > ( RLP : : VeryStrict ) ;
proof . populateFromRLP ( _header , field = 13 ) ;
nonce = _header [ field = 14 ] . toHash < Nonce > ( RLP : : VeryStrict ) ;
}
}
catch ( Exception const & _e )
catch ( Exception const & _e )
{
{
@ -152,22 +149,18 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s, h256 const
if ( _s = = CheckEverything & & parentHash & & ! ProofOfWork : : verify ( * this ) )
if ( _s = = CheckEverything & & parentHash & & ! ProofOfWork : : verify ( * this ) )
{
{
InvalidBlockNonce ex ;
InvalidBlockNonce ex ;
ex < < errinfo_hash256 ( headerHash ( WithoutNonce ) ) ;
ProofOfWork : : composeException ( ex , * this ) ;
ex < < errinfo_nonce ( nonce ) ;
ex < < errinfo_hash256 ( headerHash ( WithoutProof ) ) ;
ex < < errinfo_difficulty ( difficulty ) ;
ex < < errinfo_difficulty ( difficulty ) ;
ex < < errinfo_seedHash ( seedHash ( ) ) ;
ex < < errinfo_target ( boundary ( ) ) ;
ex < < errinfo_target ( boundary ( ) ) ;
ex < < errinfo_mixHash ( mixHash ) ;
Ethash : : Result er = EthashAux : : eval ( seedHash ( ) , headerHash ( WithoutNonce ) , nonce ) ;
ex < < errinfo_ethashResult ( make_tuple ( er . value , er . mixHash ) ) ;
BOOST_THROW_EXCEPTION ( ex ) ;
BOOST_THROW_EXCEPTION ( ex ) ;
}
}
else if ( _s = = QuickNonce & & parentHash & & ! ProofOfWork : : preVerify ( * this ) )
else if ( _s = = QuickNonce & & parentHash & & ! ProofOfWork : : preVerify ( * this ) )
{
{
InvalidBlockNonce ex ;
InvalidBlockNonce ex ;
ex < < errinfo_hash256 ( headerHash ( WithoutNonce ) ) ;
ex < < errinfo_hash256 ( headerHash ( WithoutProof ) ) ;
ex < < errinfo_nonce ( nonce ) ;
ex < < errinfo_difficulty ( difficulty ) ;
ex < < errinfo_difficulty ( difficulty ) ;
ProofOfWork : : composeExceptionPre ( ex , * this ) ;
BOOST_THROW_EXCEPTION ( ex ) ;
BOOST_THROW_EXCEPTION ( ex ) ;
}
}