Ethereum  PoC-8
The C++ Implementation of Ethereum
Block.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #include "Block.h"
23 
24 #include <ctime>
25 #include <boost/filesystem.hpp>
26 #include <boost/timer.hpp>
27 #include <libdevcore/CommonIO.h>
28 #include <libdevcore/Assertions.h>
29 #include <libdevcore/TrieHash.h>
30 #include <libethcore/Exceptions.h>
31 #include <libethcore/SealEngine.h>
32 #include <libevm/VMFactory.h>
33 #include "BlockChain.h"
34 #include "ExtVM.h"
35 #include "Executive.h"
36 #include "TransactionQueue.h"
37 #include "GenesisInfo.h"
38 using namespace std;
39 using namespace dev;
40 using namespace dev::eth;
41 namespace fs = boost::filesystem;
42 
43 #define ETH_TIMED_ENACTMENTS 0
44 
45 static const unsigned c_maxSyncTransactions = 1024;
46 
47 namespace
48 {
49 
50 class DummyLastBlockHashes: public eth::LastBlockHashesFace
51 {
52 public:
53  h256s precedingHashes(h256 const& /* _mostRecentHash */) const override { return {}; }
54  void clear() override {}
55 };
56 
57 }
58 
59 
60 Block::Block(BlockChain const& _bc, OverlayDB const& _db, BaseState _bs, Address const& _author):
61  m_state(Invalid256, _db, _bs),
62  m_precommit(Invalid256),
63  m_author(_author)
64 {
65  noteChain(_bc);
66  m_previousBlock.clear();
67  m_currentBlock.clear();
68 // assert(m_state.root() == m_previousBlock.stateRoot());
69 }
70 
71 Block::Block(BlockChain const& _bc, OverlayDB const& _db, h256 const& _root, Address const& _author):
72  m_state(Invalid256, _db, BaseState::PreExisting),
73  m_precommit(Invalid256),
74  m_author(_author)
75 {
76  noteChain(_bc);
77  m_state.setRoot(_root);
78  m_previousBlock.clear();
79  m_currentBlock.clear();
80 // assert(m_state.root() == m_previousBlock.stateRoot());
81 }
82 
83 Block::Block(Block const& _s):
84  m_state(_s.m_state),
85  m_transactions(_s.m_transactions),
86  m_receipts(_s.m_receipts),
87  m_transactionSet(_s.m_transactionSet),
88  m_precommit(_s.m_state),
89  m_previousBlock(_s.m_previousBlock),
90  m_currentBlock(_s.m_currentBlock),
91  m_currentBytes(_s.m_currentBytes),
92  m_author(_s.m_author),
93  m_sealEngine(_s.m_sealEngine)
94 {
95  m_committedToSeal = false;
96 }
97 
99 {
100  if (&_s == this)
101  return *this;
102 
103  m_state = _s.m_state;
104  m_transactions = _s.m_transactions;
105  m_receipts = _s.m_receipts;
106  m_transactionSet = _s.m_transactionSet;
107  m_previousBlock = _s.m_previousBlock;
108  m_currentBlock = _s.m_currentBlock;
109  m_currentBytes = _s.m_currentBytes;
110  m_author = _s.m_author;
111  m_sealEngine = _s.m_sealEngine;
112 
113  m_precommit = m_state;
114  m_committedToSeal = false;
115  return *this;
116 }
117 
118 void Block::resetCurrent(int64_t _timestamp)
119 {
120  m_transactions.clear();
121  m_receipts.clear();
122  m_transactionSet.clear();
123  m_currentBlock = BlockHeader();
124  m_currentBlock.setAuthor(m_author);
125  m_currentBlock.setTimestamp(max(m_previousBlock.timestamp() + 1, _timestamp));
126  m_currentBytes.clear();
127  sealEngine()->populateFromParent(m_currentBlock, m_previousBlock);
128 
129  // TODO: check.
130 
131  m_state.setRoot(m_previousBlock.stateRoot());
132  m_precommit = m_state;
133  m_committedToSeal = false;
134 
135  performIrregularModifications();
136  updateBlockhashContract();
137 }
138 
139 SealEngineFace* Block::sealEngine() const
140 {
141  if (!m_sealEngine)
142  BOOST_THROW_EXCEPTION(ChainOperationWithUnknownBlockChain());
143  return m_sealEngine;
144 }
145 
146 void Block::noteChain(BlockChain const& _bc)
147 {
148  if (!m_sealEngine)
149  {
152  m_sealEngine = _bc.sealEngine();
153  }
154 }
155 
157 {
158  noteChain(_bc);
159 
160  PopulationStatistics ret { 0.0, 0.0 };
161 
162  if (!_bc.isKnown(_h))
163  {
164  // Might be worth throwing here.
165  cwarn << "Invalid block given for state population: " << _h;
166  BOOST_THROW_EXCEPTION(BlockNotFound() << errinfo_target(_h));
167  }
168 
169  auto b = _bc.block(_h);
170  BlockHeader bi(b); // No need to check - it's already in the DB.
171  if (bi.number())
172  {
173  // Non-genesis:
174 
175  // 1. Start at parent's end state (state root).
176  BlockHeader bip(_bc.block(bi.parentHash()));
177  sync(_bc, bi.parentHash(), bip);
178 
179  // 2. Enact the block's transactions onto this state.
180  m_author = bi.author();
181  Timer t;
182  auto vb = _bc.verifyBlock(&b, function<void(Exception&)>(), _ir | ImportRequirements::TransactionBasic);
183  ret.verify = t.elapsed();
184  t.restart();
185  enact(vb, _bc);
186  ret.enact = t.elapsed();
187  }
188  else
189  {
190  // Genesis required:
191  // We know there are no transactions, so just populate directly.
192  m_state = State(m_state.accountStartNonce(), m_state.db(), BaseState::Empty); // TODO: try with PreExisting.
193  sync(_bc, _h, bi);
194  }
195 
196  return ret;
197 }
198 
199 bool Block::sync(BlockChain const& _bc)
200 {
201  return sync(_bc, _bc.currentHash());
202 }
203 
204 bool Block::sync(BlockChain const& _bc, h256 const& _block, BlockHeader const& _bi)
205 {
206  noteChain(_bc);
207 
208  bool ret = false;
209  // BLOCK
210  BlockHeader bi = _bi ? _bi : _bc.info(_block);
211 #if ETH_PARANOIA
212  if (!bi)
213  while (1)
214  {
215  try
216  {
217  auto b = _bc.block(_block);
218  bi.populate(b);
219  break;
220  }
221  catch (Exception const& _e)
222  {
223  // TODO: Slightly nicer handling? :-)
224  cerr << "ERROR: Corrupt block-chain! Delete your block-chain DB and restart." << endl;
225  cerr << diagnostic_information(_e) << endl;
226  }
227  catch (std::exception const& _e)
228  {
229  // TODO: Slightly nicer handling? :-)
230  cerr << "ERROR: Corrupt block-chain! Delete your block-chain DB and restart." << endl;
231  cerr << _e.what() << endl;
232  }
233  }
234 #endif
235  if (bi == m_currentBlock)
236  {
237  // We mined the last block.
238  // Our state is good - we just need to move on to next.
239  m_previousBlock = m_currentBlock;
240  resetCurrent();
241  ret = true;
242  }
243  else if (bi == m_previousBlock)
244  {
245  // No change since last sync.
246  // Carry on as we were.
247  }
248  else
249  {
250  // New blocks available, or we've switched to a different branch. All change.
251  // Find most recent state dump and replay what's left.
252  // (Most recent state dump might end up being genesis.)
253 
254  if (m_state.db().lookup(bi.stateRoot()).empty()) // TODO: API in State for this?
255  {
256  cwarn << "Unable to sync to" << bi.hash() << "; state root" << bi.stateRoot() << "not found in database.";
257  cwarn << "Database corrupt: contains block without stateRoot:" << bi;
258  cwarn << "Try rescuing the database by running: eth --rescue";
259  BOOST_THROW_EXCEPTION(InvalidStateRoot() << errinfo_target(bi.stateRoot()));
260  }
261  m_previousBlock = bi;
262  resetCurrent();
263  ret = true;
264  }
265 #if ALLOW_REBUILD
266  else
267  {
268  // New blocks available, or we've switched to a different branch. All change.
269  // Find most recent state dump and replay what's left.
270  // (Most recent state dump might end up being genesis.)
271 
272  std::vector<h256> chain;
273  while (bi.number() != 0 && m_db.lookup(bi.stateRoot()).empty()) // while we don't have the state root of the latest block...
274  {
275  chain.push_back(bi.hash()); // push back for later replay.
276  bi.populate(_bc.block(bi.parentHash())); // move to parent.
277  }
278 
279  m_previousBlock = bi;
280  resetCurrent();
281 
282  // Iterate through in reverse, playing back each of the blocks.
283  try
284  {
285  for (auto it = chain.rbegin(); it != chain.rend(); ++it)
286  {
287  auto b = _bc.block(*it);
288  enact(&b, _bc, _ir);
289  cleanup(true);
290  }
291  }
292  catch (...)
293  {
294  // TODO: Slightly nicer handling? :-)
295  cerr << "ERROR: Corrupt block-chain! Delete your block-chain DB and restart." << endl;
296  cerr << boost::current_exception_diagnostic_information() << endl;
297  exit(1);
298  }
299 
300  resetCurrent();
301  ret = true;
302  }
303 #endif
304  return ret;
305 }
306 
307 pair<TransactionReceipts, bool> Block::sync(BlockChain const& _bc, TransactionQueue& _tq, GasPricer const& _gp, unsigned msTimeout)
308 {
309  if (isSealed())
310  BOOST_THROW_EXCEPTION(InvalidOperationOnSealedBlock());
311 
312  noteChain(_bc);
313 
314  // TRANSACTIONS
315  pair<TransactionReceipts, bool> ret;
316 
317  Transactions transactions = _tq.topTransactions(c_maxSyncTransactions, m_transactionSet);
318  ret.second = (transactions.size() == c_maxSyncTransactions); // say there's more to the caller
319  // if we hit the limit
320 
321  assert(_bc.currentHash() == m_currentBlock.parentHash());
322  auto deadline = chrono::steady_clock::now() + chrono::milliseconds(msTimeout);
323 
324  for (int goodTxs = max(0, (int)transactions.size() - 1); goodTxs < (int)transactions.size();)
325  {
326  goodTxs = 0;
327  for (auto const& t : transactions)
328  if (!m_transactionSet.count(t.sha3()))
329  {
330  try
331  {
332  if (t.gasPrice() >= _gp.ask(*this))
333  {
334 // Timer t;
335  execute(_bc.lastBlockHashes(), t);
336  ret.first.push_back(m_receipts.back());
337  ++goodTxs;
338 // cnote << "TX took:" << t.elapsed() * 1000;
339  }
340  else if (t.gasPrice() < _gp.ask(*this) * 9 / 10)
341  {
342  LOG(m_logger)
343  << t.sha3() << " Dropping El Cheapo transaction (<90% of ask price)";
344  _tq.drop(t.sha3());
345  }
346  }
347  catch (InvalidNonce const& in)
348  {
349  bigint const& req = *boost::get_error_info<errinfo_required>(in);
350  bigint const& got = *boost::get_error_info<errinfo_got>(in);
351 
352  if (req > got)
353  {
354  // too old
355  LOG(m_logger) << t.sha3() << " Dropping old transaction (nonce too low)";
356  _tq.drop(t.sha3());
357  }
358  else if (got > req + _tq.waiting(t.sender()))
359  {
360  // too new
361  LOG(m_logger)
362  << t.sha3() << " Dropping new transaction (too many nonces ahead)";
363  _tq.drop(t.sha3());
364  }
365  else
366  _tq.setFuture(t.sha3());
367  }
368  catch (BlockGasLimitReached const& e)
369  {
370  bigint const& got = *boost::get_error_info<errinfo_got>(e);
371  if (got > m_currentBlock.gasLimit())
372  {
373  LOG(m_logger)
374  << t.sha3()
375  << " Dropping over-gassy transaction (gas > block's gas limit)";
376  LOG(m_logger)
377  << "got: " << got << " required: " << m_currentBlock.gasLimit();
378  _tq.drop(t.sha3());
379  }
380  else
381  {
382  LOG(m_logger) << t.sha3()
383  << " Temporarily no gas left in current block (txs gas > "
384  "block's gas limit)";
385  //_tq.drop(t.sha3());
386  // Temporarily no gas left in current block.
387  // OPTIMISE: could note this and then we don't evaluate until a block that does have the gas left.
388  // for now, just leave alone.
389  }
390  }
391  catch (Exception const& _e)
392  {
393  // Something else went wrong - drop it.
394  LOG(m_logger) << t.sha3() << " Dropping invalid transaction: "
395  << diagnostic_information(_e);
396  _tq.drop(t.sha3());
397  }
398  catch (std::exception const&)
399  {
400  // Something else went wrong - drop it.
401  _tq.drop(t.sha3());
402  cwarn << t.sha3() << "Transaction caused low-level exception :(";
403  }
404  }
405  if (chrono::steady_clock::now() > deadline)
406  {
407  ret.second = true; // say there's more to the caller if we ended up crossing the deadline.
408  break;
409  }
410  }
411  return ret;
412 }
413 
414 u256 Block::enactOn(VerifiedBlockRef const& _block, BlockChain const& _bc)
415 {
416  noteChain(_bc);
417 
418 #if ETH_TIMED_ENACTMENTS
419  Timer t;
420  double populateVerify;
421  double populateGrand;
422  double syncReset;
423  double enactment;
424 #endif
425 
426  // Check family:
427  BlockHeader biParent = _bc.info(_block.info.parentHash());
428  _block.info.verify(CheckNothingNew/*CheckParent*/, biParent);
429 
430 #if ETH_TIMED_ENACTMENTS
431  populateVerify = t.elapsed();
432  t.restart();
433 #endif
434 
435  BlockHeader biGrandParent;
436  if (biParent.number())
437  biGrandParent = _bc.info(biParent.parentHash());
438 
439 #if ETH_TIMED_ENACTMENTS
440  populateGrand = t.elapsed();
441  t.restart();
442 #endif
443 
444  sync(_bc, _block.info.parentHash(), BlockHeader());
445  resetCurrent();
446 
447 #if ETH_TIMED_ENACTMENTS
448  syncReset = t.elapsed();
449  t.restart();
450 #endif
451 
452  m_previousBlock = biParent;
453  auto ret = enact(_block, _bc);
454 
455 #if ETH_TIMED_ENACTMENTS
456  enactment = t.elapsed();
457  if (populateVerify + populateGrand + syncReset + enactment > 0.5)
458  LOG(m_logger) << "popVer/popGrand/syncReset/enactment = " << populateVerify << " / "
459  << populateGrand << " / " << syncReset << " / " << enactment;
460 #endif
461  return ret;
462 }
463 
464 u256 Block::enact(VerifiedBlockRef const& _block, BlockChain const& _bc)
465 {
466  noteChain(_bc);
467 
469 
470  // m_currentBlock is assumed to be prepopulated and reset.
471  assert(m_previousBlock.hash() == _block.info.parentHash());
472  assert(m_currentBlock.parentHash() == _block.info.parentHash());
473 
474  if (m_currentBlock.parentHash() != m_previousBlock.hash())
475  // Internal client error.
476  BOOST_THROW_EXCEPTION(InvalidParentHash());
477 
478  // Populate m_currentBlock with the correct values.
479  m_currentBlock.noteDirty();
480  m_currentBlock = _block.info;
481 
482 // cnote << "playback begins:" << m_currentBlock.hash() << "(without: " << m_currentBlock.hash(WithoutSeal) << ")";
483 // cnote << m_state;
484 
485  RLP rlp(_block.block);
486 
487  vector<bytes> receipts;
488 
489  // All ok with the block generally. Play back the transactions now...
490  unsigned i = 0;
491  DEV_TIMED_ABOVE("txExec", 500)
492  for (Transaction const& tr: _block.transactions)
493  {
494  try
495  {
496 // cnote << "Enacting transaction: " << tr.nonce() << tr.from() << state().transactionsFrom(tr.from()) << tr.value();
497  execute(_bc.lastBlockHashes(), tr);
498 // cnote << "Now: " << tr.from() << state().transactionsFrom(tr.from());
499 // cnote << m_state;
500  }
501  catch (Exception& ex)
502  {
503  ex << errinfo_transactionIndex(i);
504  throw;
505  }
506 
507  RLPStream receiptRLP;
508  m_receipts.back().streamRLP(receiptRLP);
509  receipts.push_back(receiptRLP.out());
510  ++i;
511  }
512 
513  h256 receiptsRoot;
514  DEV_TIMED_ABOVE(".receiptsRoot()", 500)
515  receiptsRoot = orderedTrieRoot(receipts);
516 
517  if (receiptsRoot != m_currentBlock.receiptsRoot())
518  {
519  InvalidReceiptsStateRoot ex;
520  ex << Hash256RequirementError(m_currentBlock.receiptsRoot(), receiptsRoot);
521  ex << errinfo_receipts(receipts);
522 // ex << errinfo_vmtrace(vmTrace(_block.block, _bc, ImportRequirements::None));
523  BOOST_THROW_EXCEPTION(ex);
524  }
525 
526  if (m_currentBlock.logBloom() != logBloom())
527  {
528  InvalidLogBloom ex;
529  ex << LogBloomRequirementError(m_currentBlock.logBloom(), logBloom());
530  ex << errinfo_receipts(receipts);
531  BOOST_THROW_EXCEPTION(ex);
532  }
533 
534  // Initialise total difficulty calculation.
535  u256 tdIncrease = m_currentBlock.difficulty();
536 
537  // Check uncles & apply their rewards to state.
538  if (rlp[2].itemCount() > 2)
539  {
540  TooManyUncles ex;
541  ex << errinfo_max(2);
542  ex << errinfo_got(rlp[2].itemCount());
543  BOOST_THROW_EXCEPTION(ex);
544  }
545 
546  vector<BlockHeader> rewarded;
547  h256Hash excluded;
548  DEV_TIMED_ABOVE("allKin", 500)
549  excluded = _bc.allKinFrom(m_currentBlock.parentHash(), 6);
550  excluded.insert(m_currentBlock.hash());
551 
552  unsigned ii = 0;
553  DEV_TIMED_ABOVE("uncleCheck", 500)
554  for (auto const& i: rlp[2])
555  {
556  try
557  {
558  auto h = sha3(i.data());
559  if (excluded.count(h))
560  {
561  UncleInChain ex;
562  ex << errinfo_comment("Uncle in block already mentioned");
563  ex << errinfo_unclesExcluded(excluded);
564  ex << errinfo_hash256(sha3(i.data()));
565  BOOST_THROW_EXCEPTION(ex);
566  }
567  excluded.insert(h);
568 
569  // CheckNothing since it's a VerifiedBlock.
570  BlockHeader uncle(i.data(), HeaderData, h);
571 
572  BlockHeader uncleParent;
573  if (!_bc.isKnown(uncle.parentHash()))
574  BOOST_THROW_EXCEPTION(UnknownParent() << errinfo_hash256(uncle.parentHash()));
575  uncleParent = BlockHeader(_bc.block(uncle.parentHash()));
576 
577  // m_currentBlock.number() - uncle.number() m_cB.n - uP.n()
578  // 1 2
579  // 2
580  // 3
581  // 4
582  // 5
583  // 6 7
584  // (8 Invalid)
585  bigint depth = (bigint)m_currentBlock.number() - (bigint)uncle.number();
586  if (depth > 6)
587  {
588  UncleTooOld ex;
589  ex << errinfo_uncleNumber(uncle.number());
590  ex << errinfo_currentNumber(m_currentBlock.number());
591  BOOST_THROW_EXCEPTION(ex);
592  }
593  else if (depth < 1)
594  {
595  UncleIsBrother ex;
596  ex << errinfo_uncleNumber(uncle.number());
597  ex << errinfo_currentNumber(m_currentBlock.number());
598  BOOST_THROW_EXCEPTION(ex);
599  }
600  // cB
601  // cB.p^1 1 depth, valid uncle
602  // cB.p^2 ---/ 2
603  // cB.p^3 -----/ 3
604  // cB.p^4 -------/ 4
605  // cB.p^5 ---------/ 5
606  // cB.p^6 -----------/ 6
607  // cB.p^7 -------------/
608  // cB.p^8
609  auto expectedUncleParent = _bc.details(m_currentBlock.parentHash()).parent;
610  for (unsigned i = 1; i < depth; expectedUncleParent = _bc.details(expectedUncleParent).parent, ++i) {}
611  if (expectedUncleParent != uncleParent.hash())
612  {
613  UncleParentNotInChain ex;
614  ex << errinfo_uncleNumber(uncle.number());
615  ex << errinfo_currentNumber(m_currentBlock.number());
616  BOOST_THROW_EXCEPTION(ex);
617  }
618  uncle.verify(CheckNothingNew/*CheckParent*/, uncleParent);
619 
620  rewarded.push_back(uncle);
621  ++ii;
622  }
623  catch (Exception& ex)
624  {
625  ex << errinfo_uncleIndex(ii);
626  throw;
627  }
628  }
629 
630  assert(_bc.sealEngine());
631  DEV_TIMED_ABOVE("applyRewards", 500)
632  applyRewards(rewarded, _bc.sealEngine()->blockReward(m_currentBlock.number()));
633 
634  // Commit all cached state changes to the state trie.
635  bool removeEmptyAccounts = m_currentBlock.number() >= _bc.chainParams().EIP158ForkBlock; // TODO: use EVMSchedule
636  DEV_TIMED_ABOVE("commit", 500)
637  m_state.commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);
638 
639  // Hash the state trie and check against the state_root hash in m_currentBlock.
640  if (m_currentBlock.stateRoot() != m_previousBlock.stateRoot() && m_currentBlock.stateRoot() != rootHash())
641  {
642  auto r = rootHash();
643  m_state.db().rollback(); // TODO: API in State for this?
644  BOOST_THROW_EXCEPTION(InvalidStateRoot() << Hash256RequirementError(m_currentBlock.stateRoot(), r));
645  }
646 
647  if (m_currentBlock.gasUsed() != gasUsed())
648  {
649  // Rollback the trie.
650  m_state.db().rollback(); // TODO: API in State for this?
651  BOOST_THROW_EXCEPTION(InvalidGasUsed() << RequirementError(bigint(m_currentBlock.gasUsed()), bigint(gasUsed())));
652  }
653 
654  return tdIncrease;
655 }
656 
658 {
659  if (isSealed())
660  BOOST_THROW_EXCEPTION(InvalidOperationOnSealedBlock());
661 
662  // Uncommitting is a non-trivial operation - only do it once we've verified as much of the
663  // transaction as possible.
664  uncommitToSeal();
665 
666  std::pair<ExecutionResult, TransactionReceipt> resultReceipt = m_state.execute(EnvInfo(info(), _lh, gasUsed()), *m_sealEngine, _t, _p, _onOp);
667 
668  if (_p == Permanence::Committed)
669  {
670  // Add to the user-originated transactions that we've executed.
671  m_transactions.push_back(_t);
672  m_receipts.push_back(resultReceipt.second);
673  m_transactionSet.insert(_t.sha3());
674  }
675 
676  return resultReceipt.first;
677 }
678 
679 void Block::applyRewards(vector<BlockHeader> const& _uncleBlockHeaders, u256 const& _blockReward)
680 {
681  u256 r = _blockReward;
682  for (auto const& i: _uncleBlockHeaders)
683  {
684  m_state.addBalance(i.author(), _blockReward * (8 + i.number() - m_currentBlock.number()) / 8);
685  r += _blockReward / 32;
686  }
687  m_state.addBalance(m_currentBlock.author(), r);
688 }
689 
690 void Block::performIrregularModifications()
691 {
692  u256 const& daoHardfork = m_sealEngine->chainParams().daoHardforkBlock;
693  if (daoHardfork != 0 && info().number() == daoHardfork)
694  {
695  Address recipient("0xbf4ed7b27f1d666546e30d74d50d173d20bca754");
696  Addresses allDAOs = childDaos();
697  for (Address const& dao: allDAOs)
698  m_state.transferBalance(dao, recipient, m_state.balance(dao));
700  }
701 }
702 
703 void Block::updateBlockhashContract()
704 {
705  u256 const& blockNumber = info().number();
706 
707  u256 const& forkBlock = m_sealEngine->chainParams().experimentalForkBlock;
708  if (blockNumber == forkBlock)
709  {
713  }
714 
715  if (blockNumber >= forkBlock)
716  {
717  DummyLastBlockHashes lastBlockHashes; // assuming blockhash contract won't need BLOCKHASH itself
718  Executive e(*this, lastBlockHashes);
719  h256 const parentHash = m_previousBlock.hash();
720  if (!e.call(c_blockhashContractAddress, SystemAddress, 0, 0, parentHash.ref(), 1000000))
721  e.go();
722  e.finalize();
723 
725  }
726 }
727 
728 void Block::commitToSeal(BlockChain const& _bc, bytes const& _extraData)
729 {
730  if (isSealed())
731  BOOST_THROW_EXCEPTION(InvalidOperationOnSealedBlock());
732 
733  noteChain(_bc);
734 
735  if (m_committedToSeal)
736  uncommitToSeal();
737  else
738  m_precommit = m_state;
739 
740  vector<BlockHeader> uncleBlockHeaders;
741 
742  RLPStream unclesData;
743  unsigned unclesCount = 0;
744  if (m_previousBlock.number() != 0)
745  {
746  // Find great-uncles (or second-cousins or whatever they are) - children of great-grandparents, great-great-grandparents... that were not already uncles in previous generations.
747  LOG(m_loggerDetailed) << "Checking " << m_previousBlock.hash()
748  << ", parent = " << m_previousBlock.parentHash();
749  h256Hash excluded = _bc.allKinFrom(m_currentBlock.parentHash(), 6);
750  auto p = m_previousBlock.parentHash();
751  for (unsigned gen = 0; gen < 6 && p != _bc.genesisHash() && unclesCount < 2; ++gen, p = _bc.details(p).parent)
752  {
753  auto us = _bc.details(p).children;
754  assert(us.size() >= 1); // must be at least 1 child of our grandparent - it's our own parent!
755  for (auto const& u: us)
756  if (!excluded.count(u)) // ignore any uncles/mainline blocks that we know about.
757  {
758  uncleBlockHeaders.push_back(_bc.info(u));
759  unclesData.appendRaw(_bc.headerData(u));
760  ++unclesCount;
761  if (unclesCount == 2)
762  break;
763  excluded.insert(u);
764  }
765  }
766  }
767 
768  BytesMap transactionsMap;
769  BytesMap receiptsMap;
770 
771  RLPStream txs;
772  txs.appendList(m_transactions.size());
773 
774  for (unsigned i = 0; i < m_transactions.size(); ++i)
775  {
776  RLPStream k;
777  k << i;
778 
779  RLPStream receiptrlp;
780  receipt(i).streamRLP(receiptrlp);
781  receiptsMap.insert(std::make_pair(k.out(), receiptrlp.out()));
782 
783  RLPStream txrlp;
784  m_transactions[i].streamRLP(txrlp);
785  transactionsMap.insert(std::make_pair(k.out(), txrlp.out()));
786 
787  txs.appendRaw(txrlp.out());
788  }
789 
790  txs.swapOut(m_currentTxs);
791 
792  RLPStream(unclesCount).appendRaw(unclesData.out(), unclesCount).swapOut(m_currentUncles);
793 
794  // Apply rewards last of all.
795  assert(_bc.sealEngine());
796  applyRewards(uncleBlockHeaders, _bc.sealEngine()->blockReward(m_currentBlock.number()));
797 
798  // Commit any and all changes to the trie that are in the cache, then update the state root accordingly.
799  bool removeEmptyAccounts = m_currentBlock.number() >= _bc.chainParams().EIP158ForkBlock; // TODO: use EVMSchedule
800  DEV_TIMED_ABOVE("commit", 500)
802 
803  LOG(m_loggerDetailed) << "Post-reward stateRoot: " << m_state.rootHash();
804  LOG(m_loggerDetailed) << m_state;
805 
806  m_currentBlock.setLogBloom(logBloom());
807  m_currentBlock.setGasUsed(gasUsed());
808  m_currentBlock.setRoots(hash256(transactionsMap), hash256(receiptsMap),
809  sha3(m_currentUncles), m_state.rootHash());
810 
811  m_currentBlock.setParentHash(m_previousBlock.hash());
812  m_currentBlock.setExtraData(_extraData);
813  if (m_currentBlock.extraData().size() > 32)
814  {
815  auto ed = m_currentBlock.extraData();
816  ed.resize(32);
817  m_currentBlock.setExtraData(ed);
818  }
819 
820  m_committedToSeal = true;
821 }
822 
823 void Block::uncommitToSeal()
824 {
825  if (m_committedToSeal)
826  {
827  m_state = m_precommit;
828  m_committedToSeal = false;
829  }
830 }
831 
833 {
834  if (!m_committedToSeal)
835  return false;
836 
837  if (BlockHeader(_header, HeaderData).hash(WithoutSeal) != m_currentBlock.hash(WithoutSeal))
838  return false;
839 
840  // Compile block:
841  RLPStream ret;
842  ret.appendList(3);
843  ret.appendRaw(_header);
844  ret.appendRaw(m_currentTxs);
845  ret.appendRaw(m_currentUncles);
846  ret.swapOut(m_currentBytes);
847  m_currentBlock = BlockHeader(_header, HeaderData);
848 // cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash() << ")";
849  // TODO: move into SealEngine
850 
851  m_state = m_precommit;
852 
853  // m_currentBytes is now non-empty; we're in a sealed state so no more transactions can be added.
854 
855  return true;
856 }
857 
858 h256 Block::stateRootBeforeTx(unsigned _i) const
859 {
860  _i = min<unsigned>(_i, m_transactions.size());
861  try
862  {
863  return (_i > 0 ? receipt(_i - 1).stateRoot() : m_previousBlock.stateRoot());
864  }
865  catch (TransactionReceiptVersionError const&)
866  {
867  return {};
868  }
869 }
870 
872 {
873  LogBloom ret;
874  for (TransactionReceipt const& i: m_receipts)
875  ret |= i.bloom();
876  return ret;
877 }
878 
880 {
881  // Commit the new trie to disk.
882  LOG(m_logger) << "Committing to disk: stateRoot " << m_currentBlock.stateRoot() << " = "
883  << rootHash() << " = " << toHex(asBytes(db().lookup(rootHash())));
884 
885  try
886  {
887  EnforceRefs er(db(), true);
888  rootHash();
889  }
890  catch (BadRoot const&)
891  {
892  cwarn << "Trie corrupt! :-(";
893  throw;
894  }
895 
896  m_state.db().commit(); // TODO: State API for this?
897 
898  LOG(m_logger) << "Committed: stateRoot " << m_currentBlock.stateRoot() << " = " << rootHash()
899  << " = " << toHex(asBytes(db().lookup(rootHash())));
900 
901  m_previousBlock = m_currentBlock;
902  sealEngine()->populateFromParent(m_currentBlock, m_previousBlock);
903 
904  LOG(m_logger) << "finalising enactment. current -> previous, hash is "
905  << m_previousBlock.hash();
906 
907  resetCurrent();
908 }
dev::eth::TransactionQueue::topTransactions
Transactions topTransactions(unsigned _limit, h256Hash const &_avoid=h256Hash()) const
Definition: TransactionQueue.cpp:102
dev::eth::BlockChain::info
BlockHeader info(h256 const &_hash) const
Get the partial-header of a block (or the most recent mined if none given). Thread-safe.
Definition: BlockChain.h:145
dev::eth::BlockChain::currentHash
h256 currentHash() const
Get a given block (RLP format). Thread-safe.
Definition: BlockChain.h:228
dev::eth::OnOpFunc
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VMFace const *, ExtVMFace const *)> OnOpFunc
Definition: ExtVMFace.h:115
dev::eth::GasPricer::ask
virtual u256 ask(Block const &) const =0
dev::eth::BlockChain::headerData
bytes headerData(h256 const &_hash) const
Get a block (RLP format) for the given hash (or the most recent mined if none given)....
Definition: BlockChain.cpp:1451
dev::eth::Block::commitToSeal
void commitToSeal(BlockChain const &_bc, bytes const &_extraData={})
Definition: Block.cpp:728
dev::OverlayDB::rollback
void rollback()
Definition: OverlayDB.cpp:117
dev::eth::State::rootHash
h256 rootHash() const
The hash of the root of our state tree.
Definition: State.h:310
dev::eth::State::CommitBehaviour::RemoveEmptyAccounts
@ RemoveEmptyAccounts
dev::eth::State::accountStartNonce
u256 const & accountStartNonce() const
Get the account start nonce. May be required.
Definition: State.h:320
dev::eth::Transaction
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:86
dev::eth::BlockHeader::hash
h256 hash(IncludeSeal _i=WithSeal) const
Definition: BlockHeader.cpp:119
dev::eth::HeaderData
@ HeaderData
Definition: BlockHeader.h:69
dev::vector_ref< byte const >
dev::eth::BlockHeader
Encapsulation of a block header. Class to contain all of a block header's data. It is able to parse a...
Definition: BlockHeader.h:97
dev::eth::SealEngineFace
Definition: SealEngine.h:46
dev::eth::BlockHeader::setLogBloom
void setLogBloom(LogBloom const &_v)
Definition: BlockHeader.h:152
dev::eth::TransactionException::BlockGasLimitReached
@ BlockGasLimitReached
dev::eth::Transactions
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
Definition: Transaction.h:122
dev::BytesMap
std::map< bytes, bytes > BytesMap
Definition: Common.h:134
dev::eth::BlockHeader::extraData
bytes const & extraData() const
Definition: BlockHeader.h:168
dev::eth::Block::populateFromChain
PopulationStatistics populateFromChain(BlockChain const &_bc, h256 const &_hash, ImportRequirements::value _ir=ImportRequirements::None)
Construct state object from arbitrary point in blockchain.
Definition: Block.cpp:156
dev::eth::Block::rootHash
h256 rootHash() const
The hash of the root of our state tree.
Definition: Block.h:164
dev::eth::BlockDetails::children
h256s children
Definition: BlockDetails.h:54
dev::sha3
bool sha3(bytesConstRef _input, bytesRef o_output) noexcept
Definition: SHA3.cpp:28
dev::eth::Block::enactOn
u256 enactOn(VerifiedBlockRef const &_block, BlockChain const &_bc)
Definition: Block.cpp:414
dev::eth::BaseState::Empty
@ Empty
dev::eth::Permanence
Permanence
Definition: State.h:73
dev::eth::BlockChain::genesisHash
h256 genesisHash() const
Get the hash of the genesis block. Thread-safe.
Definition: BlockChain.h:231
dev::eth::Block::stateRootBeforeTx
h256 stateRootBeforeTx(unsigned _i) const
Definition: Block.cpp:858
dev::FixedHash::ref
bytesRef ref()
Definition: FixedHash.h:132
GenesisInfo.h
dev::eth::BlockHeader::setGasUsed
void setGasUsed(u256 const &_v)
Definition: BlockHeader.h:148
dev::errinfo_hash256
boost::error_info< struct tag_hash, h256 > errinfo_hash256
Definition: Exceptions.h:89
dev::Timer
Definition: Common.h:256
dev::eth::ChainOperationParams::experimentalForkBlock
u256 experimentalForkBlock
Definition: ChainOperationParams.h:98
dev::eth::BlockHeader::stateRoot
h256 const & stateRoot() const
Definition: BlockHeader.h:162
dev::eth::BlockHeader::logBloom
LogBloom const & logBloom() const
Definition: BlockHeader.h:169
dev::eth::BlockChain::isKnown
bool isKnown(h256 const &_hash, bool _isCurrent=true) const
Returns true if the given block is known (though not necessarily a part of the canon chain).
Definition: BlockChain.cpp:1404
dev::eth::ImportRequirements::value
unsigned value
Definition: Common.h:112
dev::orderedTrieRoot
h256 orderedTrieRoot(std::vector< bytes > const &_data)
Definition: TrieHash.cpp:112
dev::eth::State::noteAccountStartNonce
void noteAccountStartNonce(u256 const &_actual)
Definition: State.cpp:117
dev::RLPStream::out
bytes const & out() const
Read the byte stream.
Definition: RLP.h:419
Exceptions.h
dev::eth::PopulationStatistics
Definition: Block.h:55
dev::eth::VerifiedBlockRef::block
bytesConstRef block
Block data reference.
Definition: VerifiedBlock.h:38
dev::eth::commit
AddressHash commit(AccountMap const &_cache, SecureTrieDB< Address, DB > &_state)
Definition: State.cpp:759
dev::eth::TransactionReceipt::streamRLP
void streamRLP(RLPStream &_s) const
Definition: TransactionReceipt.cpp:68
dev::eth::State::commit
void commit(CommitBehaviour _commitBehaviour)
Definition: State.cpp:200
dev::eth
Definition: BasicAuthority.h:32
dev::eth::SealEngineFace::chainParams
ChainOperationParams const & chainParams() const
Definition: SealEngine.h:80
dev::eth::BlockChain::sealEngine
SealEngineFace * sealEngine() const
Definition: BlockChain.h:308
dev::eth::BlockHeader::clear
void clear()
Definition: BlockHeader.cpp:100
dev::eth::BlockHeader::verify
void verify(Strictness _s=CheckEverything, BlockHeader const &_parent=BlockHeader(), bytesConstRef _block=bytesConstRef()) const
Definition: BlockHeader.cpp:210
dev::rlp
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
Definition: RLP.h:453
dev::eth::ChainOperationParams::daoHardforkBlock
u256 daoHardforkBlock
Definition: ChainOperationParams.h:97
dev::eth::ChainOperationParams::EIP158ForkBlock
u256 EIP158ForkBlock
Definition: ChainOperationParams.h:92
dev::Addresses
h160s Addresses
A vector of Ethereum addresses.
Definition: Address.h:33
dev::eth::Block::logBloom
LogBloom logBloom() const
Get the bloom filter of all logs that happened in the block.
Definition: Block.cpp:871
dev::FixedHash
Definition: FixedHash.h:47
dev::Timer::elapsed
double elapsed() const
Definition: Common.h:261
dev::eth::Block::noteChain
void noteChain(BlockChain const &_bc)
Definition: Block.cpp:146
DEV_TIMED_ABOVE
#define DEV_TIMED_ABOVE(S, MS)
Definition: Common.h:276
dev::OverlayDB::commit
void commit()
Definition: OverlayDB.cpp:48
dev::eth::State::addBalance
void addBalance(Address const &_id, u256 const &_amount)
Definition: State.cpp:346
dev::Exception
Base class for all exceptions.
Definition: Exceptions.h:39
LOG
#define LOG
Definition: Log.h:63
dev::hash256
h256 hash256(BytesMap const &_s)
Definition: TrieHash.cpp:107
dev::eth::BlockChain::details
BlockDetails details(h256 const &_hash) const
Get the familial details concerning a block (or the most recent mined if none given)....
Definition: BlockChain.h:157
dev::eth::BlockHeader::setTimestamp
void setTimestamp(int64_t _v)
Definition: BlockHeader.h:145
dev::eth::BlockHeader::setRoots
void setRoots(h256 const &_t, h256 const &_r, h256 const &_u, h256 const &_s)
Definition: BlockHeader.h:147
dev::eth::errinfo_target
boost::error_info< struct tag_target, h256 > errinfo_target
Definition: Exceptions.h:38
dev::eth::BlockChain::chainParams
ChainParams const & chainParams() const
Definition: BlockChain.h:306
dev::eth::SealEngineFace::blockReward
virtual u256 blockReward(u256 const &_blockNumber) const =0
dev::h256Hash
std::unordered_set< h256 > h256Hash
Definition: FixedHash.h:365
dev::h256s
std::vector< h256 > h256s
Definition: FixedHash.h:361
CommonIO.h
Block.h
ExtVM.h
dev::eth::BlockHeader::parentHash
h256 const & parentHash() const
Definition: BlockHeader.h:157
dev::eth::Block::Block
Block(u256 const &_accountStartNonce)
Default constructor; creates with a blank database prepopulated with the genesis block.
Definition: Block.h:80
dev::errinfo_got
boost::error_info< struct tag_got, bigint > errinfo_got
Definition: Exceptions.h:84
dev::OverlayDB::lookup
std::string lookup(h256 const &_h) const
Definition: OverlayDB.cpp:125
dev::eth::c_blockhashContractCode
const bytes c_blockhashContractCode
Code of the special contract for block hash storage defined in EIP96.
dev::eth::Block::execute
ExecutionResult execute(LastBlockHashesFace const &_lh, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
Definition: Block.cpp:657
dev::eth::BlockChain::allKinFrom
h256Hash allKinFrom(h256 const &_parent, unsigned _generations) const
Definition: BlockChain.cpp:1388
dev::eth::errinfo_transactionIndex
boost::error_info< struct tag_transactionIndex, unsigned > errinfo_transactionIndex
Definition: State.h:51
dev::eth::Block::cleanup
void cleanup()
Returns back to a pristine state after having done a playback.
Definition: Block.cpp:879
dev::bytes
std::vector< byte > bytes
Definition: Common.h:72
dev::eth::BlockChain::verifyBlock
VerifiedBlockRef verifyBlock(bytesConstRef _block, std::function< void(Exception &)> const &_onBad, ImportRequirements::value _ir=ImportRequirements::OutOfOrderChecks) const
Verify block and prepare it for enactment.
Definition: BlockChain.cpp:1501
dev::eth::errinfo_uncleNumber
boost::error_info< struct tag_uncleNumber, u256 > errinfo_uncleNumber
Definition: State.h:46
SealEngine.h
VMFactory.h
dev::eth::Executive
Message-call/contract-creation executor; useful for executing transactions.
Definition: Executive.h:104
dev::eth::BlockChain
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
Definition: BlockChain.h:105
dev::eth::BlockChain::lastBlockHashes
LastBlockHashesFace const & lastBlockHashes() const
Definition: BlockChain.h:186
dev::eth::BlockHeader::number
int64_t number() const
Definition: BlockHeader.h:166
dev::eth::BlockHeader::noteDirty
void noteDirty() const
Definition: BlockHeader.h:133
dev::eth::SealEngineFace::populateFromParent
virtual void populateFromParent(BlockHeader &_bi, BlockHeader const &_parent) const
Don't forget to call Super::populateFromParent when subclassing & overriding.
Definition: SealEngine.cpp:126
TrieHash.h
dev::eth::State::CommitBehaviour::KeepEmptyAccounts
@ KeepEmptyAccounts
Executive.h
dev::eth::TransactionBase::sha3
h256 sha3(IncludeSignature _sig=WithSignature) const
Definition: TransactionBase.cpp:212
dev::eth::c_blockhashContractAddress
const Address c_blockhashContractAddress(0xf0)
Address of the special contract for block hash storage defined in EIP96.
Definition: Common.h:34
dev::eth::Block::isSealed
bool isSealed() const
Definition: Block.h:266
dev::OverlayDB
Definition: OverlayDB.h:34
BlockChain.h
dev::Invalid256
constexpr u256 Invalid256
Definition: Common.h:147
dev::eth::errinfo_uncleIndex
boost::error_info< struct tag_uncleIndex, unsigned > errinfo_uncleIndex
Definition: State.h:44
dev::eth::TransactionQueue
A queue of Transactions, each stored as RLP. Maintains a transaction queue sorted by nonce diff and g...
Definition: TransactionQueue.h:45
dev::RLPStream
Class for writing to an RLP bytestream.
Definition: RLP.h:370
dev::eth::TransactionQueue::setFuture
void setFuture(h256 const &_t)
Definition: TransactionQueue.cpp:253
dev::eth::BaseState
BaseState
Definition: State.h:67
dev::Timer::restart
void restart()
Definition: Common.h:262
dev::eth::State::db
OverlayDB const & db() const
Definition: State.h:195
dev::eth::BlockDetails::parent
h256 parent
Definition: BlockDetails.h:53
dev::bigint
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
Definition: Common.h:118
dev::eth::State::transferBalance
void transferBalance(Address const &_from, Address const &_to, u256 const &_value)
Transfers "the balance _value between two accounts.
Definition: State.h:251
dev::eth::Block::resetCurrent
void resetCurrent(int64_t _timestamp=utcTime())
Definition: Block.cpp:118
dev::eth::Block::db
OverlayDB const & db() const
Open a DB - useful for passing into the constructor & keeping for other states that are necessary.
Definition: Block.h:161
dev::eth::errinfo_unclesExcluded
boost::error_info< struct tag_unclesExcluded, h256Hash > errinfo_unclesExcluded
Definition: State.h:47
Assertions.h
dev::errinfo_max
boost::error_info< struct tag_max, bigint > errinfo_max
Definition: Exceptions.h:86
dev::asBytes
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
Definition: CommonData.h:106
dev::eth::Permanence::Committed
@ Committed
dev::eth::Block::receipt
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
Definition: Block.h:189
dev::eth::BlockHeader::setExtraData
void setExtraData(bytes const &_v)
Definition: BlockHeader.h:151
std
Definition: FixedHash.h:393
dev::eth::State
Definition: State.h:160
dev::eth::BlockHeader::setParentHash
void setParentHash(h256 const &_v)
Definition: BlockHeader.h:143
dev::u256
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:121
dev::EnforceRefs
Definition: StateCacheDB.h:68
dev::eth::errinfo_receipts
boost::error_info< struct tag_receipts, std::vector< bytes > > errinfo_receipts
Definition: State.h:54
dev::eth::BlockChain::block
bytes block(h256 const &_hash) const
Get a block (RLP format) for the given hash (or the most recent mined if none given)....
Definition: BlockChain.cpp:1423
dev::eth::errinfo_currentNumber
boost::error_info< struct tag_currentNumber, u256 > errinfo_currentNumber
Definition: State.h:45
dev::eth::VerifiedBlockRef
Verified block info, does not hold block data, but a reference instead.
Definition: VerifiedBlock.h:37
dev::RLPStream::swapOut
void swapOut(bytes &_dest)
Swap the contents of the output stream out for some other byte array.
Definition: RLP.h:425
dev::eth::State::setRoot
void setRoot(h256 const &_root)
Resets any uncommitted changes to the cache.
Definition: State.cpp:282
dev::eth::Block::sealBlock
bool sealBlock(bytes const &_header)
Definition: Block.h:262
dev::eth::TransactionReceipt
Definition: TransactionReceipt.h:40
dev::Hash256RequirementError
boost::tuple< errinfo_required_h256, errinfo_got_h256 > Hash256RequirementError
Definition: Exceptions.h:92
dev::eth::BlockHeader::author
Address const & author() const
Definition: BlockHeader.h:161
dev::eth::BlockHeader::setAuthor
void setAuthor(Address const &_v)
Definition: BlockHeader.h:146
dev
Definition: Address.cpp:21
dev::eth::State::setCode
void setCode(Address const &_address, bytes &&_code)
Sets the code of the account. Must only be called during / after contract creation.
Definition: State.cpp:520
dev::RequirementError
boost::tuple< errinfo_required, errinfo_got > RequirementError
Definition: Exceptions.h:87
dev::eth::State::balance
u256 balance(Address const &_id) const
Definition: State.cpp:312
dev::eth::CheckNothingNew
@ CheckNothingNew
Definition: BlockHeader.h:51
dev::eth::Block::info
BlockHeader const & info() const
Get the header information on the present block.
Definition: Block.h:273
dev::eth::ExecutionResult
Description of the result of executing a transaction.
Definition: Transaction.h:71
dev::eth::TransactionQueue::waiting
unsigned waiting(Address const &_a) const
Definition: TransactionQueue.cpp:240
dev::eth::BaseState::PreExisting
@ PreExisting
dev::eth::BlockHeader::gasLimit
u256 const & gasLimit() const
Definition: BlockHeader.h:167
dev::eth::BlockHeader::receiptsRoot
h256 const & receiptsRoot() const
Definition: BlockHeader.h:164
cwarn
#define cwarn
dev::RLPStream::appendRaw
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
Definition: RLP.cpp:222
dev::eth::childDaos
dev::Addresses childDaos()
Definition: GenesisInfo.cpp:303
dev::eth::GasPricer
Definition: GasPricer.h:46
dev::toHex
std::string toHex(Iterator _it, Iterator _end, std::string const &_prefix)
Definition: CommonData.h:46
dev::eth::State::execute
std::pair< ExecutionResult, TransactionReceipt > execute(EnvInfo const &_envInfo, SealEngineFace const &_sealEngine, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
Definition: State.cpp:598
dev::eth::TransactionQueue::drop
void drop(h256 const &_txHash)
Definition: TransactionQueue.cpp:323
dev::eth::TransactionException::InvalidNonce
@ InvalidNonce
dev::eth::ImportResult::UnknownParent
@ UnknownParent
dev::SystemAddress
Address const SystemAddress
The SYSTEM address.
Definition: Address.cpp:24
dev::eth::State::createContract
void createContract(Address const &_address)
Create a contract at the given address (with unset code and unchanged balance).
Definition: State.cpp:394
dev::eth::ImportRequirements::TransactionBasic
@ TransactionBasic
Check the basic structure of the transactions.
Definition: Common.h:117
dev::eth::EnvInfo
Definition: ExtVMFace.h:143
dev::eth::LastBlockHashesFace
Interface for getting a list of recent block hashes @threadsafe.
Definition: LastBlockHashesFace.h:37
dev::RLP
Definition: RLP.h:48
dev::eth::BlockHeader::difficulty
u256 const & difficulty() const
Definition: BlockHeader.h:170
dev::eth::Block
Active model of a block within the block chain. Keeps track of all transactions, receipts and state f...
Definition: Block.h:69
TransactionQueue.h
dev::eth::LogBloomRequirementError
boost::tuple< errinfo_required_LogBloom, errinfo_got_LogBloom > LogBloomRequirementError
Definition: State.h:59
dev::RLPStream::appendList
RLPStream & appendList(size_t _items)
Appends a list.
Definition: RLP.cpp:268
dev::errinfo_comment
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:69
dev::eth::BlockHeader::gasUsed
u256 const & gasUsed() const
Definition: BlockHeader.h:165
dev::eth::WithoutSeal
@ WithoutSeal
Definition: BlockHeader.h:41
dev::eth::BlockHeader::timestamp
int64_t timestamp() const
Definition: BlockHeader.h:160
dev::eth::Block::sync
std::pair< TransactionReceipts, bool > sync(BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
Definition: Block.cpp:307
dev::eth::ChainOperationParams::accountStartNonce
u256 accountStartNonce
Definition: ChainOperationParams.h:85
dev::eth::VerifiedBlockRef::info
BlockHeader info
Prepopulated block info.
Definition: VerifiedBlock.h:39
DEV_TIMED_FUNCTION_ABOVE
#define DEV_TIMED_FUNCTION_ABOVE(MS)
Definition: Common.h:281
dev::eth::Block::operator=
Block & operator=(Block const &_s)
Copy state object.
Definition: Block.cpp:98