Fabcoin Core  0.16.2
P2P Digital Currency
BlockChain.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>
29 
30 
31 using namespace std;
32 using namespace dev;
33 using namespace dev::eth;
34 using namespace dev::test;
35 
37 
39 {
40  try
41  {
42  BOOST_WARN(string(BlockChainDebug::name()) == string(EthBlue "☍" EthWhite " ◇"));
43  BOOST_WARN(string(BlockChainWarn::name()) == string(EthBlue "☍" EthOnRed EthBlackBold " ✘"));
44  BOOST_WARN(string(BlockChainNote::name()) == string(EthBlue "☍" EthBlue " ℹ"));
45  BOOST_WARN(string(BlockChainChat::name()) == string(EthBlue "☍" EthWhite " ◌"));
46 
47  TestBlock genesis = TestBlockChain::defaultGenesisBlock();
48  TestBlockChain bc(genesis);
49 
50  TestBlock block;
51  block.mine(bc);
52  bc.addBlock(block);
53 
54  std::stringstream buffer;
55  buffer << bc.interface();
56  BOOST_REQUIRE(buffer.str().size() == 139);
57  buffer.str(std::string());
58  }
59  catch (Exception const& _e)
60  {
61  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
62  }
63  catch (std::exception const& _e)
64  {
65  BOOST_ERROR("Failed test with Exception: " << _e.what());
66  }
67  catch(...)
68  {
69  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
70  }
71 }
72 
74 {
75  TestBlock genesis = TestBlockChain::defaultGenesisBlock();
76  TransientDirectory tempDirBlockchain;
77  ChainParams p(genesisInfo(Network::TransitionnetTest), genesis.bytes(), genesis.accountMap());
78  BlockChain bc(p, tempDirBlockchain.path(), WithExisting::Kill);
79  auto is_critical = []( std::exception const& _e) { return string(_e.what()).find("DatabaseAlreadyOpen") != string::npos; };
80  BOOST_CHECK_EXCEPTION(BlockChain bc2(p, tempDirBlockchain.path(), WithExisting::Verify), DatabaseAlreadyOpen, is_critical);
81 }
82 
83 //BOOST_AUTO_TEST_CASE(rebuild)
84 //{
85 // string dbPath;
86 // TestBlock genesisCopy;
87 // {
88 // TestBlock genesis = TestBlockChain::getDefaultGenesisBlock();
89 // genesisCopy = genesis;
90 // TransientDirectory tempDirBlockchain;
91 // dbPath = tempDirBlockchain.path();
92 // FullBlockChain<Ethash> bc(genesis.getBytes(), AccountMap(), tempDirBlockchain.path(), WithExisting::Kill);
93 
94 // TestTransaction testTr = TestTransaction::getDefaultTransaction();
95 // TransactionQueue trQueue;
96 // trQueue.import(testTr.getTransaction().rlp());
97 
98 // ZeroGasPricer gp;
99 // Block block = bc.genesisBlock(genesis.getState().db());
100 // block.sync(bc);
101 // block.sync(bc, trQueue, gp);
102 // dev::eth::mine(block, bc);
103 // bc.import(block.blockData(), block.state().db());
104 // BOOST_REQUIRE(bc.number() == 1);
105 
106 // bc.rebuild(tempDirBlockchain.path());
107 // BOOST_REQUIRE(bc.number() == 1);
108 // }
109 
110 // FullBlockChain<Ethash> bc(genesisCopy.getBytes(), AccountMap(), dbPath, WithExisting::Verify);
111 // BOOST_REQUIRE(bc.number() == 0);
112 // bc.rebuild(dbPath);
113 // BOOST_REQUIRE(bc.number() == 1);
114 //}
115 
116 BOOST_AUTO_TEST_CASE(Mining_1_mineBlockWithTransaction)
117 {
118  try
119  {
120  dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest;
121  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
122  TestTransaction tr = TestTransaction::defaultTransaction(1); //nonce = 1
123  TestBlock block;
124  block.addTransaction(tr);
125  block.mine(bc);
126  bc.addBlock(block);
127  BOOST_REQUIRE(bc.interface().transactions().size() > 0);
128  }
129  catch (Exception const& _e)
130  {
131  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
132  }
133  catch (std::exception const& _e)
134  {
135  BOOST_ERROR("Failed test with Exception: " << _e.what());
136  }
137  catch(...)
138  {
139  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
140  }
141 }
142 
143 BOOST_AUTO_TEST_CASE(Mining_2_mineUncles)
144 {
145  try
146  {
147  dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest;
148  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
149  TestTransaction tr = TestTransaction::defaultTransaction(1); //nonce = 1
150  TestBlock block;
151  block.addTransaction(tr);
152  block.mine(bc);
153  bc.addBlock(block);
154 
155  TestBlock uncleBlock;
156  uncleBlock.mine(bc);
157  TestBlock uncleBlock2;
158  uncleBlock2.mine(bc);
159 
160  TestTransaction tr2 = TestTransaction::defaultTransaction(2);
161  TestBlock block2;
162  block2.addTransaction(tr2);
163  block2.mine(bc);
164  bc.addBlock(block2);
165  }
166  catch (Exception const& _e)
167  {
168  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
169  }
170  catch (std::exception const& _e)
171  {
172  BOOST_ERROR("Failed test with Exception: " << _e.what());
173  }
174  catch(...)
175  {
176  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
177  }
178 }
179 
180 
181 /*
182 
183 Often broken test disabled 5th September 2016, until we have time to
184 troubleshoot the root cause.
185 
186 See https://github.com/ethereum/cpp-ethereum/issues/3256.
187 
188 BOOST_AUTO_TEST_CASE(Mining_3_mineBlockWithUncles)
189 {
190  try
191  {
192  dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest;
193  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
194  TestTransaction tr = TestTransaction::defaultTransaction(1); //nonce = 1
195  TestBlock block;
196  block.addTransaction(tr);
197  block.mine(bc);
198  bc.addBlock(block);
199 
200  TestBlock uncleBlock;
201  uncleBlock.mine(bc);
202  TestBlock uncleBlock2;
203  uncleBlock2.mine(bc);
204 
205  TestTransaction tr2 = TestTransaction::defaultTransaction(2);
206  TestBlock block2;
207  block2.addTransaction(tr2);
208  block2.mine(bc);
209  bc.addBlock(block2);
210 
211  TestTransaction tr3 = TestTransaction::defaultTransaction(3);
212  TestBlock block3;
213  block3.addUncle(uncleBlock);
214  bc.syncUncles(block3.uncles());
215  block3.addTransaction(tr3);
216  block3.mine(bc);
217  bc.addBlock(block3);
218  BOOST_REQUIRE(bc.interface().info().number() == 3);
219  BOOST_REQUIRE(bc.interface().info(uncleBlock.blockHeader().hash()) == uncleBlock.blockHeader());
220  }
221  catch (Exception const& _e)
222  {
223  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
224  }
225  catch (std::exception const& _e)
226  {
227  BOOST_ERROR("Failed test with Exception: " << _e.what());
228  }
229  catch(...)
230  {
231  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
232  }
233 }
234 */
235 
236 
237 /*
238 
239 Often broken test disabled 5th September 2016, until we have time to
240 troubleshoot the root cause.
241 
242 See https://github.com/ethereum/cpp-ethereum/issues/3059.
243 
244 BOOST_AUTO_TEST_CASE(Mining_4_BlockQueueSyncing)
245 {
246  try
247  {
248  dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest;
249  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
250  TestBlockChain bc2(TestBlockChain::defaultGenesisBlock());
251 
252  TestBlock block;
253  block.mine(bc2);
254  bc2.addBlock(block);
255  TestBlock block2;
256  block2.mine(bc2);
257 
258  BlockQueue uncleBlockQueue;
259  uncleBlockQueue.setChain(bc2.interface());
260  ImportResult importIntoQueue = uncleBlockQueue.import(&block2.bytes(), false);
261  BOOST_REQUIRE(importIntoQueue == ImportResult::Success);
262  this_thread::sleep_for(chrono::seconds(2));
263 
264  BlockChain& bcRef = bc.interfaceUnsafe();
265  bcRef.sync(uncleBlockQueue, bc.testGenesis().state().db(), unsigned(4));
266 
267  //Attempt import block5 to another blockchain
268  pair<ImportResult, ImportRoute> importAttempt;
269  importAttempt = bcRef.attemptImport(block2.bytes(), bc.testGenesis().state().db());
270  BOOST_REQUIRE(importAttempt.first == ImportResult::UnknownParent);
271 
272  //Insert block5 to another blockchain
273  auto is_critical = []( std::exception const& _e) { cnote << _e.what(); return true; };
274  BOOST_CHECK_EXCEPTION(bcRef.insert(block2.bytes(), block2.receipts()), UnknownParent, is_critical);
275 
276  //Get status of block5 in the block queue based on block5's chain (block5 imported into queue but not imported into chain)
277  //BlockQueue(bc2) changed by sync function of original bc
278  QueueStatus status = uncleBlockQueue.blockStatus(block2.blockHeader().hash());
279  BOOST_REQUIRE_MESSAGE(status == QueueStatus::Bad, "Received Queue Status: " + toString(status) + " Expected Queue Status: " + toString(QueueStatus::Bad));
280  }
281  catch (Exception const& _e)
282  {
283  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
284  }
285  catch (std::exception const& _e)
286  {
287  BOOST_ERROR("Failed test with Exception: " << _e.what());
288  }
289  catch(...)
290  {
291  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
292  }
293 }
294 */
295 
296 
297 BOOST_AUTO_TEST_CASE(Mining_5_BlockFutureTime)
298 {
299  try
300  {
301  dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest;
302  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
303 
304  TestBlock uncleBlock;
305  uncleBlock.mine(bc);
306 
307  BlockHeader uncleHeader = uncleBlock.blockHeader();
308  uncleHeader.setTimestamp(uncleHeader.timestamp() + 10000);
309  uncleBlock.setBlockHeader(uncleHeader);
310  uncleBlock.updateNonce(bc);
311 
312  BlockQueue uncleBlockQueue;
313  uncleBlockQueue.setChain(bc.interface());
314  uncleBlockQueue.import(&uncleBlock.bytes(), false);
315  this_thread::sleep_for(chrono::seconds(2));
316 
317  BlockChain& bcRef = bc.interfaceUnsafe();
318  bcRef.sync(uncleBlockQueue, bc.testGenesis().state().db(), unsigned(4));
319  BOOST_REQUIRE(uncleBlockQueue.blockStatus(uncleBlock.blockHeader().hash()) == QueueStatus::Unknown);
320 
321  pair<ImportResult, ImportRoute> importAttempt;
322  importAttempt = bcRef.attemptImport(uncleBlock.bytes(), bc.testGenesis().state().db());
323  BOOST_REQUIRE(importAttempt.first == ImportResult::FutureTimeKnown);
324 
325  auto is_critical = []( std::exception const& _e) { cnote << _e.what(); return true; };
326  BOOST_CHECK_EXCEPTION(bcRef.insert(uncleBlock.bytes(), uncleBlock.receipts()), FutureTime, is_critical);
327  }
328  catch (Exception const& _e)
329  {
330  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
331  }
332  catch (std::exception const& _e)
333  {
334  BOOST_ERROR("Failed test with Exception: " << _e.what());
335  }
336  catch(...)
337  {
338  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
339  }
340 }
341 
342 bool onBadwasCalled = false;
343 void onBad(Exception& _ex)
344 {
345  cout << _ex.what();
346  onBadwasCalled = true;
347 }
348 
349 BOOST_AUTO_TEST_CASE(attemptImport)
350 {
351  //UnknownParent
352  //Success
353  //AlreadyKnown
354  //FutureTimeKnown
355  //Malformed
356 
357  try
358  {
359  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
360 
361  TestTransaction tr = TestTransaction::defaultTransaction();
362  TestBlock block;
363  block.addTransaction(tr);
364  block.mine(bc);
365 
366  pair<ImportResult, ImportRoute> importAttempt;
367  BlockChain& bcRef = bc.interfaceUnsafe();
368  bcRef.setOnBad(onBad);
369 
370  importAttempt = bcRef.attemptImport(block.bytes(), bc.testGenesis().state().db());
371  BOOST_REQUIRE(importAttempt.first == ImportResult::Success);
372 
373  importAttempt = bcRef.attemptImport(block.bytes(), bc.testGenesis().state().db());
374  BOOST_REQUIRE(importAttempt.first == ImportResult::AlreadyKnown);
375 
376  bytes blockBytes = block.bytes();
377  blockBytes[0] = 0;
378  importAttempt = bcRef.attemptImport(blockBytes, bc.testGenesis().state().db());
379  BOOST_REQUIRE(importAttempt.first == ImportResult::Malformed);
380  BOOST_REQUIRE(onBadwasCalled == true);
381  cout << endl;
382  }
383  catch (Exception const& _e)
384  {
385  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
386  }
387  catch (std::exception const& _e)
388  {
389  BOOST_ERROR("Failed test with Exception: " << _e.what());
390  }
391  catch(...)
392  {
393  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
394  }
395 }
396 
398 {
399  try
400  {
401  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
402  TestTransaction tr = TestTransaction::defaultTransaction();
403  TestBlock block;
404  block.addTransaction(tr);
405  block.mine(bc);
406 
407  BlockChain& bcRef = bc.interfaceUnsafe();
408 
409  //Incorrect Receipt
410  ZeroGasPricer gp;
411  Block bl = bcRef.genesisBlock(bc.testGenesis().state().db());
412  bl.sync(bcRef);
413  bl.sync(bcRef, block.transactionQueue(), gp);
414 
415  //Receipt should be RLPStream
416  const bytes receipt = bl.receipt(0).rlp();
417  bytesConstRef receiptRef(&receipt[0], receipt.size());
418 
419  auto is_critical = []( std::exception const& _e) { return string(_e.what()).find("InvalidBlockFormat") != string::npos; };
420  BOOST_CHECK_EXCEPTION(bcRef.insert(bl.blockData(), receiptRef), InvalidBlockFormat, is_critical);
421  auto is_critical2 = []( std::exception const& _e) { return string(_e.what()).find("InvalidReceiptsStateRoot") != string::npos; };
422  BOOST_CHECK_EXCEPTION(bcRef.insert(block.bytes(), receiptRef), InvalidReceiptsStateRoot, is_critical2);
423 
424  BOOST_REQUIRE(bcRef.number() == 0);
425 
426  try
427  {
428  bcRef.insert(block.bytes(), block.receipts());
429  }
430  catch(...)
431  {
432  BOOST_ERROR("Unexpected Exception!");
433  }
434  }
435  catch (Exception const& _e)
436  {
437  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
438  }
439  catch (std::exception const& _e)
440  {
441  BOOST_ERROR("Failed test with Exception: " << _e.what());
442  }
443  catch(...)
444  {
445  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
446  }
447 }
448 
449 BOOST_AUTO_TEST_CASE(insertException)
450 {
451  try
452  {
453  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
454  BlockChain& bcRef = bc.interfaceUnsafe();
455 
456  TestTransaction tr = TestTransaction::defaultTransaction();
457  TestBlock block;
458  block.addTransaction(tr);
459  block.mine(bc);
460  bc.addBlock(block);
461 
462  auto is_critical = []( std::exception const& _e) { cnote << _e.what(); return true; };
463  BOOST_CHECK_EXCEPTION(bcRef.insert(block.bytes(), block.receipts()), AlreadyHaveBlock, is_critical);
464  }
465  catch (Exception const& _e)
466  {
467  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
468  }
469  catch (std::exception const& _e)
470  {
471  BOOST_ERROR("Failed test with Exception: " << _e.what());
472  }
473  catch(...)
474  {
475  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
476  }
477 }
478 
480 {
481  try
482  {
483  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
484 
485  {
486  TestTransaction tr = TestTransaction::defaultTransaction();
487  TestBlock block;
488  block.addTransaction(tr);
489  block.mine(bc);
490  bc.addBlock(block);
491  }
492 
493  {
494  TestTransaction tr = TestTransaction::defaultTransaction(1);
495  TestBlock block;
496  block.addTransaction(tr);
497  block.mine(bc);
498  bc.addBlock(block);
499  }
500 
501  {
502  TestTransaction tr = TestTransaction::defaultTransaction(2);
503  TestBlock block;
504  block.addTransaction(tr);
505  block.mine(bc);
506  bc.addBlock(block);
507  }
508 
509  // Temporary disable this assertion, which is failing in TravisCI for OS X Mavericks
510  // See https://travis-ci.org/ethereum/cpp-ethereum/jobs/156083698.
511  #if !defined(DISABLE_BROKEN_UNIT_TESTS_UNTIL_WE_FIX_THEM)
512  try
513  {
514  BlockChain& bcRef = bc.interfaceUnsafe();
515  std::this_thread::sleep_for(std::chrono::seconds(10)); //try wait for block verification before rescue
516  bcRef.rescue(bc.testGenesis().state().db());
517  BOOST_CHECK_MESSAGE(bcRef.number() == 3, "Rescued Blockchain missing some blocks!");
518  }
519  catch(...)
520  {
521  BOOST_ERROR("Unexpected Exception!");
522  }
523  #endif // !defined(DISABLE_BROKEN_UNIT_TESTS_UNTIL_WE_FIX_THEM)
524 
525  }
526  catch (Exception const& _e)
527  {
528  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
529  }
530  catch (std::exception const& _e)
531  {
532  BOOST_ERROR("Failed test with Exception: " << _e.what());
533  }
534  catch(...)
535  {
536  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
537  }
538 }
539 
541 {
542  try
543  {
544  TestBlockChain bc(TestBlockChain::defaultGenesisBlock());
545  BlockChain& bcRef = bc.interfaceUnsafe();
546 
547  BlockChain::Statistics stat = bcRef.usage();
548  //Absolutely random values here!
549  //BOOST_REQUIRE(stat.memBlockHashes == 0);
550  //BOOST_REQUIRE(stat.memBlocks == 1); //incorrect value here
551  //BOOST_REQUIRE(stat.memDetails == 0);
552  //BOOST_REQUIRE(stat.memLogBlooms == 0);
553  //BOOST_REQUIRE(stat.memReceipts == 0);
554  //BOOST_REQUIRE(stat.memTotal() == 0);
555  //BOOST_REQUIRE(stat.memTransactionAddresses == 0); //incorrect value here
556 
557  TestTransaction tr = TestTransaction::defaultTransaction();
558  TestBlock block;
559  block.addTransaction(tr);
560  block.mine(bc);
561  bc.addBlock(block);
562 
563  stat = bcRef.usage(true);
564  BOOST_REQUIRE(stat.memBlockHashes == 0);
565  BOOST_REQUIRE(stat.memBlocks == 675);
566  BOOST_REQUIRE(stat.memDetails == 138);
567  BOOST_REQUIRE(stat.memLogBlooms == 8422);
568  BOOST_REQUIRE(stat.memReceipts == 0);
569  BOOST_REQUIRE(stat.memTotal() == 9235);
570  BOOST_REQUIRE(stat.memTransactionAddresses == 0);
571 
572  //memchache size 33554432 - 3500 blocks before cache to be cleared
573  bcRef.garbageCollect(true);
574  }
575  catch (Exception const& _e)
576  {
577  BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
578  }
579  catch (std::exception const& _e)
580  {
581  BOOST_ERROR("Failed test with Exception: " << _e.what());
582  }
583  catch(...)
584  {
585  BOOST_ERROR("Exception thrown when trying to mine or import a block!");
586  }
587 }
588 
bytes const & blockData() const
Get the complete current block, including valid nonce.
Definition: Block.h:276
Statistics usage(bool _freshen=false) const
Definition: BlockChain.h:287
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
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
Implements the blockchain database.
Definition: BlockChain.h:105
h256 hash(IncludeSeal _i=WithSeal) const
Definition: BlockHeader.cpp:64
Encapsulation of a block header.
Definition: BlockHeader.h:95
BlockChain const & interface() const
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
Block genesisBlock(OverlayDB const &_db) const
Get a pre-made genesis State object.
std::hash for asio::adress
Definition: Common.h:323
#define EthBlackBold
Definition: Terminal.h:133
BlockHeader const & blockHeader() const
QueueStatus blockStatus(h256 const &_h) const
Get some infomration on the given block&#39;s status regarding us.
Definition: BlockQueue.cpp:386
static eth::Network s_sealEngineNetwork
OverlayDB const & db() const
Definition: State.h:195
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
Definition: Block.h:194
void updateNonce(TestBlockChain const &_bc)
std::vector< bytes > transactions(h256 const &_blockHash) const
Get all transactions from a block.
Definition: BlockChain.h:221
void setTimestamp(u256 const &_v)
Definition: BlockHeader.h:142
Active model of a block within the block chain.
Definition: Block.h:73
TestBlock const & testGenesis() const
Base class for all exceptions.
Definition: Exceptions.h:39
unsigned number(h256 const &_hash) const
Get a number for the given hash (or the most recent mined if none given). Thread-safe.
Definition: BlockChain.h:225
BOOST_AUTO_TEST_CASE(output)
Definition: BlockChain.cpp:38
const char * name
Definition: rest.cpp:36
#define EthWhite
Definition: Terminal.h:119
std::vector< byte > bytes
Definition: Common.h:75
bytesConstRef receipts() const
A queue of blocks.
Definition: BlockQueue.h:225
void garbageCollect(bool _force=false)
Deallocate unused data.
u256 const & timestamp() const
Definition: BlockHeader.h:156
bool addBlock(TestBlock const &_block)
void mine(TestBlockChain const &_bc)
TransactionQueue const & transactionQueue() const
State const & state() const
std::string const & genesisInfo(Network _n)
Definition: GenesisInfo.cpp:37
BlockChain & interfaceUnsafe() const
dev::bytes const & bytes() const
#define cnote
Definition: Log.h:303
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
std::string const & path() const
void setChain(BlockChain const &_bc)
Definition: BlockQueue.h:231
void setOnBad(std::function< void(Exception &)> _t)
Change the function that is called with a bad block.
Definition: BlockChain.h:293
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
void addTransaction(TestTransaction const &_tr)
bool onBadwasCalled
Definition: BlockChain.cpp:342
void insert(bytes const &_block, bytesConstRef _receipts, bool _mustBeNew=true)
Import data into disk-backed DB.
Definition: BlockChain.cpp:522
#define EthBlue
Definition: Terminal.h:127
#define EthOnRed
Definition: Terminal.h:172
std::tuple< ImportRoute, bool, unsigned > sync(BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max)
Sync the chain with any incoming blocks.
Definition: BlockChain.cpp:408
void onBad(Exception &_ex)
Definition: BlockChain.cpp:343
void rescue(OverlayDB const &_db)
Rescue the database.
temporary directory implementation It creates temporary directory in the given path.
void setBlockHeader(BlockHeader const &_header)
Helper functions to work with json::spirit and test files.
AccountMap const & accountMap() const
std::pair< ImportResult, ImportRoute > attemptImport(bytes const &_block, OverlayDB const &_stateDB, bool _mutBeNew=true) noexcept
Attempt to import the given block directly into the BlockChain and sync with the state DB...
Definition: BlockChain.cpp:472