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()))