Fabcoin Core  0.16.2
P2P Digital Currency
BlockChainHelper.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 */
23 #include <libethereum/Block.h>
24 #include <libethereum/BlockChain.h>
30 using namespace std;
31 using namespace json_spirit;
32 using namespace dev;
33 using namespace dev::eth;
34 
35 namespace dev
36 {
37 namespace test
38 {
39 
40 TestTransaction::TestTransaction(mObject const& _o):
41  m_jsonTransaction(_o)
42 {
43  ImportTest::importTransaction(_o, m_transaction); //check that json structure is valid
44 }
45 
47 {
48  m_dirty = false;
49 }
50 
51 TestBlock::TestBlock(mObject const& _blockObj, mObject const& _stateObj):
52  TestBlock()
53 {
54  m_tempDirState = std::unique_ptr<TransientDirectory>(new TransientDirectory());
55 
56  m_state = std::unique_ptr<State>(new State(0, OverlayDB(State::openDB(m_tempDirState.get()->path(), h256{}, WithExisting::Kill)), BaseState::Empty));
57  ImportTest::importState(_stateObj, *m_state.get());
58  m_state.get()->commit(State::CommitBehaviour::KeepEmptyAccounts);
59 
60  json_spirit::mObject state = _stateObj;
63 
64  m_blockHeader = constructBlock(_blockObj, _stateObj.size() ? m_state.get()->rootHash() : h256{});
66 }
67 
68 TestBlock::TestBlock(std::string const& _blockRLP):
69  TestBlock()
70 {
71  m_bytes = importByteArray(_blockRLP);
72 
73  RLP root(m_bytes);
75 
77  m_testTransactions.clear();
78  for (auto const& tr: root[1])
79  {
80  Transaction tx(tr.data(), CheckTransaction::Everything);
81  TestTransaction testTx(tx);
82  m_transactionQueue.import(tx.rlp());
83  m_testTransactions.push_back(testTx);
84  }
85 
86  for (auto const& uRLP: root[2])
87  {
88  BlockHeader uBl(uRLP.data(), HeaderData);
89  TestBlock uncle;
90  uncle.setBlockHeader(uBl);
91  m_uncles.push_back(uncle);
92  }
93 }
94 
96 {
97  populateFrom(_original);
98 }
99 
101 {
102  populateFrom(_original);
103  return *this;
104 }
105 
106 void TestBlock::setState(State const& _state)
107 {
108  copyStateFrom(_state);
109 }
110 
112 {
113  try
114  {
115  m_testTransactions.push_back(_tr);
116  if (m_transactionQueue.import(_tr.transaction().rlp()) != ImportResult::Success)
117  cnote << TestOutputHelper::testName() + "Test block failed importing transaction\n";
118  }
119  catch (Exception const& _e)
120  {
121  BOOST_ERROR(TestOutputHelper::testName() + "Failed transaction constructor with Exception: " << diagnostic_information(_e));
122  }
123  catch (exception const& _e)
124  {
125  cnote << _e.what();
126  }
127 
129 }
130 
131 void TestBlock::addUncle(TestBlock const& _uncle)
132 {
133  m_uncles.push_back(_uncle);
135 }
136 
137 void TestBlock::setUncles(vector<TestBlock> const& _uncles)
138 {
139  m_uncles.clear();
140  m_uncles = _uncles;
142 }
143 
145 {
146  //alter blockheader with defined fields before actual mining
147 
148  if (m_premineUpdate.count("parentHash") > 0)
149  _blockInfo.setParentHash(m_blockHeader.parentHash());
150  if (m_premineUpdate.count("coinbase") > 0)
151  _blockInfo.setAuthor(m_blockHeader.author());
152 
153  if (m_premineUpdate.count("uncleHash") > 0 || m_premineUpdate.count("stateRoot") > 0 ||
154  m_premineUpdate.count("transactionsTrie") > 0 || m_premineUpdate.count("receiptTrie") > 0)
155  _blockInfo.setRoots(m_premineUpdate.count("transactionsTrie") > 0 ? m_blockHeader.transactionsRoot() : _blockInfo.transactionsRoot(),
156  m_premineUpdate.count("receiptTrie") > 0 ? m_blockHeader.receiptsRoot() : _blockInfo.receiptsRoot(),
157  m_premineUpdate.count("uncleHash") > 0 ? m_blockHeader.sha3Uncles() : _blockInfo.sha3Uncles(),
158  m_premineUpdate.count("stateRoot") > 0 ? m_blockHeader.stateRoot() : _blockInfo.stateRoot());
159 
160  if (m_premineUpdate.count("bloom") > 0)
161  _blockInfo.setLogBloom(m_blockHeader.logBloom());
162  if (m_premineUpdate.count("difficulty") > 0)
163  _blockInfo.setDifficulty(m_blockHeader.difficulty());
164  if (m_premineUpdate.count("number") > 0)
165  _blockInfo.setNumber(m_blockHeader.number());
166  if (m_premineUpdate.count("gasLimit") > 0)
167  _blockInfo.setGasLimit(m_blockHeader.gasLimit());
168  if (m_premineUpdate.count("gasUsed") > 0)
169  _blockInfo.setGasUsed(m_blockHeader.gasUsed());
170  if (m_premineUpdate.count("timestamp") > 0)
171  _blockInfo.setTimestamp(m_blockHeader.timestamp());
172  if (m_premineUpdate.count("extraData") > 0)
173  _blockInfo.setExtraData(m_blockHeader.extraData());
174 
175  m_premineHeader = _blockInfo; //needed for check that any altered fields are altered in mined block as well
176 }
177 
179 {
180  TestBlock const& genesisBlock = _bc.testGenesis();
181  OverlayDB const& genesisDB = genesisBlock.state().db();
182 
183  BlockChain const& blockchain = _bc.interface();
184 
185  Block block = blockchain.genesisBlock(genesisDB);
186  block.setAuthor(genesisBlock.beneficiary());
187 
188  //set some header data before mining from original blockheader
189  BlockHeader& blockInfo = *const_cast<BlockHeader*>(&block.info());
190 
191  try
192  {
193  ZeroGasPricer gp;
194  block.sync(blockchain); //sync block with blockchain
195 
196  premineUpdate(blockInfo);
197 
198  size_t transactionsOnImport = m_transactionQueue.topTransactions(100).size();
199  block.sync(blockchain, m_transactionQueue, gp);
200  if (transactionsOnImport > m_transactionQueue.topTransactions(100).size())
201  cnote << "Dropped invalid Transactions when mining!";
202 
203  dev::eth::mine(block, blockchain, blockchain.sealEngine());
204  blockchain.sealEngine()->verify(JustSeal, block.info());
205  }
206  catch (Exception const& _e)
207  {
208  cnote << TestOutputHelper::testName() + "block sync or mining did throw an exception: " << diagnostic_information(_e);
209  return;
210  }
211  catch (std::exception const& _e)
212  {
213  cnote << TestOutputHelper::testName() + "block sync or mining did throw an exception: " << _e.what();
214  return;
215  }
216 
217  size_t validTransactions = m_transactionQueue.topTransactions(100).size();
218  m_receipts = RLPStream(validTransactions);
219  for (size_t i = 0; i < validTransactions; i++)
220  {
221  const dev::bytes receipt = block.receipt(i).rlp();
222  m_receipts.appendRaw(receipt);
223  }
224 
225  m_blockHeader = BlockHeader(block.blockData()); // NOTE no longer checked at this point in new API. looks like it was unimportant anyway
226  cnote << "Mined TrRoot: " << m_blockHeader.transactionsRoot();
227  copyStateFrom(block.state());
228 
229  //Invalid uncles are dropped when mining. but we restore the hash to produce block with invalid uncles (for later test when importing to blockchain)
230  if (m_uncles.size())
231  {
232  //Fill info with uncles
233  RLPStream uncleStream;
234  uncleStream.appendList(m_uncles.size());
235  for (unsigned i = 0; i < m_uncles.size(); ++i)
236  {
237  RLPStream uncleRlp;
238  m_uncles[i].blockHeader().streamRLP(uncleRlp);
239  uncleStream.appendRaw(uncleRlp.out());
240  }
241 
242  m_blockHeader.setSha3Uncles(sha3(uncleStream.out()));
243  updateNonce(_bc);
244  }
245  else
247 }
248 
250 {
251  m_blockHeader = _header;
253 }
254 
256 BlockHeader TestBlock::constructBlock(mObject const& _o, h256 const& _stateRoot)
257 {
258  BlockHeader ret;
259  try
260  {
261  const dev::bytes c_blockRLP = createBlockRLPFromFields(_o, _stateRoot);
262  ret = BlockHeader(c_blockRLP, HeaderData);
263 // cdebug << "Block constructed of hash" << ret.hash() << "(without:" << ret.hash(WithoutSeal) << ")";
264  }
265  catch (Exception const& _e)
266  {
267  cnote << TestOutputHelper::testName() + "block population did throw an exception: " << diagnostic_information(_e);
268  }
269  catch (std::exception const& _e)
270  {
271  BOOST_ERROR(TestOutputHelper::testName() + "Failed block population with Exception: " << _e.what());
272  }
273  catch(...)
274  {
275  BOOST_ERROR(TestOutputHelper::testName() + "block population did throw an unknown exception\n");
276  }
277  return ret;
278 }
279 
281 {
282  RLPStream rlpStream;
283  rlpStream.appendList(_tObj.count("hash") > 0 ? (_tObj.size() - 1) : _tObj.size());
284 
285  if (_tObj.count("parentHash"))
286  rlpStream << importByteArray(_tObj.at("parentHash").get_str());
287 
288  if (_tObj.count("uncleHash"))
289  rlpStream << importByteArray(_tObj.at("uncleHash").get_str());
290 
291  if (_tObj.count("coinbase"))
292  rlpStream << importByteArray(_tObj.at("coinbase").get_str());
293 
294  if (_stateRoot)
295  rlpStream << _stateRoot;
296  else if (_tObj.count("stateRoot"))
297  rlpStream << importByteArray(_tObj.at("stateRoot").get_str());
298 
299  if (_tObj.count("transactionsTrie"))
300  rlpStream << importByteArray(_tObj.at("transactionsTrie").get_str());
301 
302  if (_tObj.count("receiptTrie"))
303  rlpStream << importByteArray(_tObj.at("receiptTrie").get_str());
304 
305  if (_tObj.count("bloom"))
306  rlpStream << importByteArray(_tObj.at("bloom").get_str());
307 
308  if (_tObj.count("difficulty"))
309  rlpStream << bigint(_tObj.at("difficulty").get_str());
310 
311  if (_tObj.count("number"))
312  rlpStream << bigint(_tObj.at("number").get_str());
313 
314  if (_tObj.count("gasLimit"))
315  rlpStream << bigint(_tObj.at("gasLimit").get_str());
316 
317  if (_tObj.count("gasUsed"))
318  rlpStream << bigint(_tObj.at("gasUsed").get_str());
319 
320  if (_tObj.count("timestamp"))
321  rlpStream << bigint(_tObj.at("timestamp").get_str());
322 
323  if (_tObj.count("extraData"))
324  rlpStream << fromHex(_tObj.at("extraData").get_str());
325 
326  if (_tObj.count("mixHash"))
327  rlpStream << importByteArray(_tObj.at("mixHash").get_str());
328 
329  if (_tObj.count("nonce"))
330  rlpStream << importByteArray(_tObj.at("nonce").get_str());
331 
332  return rlpStream.out();
333 }
334 
336 {
337  if (((BlockHeader)m_blockHeader).difficulty() == 0)
338  BOOST_TEST_MESSAGE("Trying to mine a block with 0 difficulty! " + TestOutputHelper::testName());
339  else
340  {
341  //do not verify blockheader for validity here
342  dev::eth::mine(m_blockHeader, _bc.interface().sealEngine(), false);
343  }
344 
346 }
347 
348 void TestBlock::verify(TestBlockChain const& _bc) const
349 {
350  if (m_dirty) //TestBlock have incorrect blockheader for testing purposes
351  return;
352 
353  try
354  {
356  }
357  catch (Exception const& _e)
358  {
359  u256 daoHardfork = _bc.interface().sealEngine()->chainParams().u256Param("daoHardforkBlock");
360  if ((m_blockHeader.number() >= daoHardfork && m_blockHeader.number() <= daoHardfork + 9) || m_blockHeader.number() == 0)
361  {
362  string exWhat { _e.what() };
363  string exExpect = "InvalidTransactionsRoot";
364  BOOST_REQUIRE_MESSAGE(exWhat.find(exExpect) != string::npos, TestOutputHelper::testName() + "block import expected another exeption: " + exExpect);
365  }
366  else
367  BOOST_ERROR(TestOutputHelper::testName() + toString(m_blockHeader.number()) + " BlockHeader Verification failed: " << boost::current_exception_diagnostic_information());
368  }
369  catch (...)
370  {
371  BOOST_ERROR(TestOutputHelper::testName() + "BlockHeader Verification failed: " << boost::current_exception_diagnostic_information());
372  }
373 }
374 
375 //Form bytestream of a block with [header transactions uncles]
377 {
378  Transactions txList;
380  txList.push_back(txi);
381  RLPStream txStream;
382  txStream.appendList(txList.size());
383  for (unsigned i = 0; i < txList.size(); ++i)
384  {
385  RLPStream txrlp;
386  txList[i].streamRLP(txrlp);
387  txStream.appendRaw(txrlp.out());
388  }
389 
390  RLPStream uncleStream;
391  uncleStream.appendList(m_uncles.size());
392  for (unsigned i = 0; i < m_uncles.size(); ++i)
393  {
394  RLPStream uncleRlp;
395  m_uncles[i].blockHeader().streamRLP(uncleRlp);
396  uncleStream.appendRaw(uncleRlp.out());
397  }
398 
399  RLPStream blHeaderStream;
400  m_blockHeader.streamRLP(blHeaderStream, WithSeal);
401 
402  RLPStream ret(3);
403  ret.appendRaw(blHeaderStream.out()); //block header
404  ret.appendRaw(txStream.out()); //transactions
405  ret.appendRaw(uncleStream.out()); //uncles
406  m_bytes = ret.out();
407 }
408 
409 void TestBlock::copyStateFrom(State const& _state)
410 {
411  //WEIRD WAY TO COPY STATE AS COPY CONSTRUCTOR FOR STATE NOT IMPLEMENTED CORRECTLY (they would share the same DB)
412  m_tempDirState.reset(new TransientDirectory());
413  m_state.reset(new State(0, OverlayDB(State::openDB(m_tempDirState.get()->path(), h256{}, WithExisting::Kill)), BaseState::Empty));
415  ImportTest::importState(obj, *m_state.get());
416 }
417 
419 {
420  m_state.reset(0);
421  m_tempDirState.reset(0);
422  for (size_t i = 0; i < m_uncles.size(); i++)
423  m_uncles.at(i).clearState();
424 }
425 
426 void TestBlock::populateFrom(TestBlock const& _original)
427 {
428  try
429  {
430  copyStateFrom(_original.state()); //copy state if it is defined in _original
431  }
432  catch (BlockStateUndefined const& _ex)
433  {
434  if (g_logVerbosity > 6)
435  cnote << _ex.what() << "copying block with null state";
436  }
437  m_testTransactions = _original.testTransactions();
439  TransactionQueue const& trQueue = _original.transactionQueue();
440  for (auto const& txi: trQueue.topTransactions(std::numeric_limits<unsigned>::max()))
441  m_transactionQueue.import(txi.rlp());
442 
443  m_uncles = _original.uncles();
444  m_blockHeader = _original.blockHeader();
445  m_bytes = _original.bytes();
446  m_accountMap = _original.accountMap();
447  m_dirty = false;
448 }
449 
451 {
452  reset(_genesisBlock);
453 }
454 
455 void TestBlockChain::reset(TestBlock const& _genesisBlock)
456 {
457  m_tempDirBlockchain.reset(new TransientDirectory);
459 
460  m_blockChain.reset(new BlockChain(p, m_tempDirBlockchain.get()->path(), WithExisting::Kill));
461  if (!m_blockChain->isKnown(BlockHeader::headerHashFromBlock(_genesisBlock.bytes())))
462  {
463  cdebug << "Not known:" << BlockHeader::headerHashFromBlock(_genesisBlock.bytes()) << BlockHeader(p.genesisBlock()).hash();
464  cdebug << "Genesis block not known!";
465  cdebug << "This should never happen.";
466  assert(false);
467  }
468  m_lastBlock = m_genesisBlock = _genesisBlock;
469 }
470 
472 {
473  while (true)
474  {
475  try
476  {
477  _block.verify(*this); //check that block header match TestBlock contents
478  m_blockChain.get()->import(_block.bytes(), m_genesisBlock.state().db());
479  break;
480  }
481  catch (FutureTime)
482  {
483  this_thread::sleep_for(chrono::milliseconds(100));
484  break;
485  }
486  }
487 
488  //Imported and best
489  if (_block.bytes() == m_blockChain.get()->block())
490  {
491  m_lastBlock = _block;
492 
493  //overwrite state in case _block had no State defined (e.x. created from RLP)
494  OverlayDB const& genesisDB = m_genesisBlock.state().db();
495  Block block = (m_blockChain.get()->genesisBlock(genesisDB));
496  block.sync(*m_blockChain.get());
497 
498  //BOOST_REQUIRE(m_lastBlock.blockHeader().hash() == BlockHeader(block.blockData()).hash());
499  m_lastBlock.setState(block.fromPending(10000));
500  return true;
501  }
502 
503  return false;
504 }
505 
506 vector<TestBlock> TestBlockChain::syncUncles(vector<TestBlock> const& uncles)
507 {
508  vector<TestBlock> validUncles;
509  if (uncles.size() == 0)
510  return validUncles;
511 
512  BlockQueue uncleBlockQueue;
513  BlockChain& blockchain = *m_blockChain.get();
514  uncleBlockQueue.setChain(blockchain);
515 
516  for (size_t i = 0; i < uncles.size(); i++)
517  {
518  try
519  {
520  uncleBlockQueue.import(&uncles.at(i).bytes(), false);
521  this_thread::sleep_for(chrono::seconds(1)); // wait until block is verified
522  validUncles.push_back(uncles.at(i));
523  }
524  catch(...)
525  {
526  cnote << "error in importing uncle! This produces an invalid block (May be by purpose for testing).";
527  }
528  }
529 
530  blockchain.sync(uncleBlockQueue, m_genesisBlock.state().db(), (unsigned)4);
531  return validUncles;
532 }
533 
534 TestTransaction TestTransaction::defaultTransaction(u256 const& _nonce, u256 const& _gasPrice, u256 const& _gasLimit, bytes const& _data)
535 {
536  json_spirit::mObject txObj;
537  txObj["data"] = toHex(_data);
538  txObj["gasLimit"] = toString(_gasLimit);
539  txObj["gasPrice"] = toString(_gasPrice);
540  txObj["nonce"] = toString(_nonce);
541  txObj["secretKey"] = "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8";
542  txObj["to"] = "095e7baea6a6c7c4c2dfeb977efac326af552d87";
543  txObj["value"] = "100";
544 
545  return TestTransaction(txObj);
546 }
547 
549 {
550  AccountMap ret;
551  ret[Address("a94f5374fce5edbc8e2a8697c15331677e6ebf0b")] = Account(0, 10000000000);
552  return ret;
553 }
554 
556 {
557  json_spirit::mObject blockObj;
558  blockObj["bloom"] = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
559  blockObj["coinbase"] = "0x8888f1f195afa192cfee860698584c030f4c9db1";
560  blockObj["difficulty"] = "131072";
561  blockObj["extraData"] = "0x42";
562  blockObj["gasLimit"] = "3141592";
563  blockObj["gasUsed"] = "0";
564  blockObj["mixHash"] = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421";
565  blockObj["nonce"] = "0x0102030405060708";
566  blockObj["number"] = "0";
567  blockObj["parentHash"] = "0x0000000000000000000000000000000000000000000000000000000000000000";
568  blockObj["receiptTrie"] = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421";
569  blockObj["stateRoot"] = "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a";
570  blockObj["timestamp"] = "0x54c98c81";
571  blockObj["transactionsTrie"] = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421";
572  blockObj["uncleHash"] = "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347";
573  return blockObj;
574 }
575 
577 {
578  json_spirit::mObject blockObj = defaultGenesisBlockJson();
579  blockObj["gasLimit"] = toString(_gasLimit);
580 
581  json_spirit::mObject accountObj;
582  accountObj["balance"] = "10000000000";
583  accountObj["nonce"] = "1"; //=1for nonce too low exception check
584  accountObj["code"] = "";
585  accountObj["storage"] = json_spirit::mObject();
586 
587  json_spirit::mObject accountMapObj;
588  accountMapObj["a94f5374fce5edbc8e2a8697c15331677e6ebf0b"] = accountObj;
589 
590  return TestBlock(blockObj, accountMapObj);
591 }
592 
593 }}
bytes const & blockData() const
Get the complete current block, including valid nonce.
Definition: Block.h:276
vector< TestTransaction > m_testTransactions
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
State const & state() const
Get the backing state object.
Definition: Block.h:163
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
Definition: CommonData.h:54
LogBloom const & logBloom() const
Definition: BlockHeader.h:165
std::pair< TransactionReceipts, bool > sync(BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
Sync our transactions, killing those from the queue that we have and assimilating those that we don&#39;t...
Definition: Block.cpp:301
std::map< std::string, bool > m_premineUpdate
u256 const & number() const
Definition: BlockHeader.h:162
A queue of Transactions, each stored as RLP.
static AccountMap defaultAccountMap()
ChainOperationParams const & chainParams() const
Definition: SealEngine.h:75
std::unordered_map< Address, Account > AccountMap
Definition: Account.h:239
State fromPending(unsigned _i) const
Get the State immediately after the given number of pending transactions have been applied...
Definition: Block.cpp:832
bytes genesisBlock() const
Genesis block info.
void streamRLP(RLPStream &_s, IncludeSeal _i=WithSeal) const
Definition: BlockHeader.cpp:83
Implements the blockchain database.
Definition: BlockChain.h:105
h256 const & stateRoot() const
Definition: BlockHeader.h:158
static TestTransaction defaultTransaction(u256 const &_nonce=1, u256 const &_gasPrice=1, u256 const &_gasLimit=50000, bytes const &_data=bytes())
Encapsulation of a block header.
Definition: BlockHeader.h:95
BlockChain const & interface() const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
Definition: Common.h:121
Models the state of a single Ethereum account.
Definition: Account.h:67
bytes const & out() const
Read the byte stream.
Definition: RLP.h:433
h256 const & transactionsRoot() const
Definition: BlockHeader.h:159
void setGasUsed(u256 const &_v)
Definition: BlockHeader.h:145
static std::string const & testName()
const char * what() const noexceptoverride
Definition: Exceptions.h:42
ImportResult import(bytesConstRef _block, bool _isOurs=false)
Import a block into the queue.
Definition: BlockQueue.cpp:175
h160 Address
An Ethereum address: 20 bytes.
Definition: Common.h:62
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
Definition: Transaction.h:121
static TestBlock defaultGenesisBlock(u256 const &_gasLimit=DefaultBlockGasLimit)
Block genesisBlock(OverlayDB const &_db) const
Get a pre-made genesis State object.
std::hash for asio::adress
Definition: Common.h:323
assert(len-trim+(2 *lenIndices)<=WIDTH)
h256 const & sha3Uncles() const
Definition: BlockHeader.h:155
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
BlockHeader const & blockHeader() const
static eth::Network s_sealEngineNetwork
Model of an Ethereum state, essentially a facade for the trie.
Definition: State.h:161
OverlayDB const & db() const
Definition: State.h:195
void setParentHash(h256 const &_v)
Definition: BlockHeader.h:140
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
Definition: Block.h:194
void setState(State const &_state)
h256 const & parentHash() const
Definition: BlockHeader.h:154
void updateNonce(TestBlockChain const &_bc)
bytes rlp(IncludeSignature _sig=WithSignature) const
Definition: Transaction.h:107
TransactionQueue m_transactionQueue
Transactions topTransactions(unsigned _limit, h256Hash const &_avoid=h256Hash()) const
Get top transactions from the queue.
void setSha3Uncles(h256 const &_v)
Definition: BlockHeader.h:141
void setTimestamp(u256 const &_v)
Definition: BlockHeader.h:142
#define cdebug
Definition: Log.h:302
Active model of a block within the block chain.
Definition: Block.h:73
TestBlock const & testGenesis() const
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
static void importState(json_spirit::mObject const &_o, eth::State &_state)
Base class for all exceptions.
Definition: Exceptions.h:39
vector< TestTransaction > const & testTransactions() const
ExecStats::duration max
Definition: ExecStats.cpp:36
void setNumber(u256 const &_v)
Definition: BlockHeader.h:146
dev::bytes createBlockRLPFromFields(mObject const &_tObj, h256 const &_stateRoot=h256{})
bytes const & extraData() const
Definition: BlockHeader.h:164
std::vector< byte > bytes
Definition: Common.h:75
void clear()
Clear the queue.
BlockHeader constructBlock(mObject const &_o, h256 const &_stateRoot)
Test Block Private.
RLPStream & appendList(size_t _items)
Appends a list.
Definition: RLP.cpp:276
void setLogBloom(LogBloom const &_v)
Definition: BlockHeader.h:149
void populateFrom(TestBlock const &_original)
A queue of blocks.
Definition: BlockQueue.h:225
json_spirit::mObject fillJsonWithState(State const &_state)
Definition: TestHelper.cpp:139
void setGasLimit(u256 const &_v)
Definition: BlockHeader.h:147
ldb::DB * db() const
Definition: OverlayDB.h:39
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
ImportResult import(bytes const &_tx, IfDropped _ik=IfDropped::Ignore)
Verify and add transaction to the queue synchronously.
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:84
u256 const & timestamp() const
Definition: BlockHeader.h:156
mConfig::Object_type mObject
bool addBlock(TestBlock const &_block)
void premineUpdate(BlockHeader &info)
int g_logVerbosity
The logging system&#39;s current verbosity.
Definition: Log.cpp:37
void mine(TestBlockChain const &_bc)
void replaceLLLinState(json_spirit::mObject &_o)
Definition: TestHelper.cpp:237
void setAuthor(Address const &_id)
Set the author address for any transactions we do and rewards we get.
Definition: Block.h:118
h256 const & receiptsRoot() const
Definition: BlockHeader.h:160
TransactionQueue const & transactionQueue() const
u256 u256Param(std::string const &_name) const
Convenience method to get an otherParam as a u256 int.
State const & state() const
Address const & author() const
Definition: BlockHeader.h:157
std::string const & genesisInfo(Network _n)
Definition: GenesisInfo.cpp:37
vector< TestBlock > const & uncles() const
Value_type::String_type write_string(const Value_type &value, bool pretty)
std::unique_ptr< State > m_state
dev::bytes const & bytes() const
static json_spirit::mObject defaultGenesisBlockJson()
#define cnote
Definition: Log.h:303
void setExtraData(bytes const &_v)
Definition: BlockHeader.h:148
void setUncles(vector< TestBlock > const &_uncles)
AccountMap jsonToAccountMap(std::string const &_json, u256 const &_defaultNonce=0, AccountMaskMap *o_mask=nullptr, PrecompiledContractMap *o_precompiled=nullptr)
Definition: Account.cpp:50
void setChain(BlockChain const &_bc)
Definition: BlockQueue.h:231
u256 const & gasLimit() const
Definition: BlockHeader.h:163
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
Definition: SHA3.cpp:214
void copyStateFrom(State const &_state)
void addTransaction(TestTransaction const &_tr)
std::unique_ptr< TransientDirectory > m_tempDirState
Transaction const & transaction() const
TestBlock & operator=(TestBlock const &_original)
void verify(TestBlockChain const &_bc) const
void setRoots(h256 const &_t, h256 const &_r, h256 const &_u, h256 const &_s)
Definition: BlockHeader.h:144
void reset(TestBlock const &_genesisBlock)
bytes importByteArray(std::string const &_str)
Definition: TestHelper.cpp:221
std::tuple< ImportRoute, bool, unsigned > sync(BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max)
Sync the chain with any incoming blocks.
Definition: BlockChain.cpp:408
Address const & beneficiary() const
vector< TestBlock > syncUncles(vector< TestBlock > const &_uncles)
u256 const & gasUsed() const
Definition: BlockHeader.h:161
void addUncle(TestBlock const &_uncle)
static void importTransaction(json_spirit::mObject const &_o, eth::Transaction &o_tr)
Class for writing to an RLP bytestream.
Definition: RLP.h:383
temporary directory implementation It creates temporary directory in the given path.
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
Definition: RLP.cpp:230
void mine(Client &c, int numBlocks)
Definition: TestHelper.cpp:39
u256 const & difficulty() const
Definition: BlockHeader.h:166
Class for interpreting Recursive Linear-Prefix Data.
Definition: RLP.h:64
void setBlockHeader(BlockHeader const &_header)
void setDifficulty(u256 const &_v)
Definition: BlockHeader.h:150
virtual void verify(Strictness _s, BlockHeader const &_bi, BlockHeader const &_parent=BlockHeader(), bytesConstRef _block=bytesConstRef()) const
Don&#39;t forget to call Super::verify when subclassing & overriding.
Definition: SealEngine.cpp:36
SealEngineFace * sealEngine() const
Definition: BlockChain.h:309
BlockHeader const & info() const
Get the header information on the present block.
Definition: Block.h:279
Helper functions to work with json::spirit and test files.
AccountMap const & accountMap() const
vector< TestBlock > m_uncles
void setAuthor(Address const &_v)
Definition: BlockHeader.h:143