35 BlockHeader::BlockHeader()
42 m_hash = _hashWith ? _hashWith :
sha3(header.
data());
47 m_parentHash(_other.parentHash()),
48 m_sha3Uncles(_other.sha3Uncles()),
49 m_stateRoot(_other.stateRoot()),
50 m_transactionsRoot(_other.transactionsRoot()),
51 m_receiptsRoot(_other.receiptsRoot()),
52 m_logBloom(_other.logBloom()),
53 m_number(_other.number()),
54 m_gasLimit(_other.gasLimit()),
55 m_gasUsed(_other.gasUsed()),
56 m_extraData(_other.extraData()),
57 m_timestamp(_other.timestamp()),
58 m_author(_other.author()),
59 m_difficulty(_other.difficulty()),
60 m_seal(_other.seal()),
61 m_hash(_other.hashRawRead()),
62 m_hashWithout(_other.hashWithoutRawRead())
64 assert(*
this == _other);
77 m_number = _other.
number();
82 m_author = _other.
author();
84 std::vector<bytes>
seal = _other.
seal();
87 m_seal = std::move(seal);
90 h256 hashWithout = _other.hashWithoutRawRead();
93 m_hash = std::move(
hash);
94 m_hashWithout = std::move(hashWithout);
96 assert(*
this == _other);
102 m_parentHash =
h256();
133 void BlockHeader::streamRLPFields(
RLPStream& _s)
const 135 _s << m_parentHash << m_sha3Uncles << m_author << m_stateRoot << m_transactionsRoot << m_receiptsRoot << m_logBloom
136 << m_difficulty << m_number << m_gasLimit << m_gasUsed << m_timestamp << m_extraData;
144 BlockHeader::streamRLPFields(_s);
147 for (
unsigned i = 0; i < m_seal.size(); ++i)
153 return sha3(
RLP(_block)[0].data());
161 RLP header = root[0];
164 if (!root[1].isList())
166 if (!root[2].isList())
171 void BlockHeader::populate(
RLP const& _header)
183 m_difficulty = _header[field = 7].
toInt<
u256>();
185 m_gasLimit = _header[field = 9].
toInt<
u256>();
186 m_gasUsed = _header[field = 10].
toInt<
u256>();
188 m_extraData = _header[field = 12].
toBytes();
190 for (
unsigned i = 13; i < _header.
itemCount(); ++i)
191 m_seal.push_back(_header[i].data().toBytes());
203 m_number = _parent.m_number + 1;
204 m_parentHash = _parent.m_hash;
205 m_gasLimit = _parent.m_gasLimit;
206 m_difficulty = _parent.m_difficulty;
212 if (m_number > ~(
unsigned)0)
213 BOOST_THROW_EXCEPTION(InvalidNumber());
220 if (m_parentHash && _parent.
hash() != m_parentHash)
221 BOOST_THROW_EXCEPTION(InvalidParentHash());
223 if (m_timestamp <= _parent.m_timestamp)
224 BOOST_THROW_EXCEPTION(InvalidTimestamp());
226 if (m_number != _parent.m_number + 1)
227 BOOST_THROW_EXCEPTION(InvalidNumber());
234 auto txList = root[1];
235 auto expectedRoot =
trieRootOver(txList.itemCount(), [&](
unsigned i){
return rlp(i); }, [&](
unsigned i){
return txList[i].data().toBytes(); });
237 LOG(m_logger) <<
"Expected trie root: " <<
toString(expectedRoot);
238 if (m_transactionsRoot != expectedRoot)
242 transactionsTrie.
init();
244 vector<bytesConstRef> txs;
246 for (
unsigned i = 0; i < txList.itemCount(); ++i)
251 transactionsTrie.
insert(&k.
out(), txList[i].data());
253 txs.push_back(txList[i].data());
256 cdebug <<
"trieRootOver" << expectedRoot;
258 cdebug <<
"TrieDB" << transactionsTrie.
root();
260 for (
auto const& t: txs)
265 LOG(m_logger) <<
"Expected uncle hash: " <<
toString(
sha3(root[2].data()));
266 if (m_sha3Uncles !=
sha3(root[2].data()))
_T toInt(int _flags=Strict) const
Converts to int of type given; if isData(), decodes as big-endian bytestream.
bytes toBytes(int _flags=LaissezFaire) const
Converts to bytearray.
boost::tuple< errinfo_required_h256, errinfo_got_h256 > Hash256RequirementError
boost::error_info< struct tag_field, std::string > errinfo_name
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
Merkle Patricia Tree "Trie": a modifed base-16 Radix tree. This version uses a database backend...
std::string toString(std::chrono::time_point< T > const &_e, std::string const &_format="%F %T")
bool sha3(bytesConstRef _input, bytesRef o_output) noexcept
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
Base class for all exceptions.
std::lock_guard< std::mutex > Guard
bytesConstRef data() const
The bare data of the RLP.
int64_t toPositiveInt64(int _flags=Strict) const
RLPStream & appendList(size_t _items)
Appends a list.
bytes const & out() const
Read the byte stream.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
boost::tuple< errinfo_field, errinfo_data > BadFieldError
boost::error_info< struct tag_comment, std::string > errinfo_comment
h256 trieRootOver(unsigned _itemCount, T const &_getKey, U const &_getValue)
std::string toString() const
h2048 LogBloom
The log bloom's size (2048-bit).
h256 orderedTrieRoot(std::vector< bytes > const &_data)
std::string toHex(Iterator _it, Iterator _end, std::string const &_prefix)
void insert(bytes const &_key, bytes const &_value)
boost::tuple< errinfo_required, errinfo_got > RequirementError
Class for writing to an RLP bytestream.
_N toHash(int _flags=Strict) const
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
h256 const & root() const
bool isList() const
List value.