From 2bc972f4c764ca03c584ac64415dd6e932c58f1e Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 11 Aug 2015 17:26:21 +0300 Subject: [PATCH 01/12] BLock2: state test filling issue --- test/libethereum/state.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/libethereum/state.cpp b/test/libethereum/state.cpp index 4c9d998b2..2aa6dd0f4 100644 --- a/test/libethereum/state.cpp +++ b/test/libethereum/state.cpp @@ -59,7 +59,6 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) const State importedStatePost = importer.m_statePost; bytes output; - // execute transaction Listener::ExecTimeGuard guard{i.first}; output = importer.executeTest(); From 4f299044411b3bbfd4b54b9dea265847caf2e4f3 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 12 Aug 2015 17:16:40 +0300 Subject: [PATCH 02/12] restore lost changes blockmining --- test/libethereum/blockchain.cpp | 269 +++++++++++++++++--------------- 1 file changed, 145 insertions(+), 124 deletions(-) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 0be4d6622..83a50a1f7 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -29,6 +29,8 @@ #include #include +#include + using namespace std; using namespace json_spirit; using namespace dev; @@ -53,6 +55,8 @@ mArray importUncles(mObject const& _blObj, vector& _vBiUncles, vect void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) { + _fillin = true; + for (auto& i: _v.get_obj()) { mObject& o = i.second.get_obj(); @@ -69,12 +73,25 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) ImportTest importer(o, _fillin, testType::BlockChainTests); TransientDirectory td_stateDB_tmp; BlockHeader biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), h256{}); - State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path(), h256{}, WithExisting::Kill)), BaseState::Empty); - importer.importState(o["pre"].get_obj(), trueState); + ImportTest::importState(o["pre"].get_obj(), trueState); o["pre"] = fillJsonWithState(trueState); //convert all fields to hex trueState.commit(); + + /// Trick + //merge into init state string our test predefined state and change difficulty for testing + //string genesisState = *(const_cast(&c_genesisInfoFrontier/*c_genesisInfoOlympic*/)); + /*size_t pos = genesisState.find("alloc"); + string sss = json_spirit::write_string(o["pre"], true); + sss.replace(0, 1, ""); + sss.replace(sss.length() - 2, 2, ","); + genesisState.insert(pos + 9, sss); + genesisState.replace(genesisState.find("0x400000000"), 7, "0x20000"); + note << genesisState; + */ + /// + //Imported blocks from the start std::vector blockSets; //Block(bytes) => UncleList(Blocks(bytes)) @@ -129,10 +146,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) TransientDirectory td_stateDB, td_bc; FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); - OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); - State state(database, BaseState::Empty); - Block block(database, BaseState::Empty, biGenesisBlock.beneficiary()); - state = importer.m_statePre; + //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); + State state = importer.m_statePre; state.commit(); //import previous blocks @@ -186,9 +201,14 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) cnote << "error in importing uncle! This produces an invalid block (May be by purpose for testing)."; } } + bc.sync(uncleBlockQueue, state.db(), 4); - block.commitToSeal(bc); + //block.commitToSeal(bc); + //Block block(State::openDB(bc.genesisHash()), BaseState::Empty, biGenesisBlock.beneficiary()); + Block block = bc.genesisBlock(State::openDB(bc.genesisHash())); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK + //Block block (State::openDB(biGenesisBlock.hash())); + //Block block(state.db(), BaseState::Empty); //mine a new block on top of previously imported try { @@ -208,125 +228,126 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) } -// blObj["rlp"] = toHex(state.blockData(), 2, HexPrefix::Add); - -// //get valid transactions -// Transactions txList; -// for (auto const& txi: txs.topTransactions(std::numeric_limits::max())) -// txList.push_back(txi); -// blObj["transactions"] = writeTransactionsToJson(txList); - -// BlockHeader current_BlockHeader = state.info(); - -// RLPStream uncleStream; -// uncleStream.appendList(vBiUncles.size()); -// for (unsigned i = 0; i < vBiUncles.size(); ++i) -// { -// RLPStream uncleRlp; -// vBiUncles[i].streamRLP(uncleRlp); -// uncleStream.appendRaw(uncleRlp.out()); -// } - -// if (blObj.count("blockHeader")) -// overwriteBlockHeader(current_BlockHeader, blObj); - -// if (blObj.count("blockHeader") && blObj["blockHeader"].get_obj().count("bruncle")) -// current_BlockHeader.populateFromParent(vBiBlocks[vBiBlocks.size() -1]); - -// if (vBiUncles.size()) -// { -// // update unclehash in case of invalid uncles -// current_BlockHeader.setSha3Uncles(sha3(uncleStream.out())); -// updatePoW(current_BlockHeader); -// } - -// // write block header -// mObject oBlockHeader; -// writeBlockHeaderToJson(oBlockHeader, current_BlockHeader); -// blObj["blockHeader"] = oBlockHeader; -// vBiBlocks.push_back(current_BlockHeader); - -// // compare blocks from state and from rlp -// RLPStream txStream; -// txStream.appendList(txList.size()); -// for (unsigned i = 0; i < txList.size(); ++i) -// { -// RLPStream txrlp; -// txList[i].streamRLP(txrlp); -// txStream.appendRaw(txrlp.out()); -// } - -// RLPStream block2 = createFullBlockFromHeader(current_BlockHeader, txStream.out(), uncleStream.out()); - -// blObj["rlp"] = toHex(block2.out(), 2, HexPrefix::Add); - -// if (sha3(RLP(state.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) -// { -// cnote << "block header mismatch state.blockData() vs updated state.info()\n"; -// cerr << toHex(state.blockData()) << "vs" << toHex(block2.out()); -// } - -// if (sha3(RLP(state.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) -// cnote << "txs mismatch\n"; - -// if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) -// cnote << "uncle list mismatch\n" << RLP(state.blockData())[2].data() << "\n" << RLP(block2.out())[2].data(); - -// try -// { -// state.sync(bc); -// bc.import(block2.out(), state.db()); -// state.sync(bc); -// state.commit(); - -// //there we get new blockchain status in state which could have more difficulty than we have in trueState -// //attempt to import new block to the true blockchain -// trueBc.sync(uncleBlockQueue, trueState.db(), 4); -// trueBc.attemptImport(block2.out(), trueState.db()); -// trueState.sync(trueBc); - -// blockSet newBlock; -// newBlock.first = block2.out(); -// newBlock.second = uncleBlockQueueList; -// if (importBlockNumber < blockSets.size()) -// { -// //make new correct history of imported blocks -// blockSets[importBlockNumber] = newBlock; -// for (size_t i = importBlockNumber + 1; i < blockSets.size(); i++) -// blockSets.pop_back(); -// } -// else -// blockSets.push_back(newBlock); -// } -// // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given -// catch (...) -// { -// cnote << "block is invalid!\n"; -// blObj.erase(blObj.find("blockHeader")); -// blObj.erase(blObj.find("uncleHeaders")); -// blObj.erase(blObj.find("transactions")); -// } -// blArray.push_back(blObj); -// this_thread::sleep_for(chrono::seconds(1)); + blObj["rlp"] = toHex(block.blockData(), 2, HexPrefix::Add); + + //get valid transactions + Transactions txList; + for (auto const& txi: txs.topTransactions(std::numeric_limits::max())) + txList.push_back(txi); + blObj["transactions"] = writeTransactionsToJson(txList); + + BlockHeader current_BlockHeader = block.info(); + + RLPStream uncleStream; + uncleStream.appendList(vBiUncles.size()); + for (unsigned i = 0; i < vBiUncles.size(); ++i) + { + RLPStream uncleRlp; + vBiUncles[i].streamRLP(uncleRlp); + uncleStream.appendRaw(uncleRlp.out()); + } + + if (blObj.count("blockHeader")) + overwriteBlockHeader(current_BlockHeader, blObj, bc.info()); + + if (blObj.count("blockHeader") && blObj["blockHeader"].get_obj().count("bruncle")) + current_BlockHeader.populateFromParent(vBiBlocks[vBiBlocks.size() -1]); + + if (vBiUncles.size()) + { + // update unclehash in case of invalid uncles + current_BlockHeader.setSha3Uncles(sha3(uncleStream.out())); + updatePoW(current_BlockHeader); + } + + // write block header + mObject oBlockHeader; + writeBlockHeaderToJson(oBlockHeader, current_BlockHeader); + blObj["blockHeader"] = oBlockHeader; + vBiBlocks.push_back(current_BlockHeader); + + // compare blocks from state and from rlp + RLPStream txStream; + txStream.appendList(txList.size()); + for (unsigned i = 0; i < txList.size(); ++i) + { + RLPStream txrlp; + txList[i].streamRLP(txrlp); + txStream.appendRaw(txrlp.out()); + } + + RLPStream block2 = createFullBlockFromHeader(current_BlockHeader, txStream.out(), uncleStream.out()); + + blObj["rlp"] = toHex(block2.out(), 2, HexPrefix::Add); + + if (sha3(RLP(block.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) + { + cnote << "block header mismatch block.blockData() vs updated block.info()\n"; + cerr << toHex(RLP(block.blockData())[0].data()) << "vs" << toHex(RLP(block2.out())[0].data()); + } + + if (sha3(RLP(block.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) + cnote << "txs mismatch\n"; + + if (sha3(RLP(block.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) + cnote << "uncle list mismatch\n" << RLP(block.blockData())[2].data() << "\n" << RLP(block2.out())[2].data(); + + try + { + block.sync(bc); + bc.import(block2.out(), block.db()); + block.sync(bc); + //block.commit(); + + + //there we get new blockchain status in state which could have more difficulty than we have in trueState + //attempt to import new block to the true blockchain + trueBc.sync(uncleBlockQueue, trueState.db(), 4); + trueBc.attemptImport(block2.out(), trueState.db()); + //trueState.sync(trueBc); + + blockSet newBlock; + newBlock.first = block2.out(); + newBlock.second = uncleBlockQueueList; + if (importBlockNumber < blockSets.size()) + { + //make new correct history of imported blocks + blockSets[importBlockNumber] = newBlock; + for (size_t i = importBlockNumber + 1; i < blockSets.size(); i++) + blockSets.pop_back(); + } + else + blockSets.push_back(newBlock); + } + // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given + catch (...) + { + cnote << "block is invalid!\n"; + blObj.erase(blObj.find("blockHeader")); + blObj.erase(blObj.find("uncleHeaders")); + blObj.erase(blObj.find("transactions")); + } + blArray.push_back(blObj); + this_thread::sleep_for(chrono::seconds(1)); } //for blocks -// if (o.count("expect") > 0) -// { -// AccountMaskMap expectStateMap; -// State stateExpect(OverlayDB(), BaseState::Empty, biGenesisBlock.beneficiary()); -// ImportTest::importState(o["expect"].get_obj(), stateExpect, expectStateMap); -// ImportTest::checkExpectedState(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); -// o.erase(o.find("expect")); -// } - -// o["blocks"] = blArray; -// o["postState"] = fillJsonWithState(trueState); -// o["lastblockhash"] = toString(trueBc.info().hash()); - -// //make all values hex in pre section -// State prestate(OverlayDB(), BaseState::Empty); -// ImportTest::importState(o["pre"].get_obj(), prestate); -// o["pre"] = fillJsonWithState(prestate); + if (o.count("expect") > 0) + { + AccountMaskMap expectStateMap; + State stateExpect(OverlayDB(), BaseState::Empty); + ImportTest::importState(o["expect"].get_obj(), stateExpect, expectStateMap); + ImportTest::compareStates(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); + o.erase(o.find("expect")); + } + + o["blocks"] = blArray; + o["postState"] = fillJsonWithState(trueState); + o["lastblockhash"] = toString(trueBc.info().hash()); + + //make all values hex in pre section + State prestate(OverlayDB(), BaseState::Empty); + ImportTest::importState(o["pre"].get_obj(), prestate); + o["pre"] = fillJsonWithState(prestate); }//_fillin else { From 291fbcbd3b4adb6f9f68dbba495b32620b976faf Mon Sep 17 00:00:00 2001 From: Dimitry Date: Fri, 14 Aug 2015 16:38:38 +0300 Subject: [PATCH 03/12] BlockChainTests mining --- libethereum/Block.cpp | 2 +- libethereum/Block.h | 5 +++-- test/libethereum/blockchain.cpp | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index 1c8dc1b21..fd2a51527 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -709,7 +709,7 @@ bool Block::sealBlock(bytesConstRef _header) ret.appendRaw(m_currentTxs); ret.appendRaw(m_currentUncles); ret.swapOut(m_currentBytes); - m_currentBlock = BlockInfo(_header, CheckNothing, h256(), HeaderData); + m_currentBlock = Ethash::BlockHeader(_header, CheckNothing, h256(), HeaderData); cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash() << ")"; // TODO: move into Sealer StructuredLogger::minedNewBlock( diff --git a/libethereum/Block.h b/libethereum/Block.h index feadbba73..f030661f1 100644 --- a/libethereum/Block.h +++ b/libethereum/Block.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include "Account.h" @@ -252,7 +253,7 @@ public: bytes const& blockData() const { return m_currentBytes; } /// Get the header information on the present block. - BlockInfo const& info() const { return m_currentBlock; } + Ethash::BlockHeader const& info() const { return m_currentBlock; } private: @@ -288,7 +289,7 @@ private: State m_precommit; ///< State at the point immediately prior to rewards. BlockInfo m_previousBlock; ///< The previous block's information. - BlockInfo m_currentBlock; ///< The current block's information. + Ethash::BlockHeader m_currentBlock; ///< The current block's information. bytes m_currentBytes; ///< The current block. bool m_committedToMine = false; ///< Have we committed to mine on the present m_currentBlock? diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 83a50a1f7..6cc4e8d05 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -143,7 +143,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) vBiBlocks.clear(); vBiBlocks.push_back(biGenesisBlock); - TransientDirectory td_stateDB, td_bc; + TransientDirectory td_bc; + TransientDirectory td_stateDB; FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); @@ -206,7 +207,9 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) //block.commitToSeal(bc); //Block block(State::openDB(bc.genesisHash()), BaseState::Empty, biGenesisBlock.beneficiary()); - Block block = bc.genesisBlock(State::openDB(bc.genesisHash())); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK + + //trueState TempDir default constructor for bc's state same as for trueState ? + Block block = bc.genesisBlock(trueState.db()); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK //Block block (State::openDB(biGenesisBlock.hash())); //Block block(state.db(), BaseState::Empty); //mine a new block on top of previously imported From 4ca36087252e0af9d6fb0c278f9bcb33ac078af2 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Fri, 14 Aug 2015 17:21:34 +0300 Subject: [PATCH 04/12] Mining --- test/libethereum/blockchain.cpp | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 6cc4e8d05..9ed4d21b5 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -78,20 +78,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) o["pre"] = fillJsonWithState(trueState); //convert all fields to hex trueState.commit(); - - /// Trick - //merge into init state string our test predefined state and change difficulty for testing - //string genesisState = *(const_cast(&c_genesisInfoFrontier/*c_genesisInfoOlympic*/)); - /*size_t pos = genesisState.find("alloc"); - string sss = json_spirit::write_string(o["pre"], true); - sss.replace(0, 1, ""); - sss.replace(sss.length() - 2, 2, ","); - genesisState.insert(pos + 9, sss); - genesisState.replace(genesisState.find("0x400000000"), 7, "0x20000"); - note << genesisState; - */ - /// - //Imported blocks from the start std::vector blockSets; //Block(bytes) => UncleList(Blocks(bytes)) @@ -148,7 +134,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); - State state = importer.m_statePre; + State state(OverlayDB(State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); //= importer.m_statePre; + ImportTest::importState(o["pre"].get_obj(), state); state.commit(); //import previous blocks @@ -164,7 +151,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) bc.sync(uncleQueue, state.db(), 4); bc.attemptImport(blockFromSet, state.db()); vBiBlocks.push_back(BlockHeader(blockFromSet)); - //state.sync(bc); } // get txs @@ -204,15 +190,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) } bc.sync(uncleBlockQueue, state.db(), 4); - //block.commitToSeal(bc); - //Block block(State::openDB(bc.genesisHash()), BaseState::Empty, biGenesisBlock.beneficiary()); - - //trueState TempDir default constructor for bc's state same as for trueState ? - Block block = bc.genesisBlock(trueState.db()); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK - //Block block (State::openDB(biGenesisBlock.hash())); - //Block block(state.db(), BaseState::Empty); - //mine a new block on top of previously imported + Block block = bc.genesisBlock(state.db()); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK try { block.sync(bc); @@ -230,7 +209,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) return; } - blObj["rlp"] = toHex(block.blockData(), 2, HexPrefix::Add); //get valid transactions From 77da5246e6e92f524ec6ab2143f24ad4f48d5028 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 14 Aug 2015 23:22:57 +0200 Subject: [PATCH 05/12] clean up --- test/libethereum/blockchain.cpp | 52 +++++++++++++++------------------ 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 9ed4d21b5..1626a9e2b 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -47,7 +47,7 @@ BlockHeader constructBlock(mObject& _o, h256 const& _stateRoot = h256{}); bytes createBlockRLPFromFields(mObject& _tObj, h256 const& _stateRoot = h256{}); RLPStream createFullBlockFromHeader(BlockHeader const& _bi, bytes const& _txs = RLPEmptyList, bytes const& _uncles = RLPEmptyList); -mArray writeTransactionsToJson(Transactions const& txs); +mArray writeTransactionsToJson(Transactions const& _txs); mObject writeBlockHeaderToJson(mObject& _o, BlockHeader const& _bi); void overwriteBlockHeader(BlockHeader& _current_BlockHeader, mObject& _blObj, const BlockHeader& _parent); void updatePoW(BlockHeader& _bi); @@ -55,8 +55,6 @@ mArray importUncles(mObject const& _blObj, vector& _vBiUncles, vect void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) { - _fillin = true; - for (auto& i: _v.get_obj()) { mObject& o = i.second.get_obj(); @@ -66,20 +64,20 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) continue; } - cerr << i.first << endl; + cout << i.first << endl; TBOOST_REQUIRE(o.count("genesisBlockHeader")); TBOOST_REQUIRE(o.count("pre")); ImportTest importer(o, _fillin, testType::BlockChainTests); - TransientDirectory td_stateDB_tmp; + TransientDirectory tdStateDB; BlockHeader biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), h256{}); - State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path(), h256{}, WithExisting::Kill)), BaseState::Empty); + State trueState(OverlayDB(State::openDB(tdStateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); ImportTest::importState(o["pre"].get_obj(), trueState); o["pre"] = fillJsonWithState(trueState); //convert all fields to hex trueState.commit(); //Imported blocks from the start - std::vector blockSets; //Block(bytes) => UncleList(Blocks(bytes)) + vector blockSets; //Block(bytes) => UncleList(Blocks(bytes)) if (_fillin) biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), trueState.rootHash()); @@ -121,7 +119,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) { mObject blObj = bl.get_obj(); if (blObj.count("blocknumber") > 0) - importBlockNumber = std::max((int)toInt(blObj["blocknumber"]), 1); + importBlockNumber = max((int)toInt(blObj["blocknumber"]), 1); else importBlockNumber++; @@ -129,12 +127,12 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) vBiBlocks.clear(); vBiBlocks.push_back(biGenesisBlock); - TransientDirectory td_bc; - TransientDirectory td_stateDB; - FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); + TransientDirectory tdBc; + TransientDirectory tdStateDB; + FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), tdBc.path(), WithExisting::Kill); //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); - State state(OverlayDB(State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); //= importer.m_statePre; + State state(OverlayDB(State::openDB(tdStateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); //= importer.m_statePre; ImportTest::importState(o["pre"].get_obj(), state); state.commit(); @@ -191,7 +189,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) bc.sync(uncleBlockQueue, state.db(), 4); - Block block = bc.genesisBlock(state.db()); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK + Block block = bc.genesisBlock(state.db()); try { block.sync(bc); @@ -257,38 +255,35 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) txStream.appendRaw(txrlp.out()); } - RLPStream block2 = createFullBlockFromHeader(current_BlockHeader, txStream.out(), uncleStream.out()); + RLPStream blockRLP = createFullBlockFromHeader(current_BlockHeader, txStream.out(), uncleStream.out()); - blObj["rlp"] = toHex(block2.out(), 2, HexPrefix::Add); + blObj["rlp"] = toHex(blockRLP.out(), 2, HexPrefix::Add); - if (sha3(RLP(block.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) + if (sha3(RLP(block.blockData())[0].data()) != sha3(RLP(blockRLP.out())[0].data())) { cnote << "block header mismatch block.blockData() vs updated block.info()\n"; - cerr << toHex(RLP(block.blockData())[0].data()) << "vs" << toHex(RLP(block2.out())[0].data()); + cnote << toHex(RLP(block.blockData())[0].data()) << "vs" << toHex(RLP(blockRLP.out())[0].data()); } - if (sha3(RLP(block.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) + if (sha3(RLP(block.blockData())[1].data()) != sha3(RLP(blockRLP.out())[1].data())) cnote << "txs mismatch\n"; - if (sha3(RLP(block.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) - cnote << "uncle list mismatch\n" << RLP(block.blockData())[2].data() << "\n" << RLP(block2.out())[2].data(); + if (sha3(RLP(block.blockData())[2].data()) != sha3(RLP(blockRLP.out())[2].data())) + cnote << "uncle list mismatch\n" << RLP(block.blockData())[2].data() << "\n" << RLP(blockRLP.out())[2].data(); try { block.sync(bc); - bc.import(block2.out(), block.db()); + bc.import(blockRLP.out(), block.db()); block.sync(bc); - //block.commit(); - //there we get new blockchain status in state which could have more difficulty than we have in trueState //attempt to import new block to the true blockchain trueBc.sync(uncleBlockQueue, trueState.db(), 4); - trueBc.attemptImport(block2.out(), trueState.db()); - //trueState.sync(trueBc); + trueBc.attemptImport(blockRLP.out(), trueState.db()); blockSet newBlock; - newBlock.first = block2.out(); + newBlock.first = blockRLP.out(); newBlock.second = uncleBlockQueueList; if (importBlockNumber < blockSets.size()) { @@ -561,7 +556,6 @@ mArray importUncles(mObject const& _blObj, vector& _vBiUncles, vect // make uncle header valid uncleBlockFromFields.setTimestamp((u256)time(0)); - cnote << "uncle block n = " << toString(uncleBlockFromFields.number()); if (_vBiBlocks.size() > 2) { if (uncleBlockFromFields.number() - 1 < _vBiBlocks.size()) @@ -747,10 +741,10 @@ void updatePoW(BlockHeader& _bi) _bi.noteDirty(); } -mArray writeTransactionsToJson(Transactions const& txs) +mArray writeTransactionsToJson(Transactions const& _txs) { mArray txArray; - for (auto const& txi: txs) + for (auto const& txi: _txs) { mObject txObject = fillJsonWithTransaction(txi); txArray.push_back(txObject); From e087e69213bb4c677ce548e4c176f53e0d09a003 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 11 Aug 2015 17:26:21 +0300 Subject: [PATCH 06/12] BLock2: state test filling issue --- test/libethereum/state.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/libethereum/state.cpp b/test/libethereum/state.cpp index 30c0ccff0..c37169949 100644 --- a/test/libethereum/state.cpp +++ b/test/libethereum/state.cpp @@ -62,7 +62,6 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) const State importedStatePost = importer.m_statePost; bytes output; - // execute transaction Listener::ExecTimeGuard guard{i.first}; output = importer.executeTest(); From feea9ae73bd2045c2b38bbd9aa65ca8421ce4ac9 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 12 Aug 2015 17:16:40 +0300 Subject: [PATCH 07/12] restore lost changes blockmining --- test/libethereum/blockchain.cpp | 237 ++++++++++++++++---------------- 1 file changed, 118 insertions(+), 119 deletions(-) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 3ec623685..df50e3318 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -73,7 +73,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) BlockHeader biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), h256{}); State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path(), h256{}, WithExisting::Kill)), BaseState::Empty); - importer.importState(o["pre"].get_obj(), trueState); + ImportTest::importState(o["pre"].get_obj(), trueState); o["pre"] = fillJsonWithState(trueState); //convert all fields to hex trueState.commit(); @@ -189,7 +189,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) } } bc.sync(uncleBlockQueue, state.db(), 4); - block.commitToSeal(bc); //mine a new block on top of previously imported try @@ -210,125 +209,125 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) } -// blObj["rlp"] = toHex(state.blockData(), 2, HexPrefix::Add); - -// //get valid transactions -// Transactions txList; -// for (auto const& txi: txs.topTransactions(std::numeric_limits::max())) -// txList.push_back(txi); -// blObj["transactions"] = writeTransactionsToJson(txList); - -// BlockHeader current_BlockHeader = state.info(); - -// RLPStream uncleStream; -// uncleStream.appendList(vBiUncles.size()); -// for (unsigned i = 0; i < vBiUncles.size(); ++i) -// { -// RLPStream uncleRlp; -// vBiUncles[i].streamRLP(uncleRlp); -// uncleStream.appendRaw(uncleRlp.out()); -// } - -// if (blObj.count("blockHeader")) -// overwriteBlockHeader(current_BlockHeader, blObj); - -// if (blObj.count("blockHeader") && blObj["blockHeader"].get_obj().count("bruncle")) -// current_BlockHeader.populateFromParent(vBiBlocks[vBiBlocks.size() -1]); - -// if (vBiUncles.size()) -// { -// // update unclehash in case of invalid uncles -// current_BlockHeader.setSha3Uncles(sha3(uncleStream.out())); -// updatePoW(current_BlockHeader); -// } - -// // write block header -// mObject oBlockHeader; -// writeBlockHeaderToJson(oBlockHeader, current_BlockHeader); -// blObj["blockHeader"] = oBlockHeader; -// vBiBlocks.push_back(current_BlockHeader); - -// // compare blocks from state and from rlp -// RLPStream txStream; -// txStream.appendList(txList.size()); -// for (unsigned i = 0; i < txList.size(); ++i) -// { -// RLPStream txrlp; -// txList[i].streamRLP(txrlp); -// txStream.appendRaw(txrlp.out()); -// } - -// RLPStream block2 = createFullBlockFromHeader(current_BlockHeader, txStream.out(), uncleStream.out()); - -// blObj["rlp"] = toHex(block2.out(), 2, HexPrefix::Add); - -// if (sha3(RLP(state.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) -// { -// cnote << "block header mismatch state.blockData() vs updated state.info()\n"; -// cerr << toHex(state.blockData()) << "vs" << toHex(block2.out()); -// } - -// if (sha3(RLP(state.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) -// cnote << "txs mismatch\n"; - -// if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) -// cnote << "uncle list mismatch\n" << RLP(state.blockData())[2].data() << "\n" << RLP(block2.out())[2].data(); - -// try -// { -// state.sync(bc); -// bc.import(block2.out(), state.db()); -// state.sync(bc); -// state.commit(); - -// //there we get new blockchain status in state which could have more difficulty than we have in trueState -// //attempt to import new block to the true blockchain -// trueBc.sync(uncleBlockQueue, trueState.db(), 4); -// trueBc.attemptImport(block2.out(), trueState.db()); -// trueState.sync(trueBc); - -// blockSet newBlock; -// newBlock.first = block2.out(); -// newBlock.second = uncleBlockQueueList; -// if (importBlockNumber < blockSets.size()) -// { -// //make new correct history of imported blocks -// blockSets[importBlockNumber] = newBlock; -// for (size_t i = importBlockNumber + 1; i < blockSets.size(); i++) -// blockSets.pop_back(); -// } -// else -// blockSets.push_back(newBlock); -// } -// // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given -// catch (...) -// { -// cnote << "block is invalid!\n"; -// blObj.erase(blObj.find("blockHeader")); -// blObj.erase(blObj.find("uncleHeaders")); -// blObj.erase(blObj.find("transactions")); -// } -// blArray.push_back(blObj); -// this_thread::sleep_for(chrono::seconds(1)); + blObj["rlp"] = toHex(block.blockData(), 2, HexPrefix::Add); + + //get valid transactions + Transactions txList; + for (auto const& txi: txs.topTransactions(std::numeric_limits::max())) + txList.push_back(txi); + blObj["transactions"] = writeTransactionsToJson(txList); + + BlockHeader current_BlockHeader = block.info(); + + RLPStream uncleStream; + uncleStream.appendList(vBiUncles.size()); + for (unsigned i = 0; i < vBiUncles.size(); ++i) + { + RLPStream uncleRlp; + vBiUncles[i].streamRLP(uncleRlp); + uncleStream.appendRaw(uncleRlp.out()); + } + + if (blObj.count("blockHeader")) + overwriteBlockHeader(current_BlockHeader, blObj, bc.info()); + + if (blObj.count("blockHeader") && blObj["blockHeader"].get_obj().count("bruncle")) + current_BlockHeader.populateFromParent(vBiBlocks[vBiBlocks.size() -1]); + + if (vBiUncles.size()) + { + // update unclehash in case of invalid uncles + current_BlockHeader.setSha3Uncles(sha3(uncleStream.out())); + updatePoW(current_BlockHeader); + } + + // write block header + mObject oBlockHeader; + writeBlockHeaderToJson(oBlockHeader, current_BlockHeader); + blObj["blockHeader"] = oBlockHeader; + vBiBlocks.push_back(current_BlockHeader); + + // compare blocks from state and from rlp + RLPStream txStream; + txStream.appendList(txList.size()); + for (unsigned i = 0; i < txList.size(); ++i) + { + RLPStream txrlp; + txList[i].streamRLP(txrlp); + txStream.appendRaw(txrlp.out()); + } + + RLPStream block2 = createFullBlockFromHeader(current_BlockHeader, txStream.out(), uncleStream.out()); + + blObj["rlp"] = toHex(block2.out(), 2, HexPrefix::Add); + + if (sha3(RLP(block.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) + { + cnote << "block header mismatch block.blockData() vs updated block.info()\n"; + cerr << toHex(RLP(block.blockData())[0].data()) << "vs" << toHex(RLP(block2.out())[0].data()); + } + + if (sha3(RLP(block.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) + cnote << "txs mismatch\n"; + + if (sha3(RLP(block.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) + cnote << "uncle list mismatch\n" << RLP(block.blockData())[2].data() << "\n" << RLP(block2.out())[2].data(); + + try + { + block.sync(bc); + bc.import(block2.out(), block.db()); + block.sync(bc); + //block.commit(); + + //there we get new blockchain status in state which could have more difficulty than we have in trueState + //attempt to import new block to the true blockchain + trueBc.sync(uncleBlockQueue, trueState.db(), 4); + trueBc.attemptImport(block2.out(), trueState.db()); + //trueState.sync(trueBc); + + blockSet newBlock; + newBlock.first = block2.out(); + newBlock.second = uncleBlockQueueList; + if (importBlockNumber < blockSets.size()) + { + //make new correct history of imported blocks + blockSets[importBlockNumber] = newBlock; + for (size_t i = importBlockNumber + 1; i < blockSets.size(); i++) + blockSets.pop_back(); + } + else + blockSets.push_back(newBlock); + } + // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given + catch (...) + { + cnote << "block is invalid!\n"; + blObj.erase(blObj.find("blockHeader")); + blObj.erase(blObj.find("uncleHeaders")); + blObj.erase(blObj.find("transactions")); + } + blArray.push_back(blObj); + this_thread::sleep_for(chrono::seconds(1)); } //for blocks -// if (o.count("expect") > 0) -// { -// AccountMaskMap expectStateMap; -// State stateExpect(OverlayDB(), BaseState::Empty, biGenesisBlock.beneficiary()); -// ImportTest::importState(o["expect"].get_obj(), stateExpect, expectStateMap); -// ImportTest::checkExpectedState(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); -// o.erase(o.find("expect")); -// } - -// o["blocks"] = blArray; -// o["postState"] = fillJsonWithState(trueState); -// o["lastblockhash"] = toString(trueBc.info().hash()); - -// //make all values hex in pre section -// State prestate(OverlayDB(), BaseState::Empty); -// ImportTest::importState(o["pre"].get_obj(), prestate); -// o["pre"] = fillJsonWithState(prestate); + if (o.count("expect") > 0) + { + AccountMaskMap expectStateMap; + State stateExpect(OverlayDB(), BaseState::Empty); + ImportTest::importState(o["expect"].get_obj(), stateExpect, expectStateMap); + ImportTest::compareStates(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); + o.erase(o.find("expect")); + } + + o["blocks"] = blArray; + o["postState"] = fillJsonWithState(trueState); + o["lastblockhash"] = toString(trueBc.info().hash()); + + //make all values hex in pre section + State prestate(OverlayDB(), BaseState::Empty); + ImportTest::importState(o["pre"].get_obj(), prestate); + o["pre"] = fillJsonWithState(prestate); }//_fillin else { From 238f17e79bed267af1b2a67e3b95d51a6e1a621d Mon Sep 17 00:00:00 2001 From: Dimitry Date: Fri, 14 Aug 2015 16:38:38 +0300 Subject: [PATCH 08/12] BlockChainTests mining --- libethereum/Block.cpp | 2 +- libethereum/Block.h | 5 +++-- test/libethereum/blockchain.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index 1c8dc1b21..fd2a51527 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -709,7 +709,7 @@ bool Block::sealBlock(bytesConstRef _header) ret.appendRaw(m_currentTxs); ret.appendRaw(m_currentUncles); ret.swapOut(m_currentBytes); - m_currentBlock = BlockInfo(_header, CheckNothing, h256(), HeaderData); + m_currentBlock = Ethash::BlockHeader(_header, CheckNothing, h256(), HeaderData); cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash() << ")"; // TODO: move into Sealer StructuredLogger::minedNewBlock( diff --git a/libethereum/Block.h b/libethereum/Block.h index feadbba73..f030661f1 100644 --- a/libethereum/Block.h +++ b/libethereum/Block.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include "Account.h" @@ -252,7 +253,7 @@ public: bytes const& blockData() const { return m_currentBytes; } /// Get the header information on the present block. - BlockInfo const& info() const { return m_currentBlock; } + Ethash::BlockHeader const& info() const { return m_currentBlock; } private: @@ -288,7 +289,7 @@ private: State m_precommit; ///< State at the point immediately prior to rewards. BlockInfo m_previousBlock; ///< The previous block's information. - BlockInfo m_currentBlock; ///< The current block's information. + Ethash::BlockHeader m_currentBlock; ///< The current block's information. bytes m_currentBytes; ///< The current block. bool m_committedToMine = false; ///< Have we committed to mine on the present m_currentBlock? diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index df50e3318..aed4ddf82 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -128,12 +128,12 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) vBiBlocks.clear(); vBiBlocks.push_back(biGenesisBlock); - TransientDirectory td_stateDB, td_bc; + TransientDirectory td_bc; + TransientDirectory td_stateDB; FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); State state(database, BaseState::Empty); - Block block(database, BaseState::Empty, biGenesisBlock.beneficiary()); state = importer.m_statePre; state.commit(); @@ -188,7 +188,9 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) cnote << "error in importing uncle! This produces an invalid block (May be by purpose for testing)."; } } + bc.sync(uncleBlockQueue, state.db(), 4); + Block block = bc.genesisBlock(state.db()); //mine a new block on top of previously imported try From 9c19f5d61f7a1f018f62dcac269d82dd9e032c1d Mon Sep 17 00:00:00 2001 From: Dimitry Date: Fri, 14 Aug 2015 17:21:34 +0300 Subject: [PATCH 09/12] Mining --- test/libethereum/blockchain.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index aed4ddf82..0188951b2 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -132,9 +132,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) TransientDirectory td_stateDB; FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); - OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); - State state(database, BaseState::Empty); - state = importer.m_statePre; + //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); + State state = importer.m_statePre; state.commit(); //import previous blocks @@ -210,7 +209,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) return; } - blObj["rlp"] = toHex(block.blockData(), 2, HexPrefix::Add); //get valid transactions From bcd6602bafad055f525a41526cc5d9b315f5f4db Mon Sep 17 00:00:00 2001 From: Dimitry Date: Sat, 15 Aug 2015 12:11:41 +0300 Subject: [PATCH 10/12] Fill tests --- .../bcValidBlockTestFiller.json | 2 +- test/libethereum/blockchain.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/libethereum/BlockchainTestsFiller/bcValidBlockTestFiller.json b/test/libethereum/BlockchainTestsFiller/bcValidBlockTestFiller.json index a1995ddbd..c983ca107 100644 --- a/test/libethereum/BlockchainTestsFiller/bcValidBlockTestFiller.json +++ b/test/libethereum/BlockchainTestsFiller/bcValidBlockTestFiller.json @@ -167,7 +167,7 @@ }, "expect" : { "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "100" + "balance" : "5100" } }, "pre" : { diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 0188951b2..475904b27 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -73,6 +73,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) BlockHeader biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), h256{}); State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path(), h256{}, WithExisting::Kill)), BaseState::Empty); + Block trueBlock; //lastBlock of trueBlockchain ImportTest::importState(o["pre"].get_obj(), trueState); o["pre"] = fillJsonWithState(trueState); //convert all fields to hex trueState.commit(); @@ -133,7 +134,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); - State state = importer.m_statePre; + State state(OverlayDB(State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); //= importer.m_statePre; + ImportTest::importState(o["pre"].get_obj(), state); state.commit(); //import previous blocks @@ -149,7 +151,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) bc.sync(uncleQueue, state.db(), 4); bc.attemptImport(blockFromSet, state.db()); vBiBlocks.push_back(BlockHeader(blockFromSet)); - //state.sync(bc); } // get txs @@ -189,9 +190,9 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) } bc.sync(uncleBlockQueue, state.db(), 4); - Block block = bc.genesisBlock(state.db()); - //mine a new block on top of previously imported + Block block = bc.genesisBlock(state.db()); //NOT CLEAR WHAT IT RETURNS IF bc INITIALIZED WITH CUSTOM GENESIS BLOCK + block.setBeneficiary(biGenesisBlock.beneficiary()); try { block.sync(bc); @@ -284,7 +285,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) //attempt to import new block to the true blockchain trueBc.sync(uncleBlockQueue, trueState.db(), 4); trueBc.attemptImport(block2.out(), trueState.db()); - //trueState.sync(trueBc); + trueBlock = block; //seems to be the last imported block blockSet newBlock; newBlock.first = block2.out(); @@ -316,7 +317,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) AccountMaskMap expectStateMap; State stateExpect(OverlayDB(), BaseState::Empty); ImportTest::importState(o["expect"].get_obj(), stateExpect, expectStateMap); - ImportTest::compareStates(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); + ImportTest::compareStates(stateExpect, trueBlock.state(), expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); o.erase(o.find("expect")); } From bcbe9aee6e2df5a3b9255fd306e33fb58b809e09 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 17 Aug 2015 08:45:23 +0200 Subject: [PATCH 11/12] style --- test/libethereum/blockchain.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index f090db8ee..10bda395e 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -69,10 +69,10 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) TBOOST_REQUIRE(o.count("pre")); ImportTest importer(o, _fillin, testType::BlockChainTests); - TransientDirectory td_stateDB_tmp; + TransientDirectory tdStateDB; BlockHeader biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), h256{}); - State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path(), h256{}, WithExisting::Kill)), BaseState::Empty); + State trueState(OverlayDB(State::openDB(tdStateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); Block trueBlock; //lastBlock of trueBlockchain ImportTest::importState(o["pre"].get_obj(), trueState); o["pre"] = fillJsonWithState(trueState); //convert all fields to hex @@ -129,12 +129,12 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) vBiBlocks.clear(); vBiBlocks.push_back(biGenesisBlock); - TransientDirectory td_bc; - TransientDirectory td_stateDB; - FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill); + TransientDirectory tdBc; + TransientDirectory tdStateDB; + FullBlockChain bc(rlpGenesisBlock.out(), AccountMap(), tdBc.path(), WithExisting::Kill); //OverlayDB database (State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)); - State state(OverlayDB(State::openDB(td_stateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); //= importer.m_statePre; + State state(OverlayDB(State::openDB(tdStateDB.path(), h256{}, WithExisting::Kill)), BaseState::Empty); //= importer.m_statePre; ImportTest::importState(o["pre"].get_obj(), state); state.commit(); From 413ebfe429700f2c2001245251baa294b2e10554 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 17 Aug 2015 09:37:21 +0200 Subject: [PATCH 12/12] fix coinbase rewards in blockChainTests --- test/libethereum/blockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 10bda395e..633707560 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -284,6 +284,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) //attempt to import new block to the true blockchain trueBc.sync(uncleBlockQueue, trueState.db(), 4); trueBc.attemptImport(blockRLP.out(), trueState.db()); + trueState = block.state(); blockSet newBlock; newBlock.first = blockRLP.out();