|
|
@ -35,9 +35,9 @@ BlockInfo::BlockInfo(): timestamp(Invalid256) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
BlockInfo::BlockInfo(bytesConstRef _block, bool _checkNonce) |
|
|
|
BlockInfo::BlockInfo(bytesConstRef _block, Strictness _s) |
|
|
|
{ |
|
|
|
populate(_block, _checkNonce); |
|
|
|
populate(_block, _s); |
|
|
|
} |
|
|
|
|
|
|
|
void BlockInfo::setEmpty() |
|
|
@ -61,10 +61,10 @@ void BlockInfo::setEmpty() |
|
|
|
hash = headerHash(WithNonce); |
|
|
|
} |
|
|
|
|
|
|
|
BlockInfo BlockInfo::fromHeader(bytesConstRef _block) |
|
|
|
BlockInfo BlockInfo::fromHeader(bytesConstRef _block, Strictness _s) |
|
|
|
{ |
|
|
|
BlockInfo ret; |
|
|
|
ret.populateFromHeader(RLP(_block)); |
|
|
|
ret.populateFromHeader(RLP(_block), _s); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
@ -89,7 +89,7 @@ h256 BlockInfo::headerHash(bytesConstRef _block) |
|
|
|
return sha3(RLP(_block)[0].data()); |
|
|
|
} |
|
|
|
|
|
|
|
void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce) |
|
|
|
void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s) |
|
|
|
{ |
|
|
|
hash = dev::sha3(_header.data()); |
|
|
|
|
|
|
@ -121,30 +121,33 @@ void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce) |
|
|
|
} |
|
|
|
|
|
|
|
// check it hashes according to proof of work or that it's the genesis block.
|
|
|
|
if (_checkNonce && parentHash && !ProofOfWork::verify(*this)) |
|
|
|
if (_s == CheckEverything && parentHash && !ProofOfWork::verify(*this)) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidBlockNonce() << errinfo_hash256(headerHash(WithoutNonce)) << errinfo_nonce(nonce) << errinfo_difficulty(difficulty)); |
|
|
|
|
|
|
|
if (gasUsed > gasLimit) |
|
|
|
BOOST_THROW_EXCEPTION(TooMuchGasUsed() << RequirementError(bigint(gasLimit), bigint(gasUsed)) ); |
|
|
|
if (_s != CheckNothing) |
|
|
|
{ |
|
|
|
if (gasUsed > gasLimit) |
|
|
|
BOOST_THROW_EXCEPTION(TooMuchGasUsed() << RequirementError(bigint(gasLimit), bigint(gasUsed)) ); |
|
|
|
|
|
|
|
if (difficulty < c_minimumDifficulty) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError(bigint(c_minimumDifficulty), bigint(difficulty)) ); |
|
|
|
if (difficulty < c_minimumDifficulty) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError(bigint(c_minimumDifficulty), bigint(difficulty)) ); |
|
|
|
|
|
|
|
if (gasLimit < c_minGasLimit) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError(bigint(c_minGasLimit), bigint(gasLimit)) ); |
|
|
|
if (gasLimit < c_minGasLimit) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError(bigint(c_minGasLimit), bigint(gasLimit)) ); |
|
|
|
|
|
|
|
if (number && extraData.size() > c_maximumExtraDataSize) |
|
|
|
BOOST_THROW_EXCEPTION(ExtraDataTooBig() << RequirementError(bigint(c_maximumExtraDataSize), bigint(extraData.size()))); |
|
|
|
if (number && extraData.size() > c_maximumExtraDataSize) |
|
|
|
BOOST_THROW_EXCEPTION(ExtraDataTooBig() << RequirementError(bigint(c_maximumExtraDataSize), bigint(extraData.size()))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void BlockInfo::populate(bytesConstRef _block, bool _checkNonce) |
|
|
|
void BlockInfo::populate(bytesConstRef _block, Strictness _s) |
|
|
|
{ |
|
|
|
RLP root(_block); |
|
|
|
RLP header = root[0]; |
|
|
|
|
|
|
|
if (!header.isList()) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidBlockFormat() << errinfo_comment("block header needs to be a list") << BadFieldError(0, header.data().toString())); |
|
|
|
populateFromHeader(header, _checkNonce); |
|
|
|
populateFromHeader(header, _s); |
|
|
|
|
|
|
|
if (!root[1].isList()) |
|
|
|
BOOST_THROW_EXCEPTION(InvalidBlockFormat() << errinfo_comment("block transactions need to be a list") << BadFieldError(1, root[1].data().toString())); |
|
|
|