Browse Source

Merge pull request #4 from CJentzsch/winsvegaBlock2

clean up - merge to develop
cl-refactor
winsvega 10 years ago
parent
commit
cccf005420
  1. 46
      test/libethereum/blockchain.cpp

46
test/libethereum/blockchain.cpp

@ -45,7 +45,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);
@ -69,17 +69,17 @@ 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
trueState.commit();
//Imported blocks from the start
std::vector<blockSet> blockSets; //Block(bytes) => UncleList(Blocks(bytes))
vector<blockSet> blockSets; //Block(bytes) => UncleList(Blocks(bytes))
if (_fillin)
biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), trueState.rootHash());
@ -121,7 +121,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 +129,12 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
vBiBlocks.clear();
vBiBlocks.push_back(biGenesisBlock);
TransientDirectory td_bc;
TransientDirectory td_stateDB;
FullBlockChain<Ethash> bc(rlpGenesisBlock.out(), AccountMap(), td_bc.path(), WithExisting::Kill);
TransientDirectory tdBc;
TransientDirectory tdStateDB;
FullBlockChain<Ethash> 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();
@ -258,37 +258,36 @@ 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());
trueBlock = block; //seems to be the last imported block
trueBc.attemptImport(blockRLP.out(), trueState.db());
trueState = block.state();
blockSet newBlock;
newBlock.first = block2.out();
newBlock.first = blockRLP.out();
newBlock.second = uncleBlockQueueList;
if (importBlockNumber < blockSets.size())
{
@ -561,7 +560,6 @@ mArray importUncles(mObject const& _blObj, vector<BlockHeader>& _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 +745,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);

Loading…
Cancel
Save