Browse Source

Merge pull request #2498 from arkpar/whizz

Whizz branch fixes for Mix, AZ, eth
cl-refactor
Gav Wood 10 years ago
parent
commit
4eab395bc2
  1. 28
      CMakeLists.txt
  2. 53
      alethzero/MainWin.cpp
  3. 4
      alethzero/MiningView.cpp
  4. 4
      alethzero/MiningView.h
  5. 2
      eth/main.cpp
  6. 26
      ethminer/MinerAux.h
  7. 12
      evmjit/libevmjit-cpp/JitVM.cpp
  8. 4
      exp/CMakeLists.txt
  9. 1
      libethcore/BlockInfo.h
  10. 3
      libethcore/Common.h
  11. 3
      libethereum/BlockChain.cpp
  12. 9
      libethereum/BlockChain.h
  13. 2
      libethereum/BlockQueue.cpp
  14. 3
      libethereum/Client.cpp
  15. 6
      libethereum/Client.h
  16. 3
      libtestutils/BlockChainLoader.cpp
  17. 2
      libtestutils/StateLoader.cpp
  18. 2
      libtestutils/StateLoader.h
  19. 8
      libweb3jsonrpc/JsonHelper.cpp
  20. 2
      libweb3jsonrpc/WebThreeStubServer.cpp
  21. 4
      libweb3jsonrpc/WebThreeStubServer.h
  22. 2
      libwebthree/WebThree.cpp
  23. 4
      mix/ClientModel.cpp
  24. 36
      mix/MixClient.cpp
  25. 36
      mix/MixClient.h
  26. 17
      test/TestHelper.cpp
  27. 10
      test/libethcore/dagger.cpp
  28. 18
      test/libethereum/ClientBase.cpp
  29. 3
      test/libethereum/gaspricer.cpp
  30. 6
      test/libethereum/genesis.cpp
  31. 5
      test/libethereum/stateOriginal.cpp
  32. 10
      test/libevm/vm.cpp

28
CMakeLists.txt

@ -400,13 +400,13 @@ if (TOOLS)
endif () endif ()
if (JSONRPC AND GENERAL) if (JSONRPC AND GENERAL)
# add_subdirectory(libweb3jsonrpc) add_subdirectory(libweb3jsonrpc)
endif () endif ()
if (JSCONSOLE) if (JSCONSOLE)
# add_subdirectory(libjsengine) add_subdirectory(libjsengine)
# add_subdirectory(libjsconsole) add_subdirectory(libjsconsole)
# add_subdirectory(ethconsole) add_subdirectory(ethconsole)
endif () endif ()
if (NOT WIN32) if (NOT WIN32)
@ -434,31 +434,31 @@ add_subdirectory(libethcore)
if (GENERAL) if (GENERAL)
add_subdirectory(libevm) add_subdirectory(libevm)
add_subdirectory(libethereum) add_subdirectory(libethereum)
# add_subdirectory(libwebthree) add_subdirectory(libwebthree)
endif () endif ()
if (MINER OR TOOLS) if (MINER OR TOOLS)
# add_subdirectory(ethminer) add_subdirectory(ethminer)
endif () endif ()
if (ETHKEY OR TOOLS) if (ETHKEY OR TOOLS)
# add_subdirectory(ethkey) add_subdirectory(ethkey)
endif () endif ()
if (TESTS) if (TESTS)
# add_subdirectory(libtestutils) add_subdirectory(libtestutils)
# add_subdirectory(test) add_subdirectory(test)
if (JSONRPC) if (JSONRPC)
# add_subdirectory(ethrpctest) add_subdirectory(ethrpctest)
endif () endif ()
endif () endif ()
if (TOOLS) if (TOOLS)
# add_subdirectory(rlp) add_subdirectory(rlp)
# add_subdirectory(abi) add_subdirectory(abi)
# add_subdirectory(ethvm) add_subdirectory(ethvm)
# add_subdirectory(eth) add_subdirectory(eth)
if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug")
add_subdirectory(exp) add_subdirectory(exp)

53
alethzero/MainWin.cpp

@ -189,9 +189,9 @@ Main::Main(QWidget *parent) :
#endif #endif
m_servers.append(QString::fromStdString(Host::pocHost() + ":30303")); m_servers.append(QString::fromStdString(Host::pocHost() + ":30303"));
cerr << "State root: " << CanonBlockChain::genesis().stateRoot() << endl; cerr << "State root: " << CanonBlockChain<Ethash>::genesis().stateRoot() << endl;
auto block = CanonBlockChain::createGenesisBlock(); auto block = CanonBlockChain<Ethash>::createGenesisBlock();
cerr << "Block Hash: " << CanonBlockChain::genesis().hash() << endl; cerr << "Block Hash: " << CanonBlockChain<Ethash>::genesis().hash() << endl;
cerr << "Block RLP: " << RLP(block) << endl; cerr << "Block RLP: " << RLP(block) << endl;
cerr << "Block Hex: " << toHex(block) << endl; cerr << "Block Hex: " << toHex(block) << endl;
cerr << "eth Network protocol version: " << eth::c_protocolVersion << endl; cerr << "eth Network protocol version: " << eth::c_protocolVersion << endl;
@ -208,13 +208,14 @@ Main::Main(QWidget *parent) :
statusBar()->addPermanentWidget(ui->chainStatus); statusBar()->addPermanentWidget(ui->chainStatus);
statusBar()->addPermanentWidget(ui->blockCount); statusBar()->addPermanentWidget(ui->blockCount);
ui->blockCount->setText(QString("PV%1.%2 D%3 %4-%5 v%6").arg(eth::c_protocolVersion).arg(eth::c_minorProtocolVersion).arg(c_databaseVersion).arg(QString::fromStdString(ethereum()->sealEngine()->name())).arg(ethereum()->sealEngine()->revision()).arg(dev::Version));
QSettings s("ethereum", "alethzero"); QSettings s("ethereum", "alethzero");
m_networkConfig = s.value("peers").toByteArray(); m_networkConfig = s.value("peers").toByteArray();
bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size()); bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size());
m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), WithExisting::Trust, {"eth"/*, "shh"*/}, p2p::NetworkPreferences(), network)); m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), WithExisting::Trust, {"eth"/*, "shh"*/}, p2p::NetworkPreferences(), network));
ui->blockCount->setText(QString("PV%1.%2 D%3 %4-%5 v%6").arg(eth::c_protocolVersion).arg(eth::c_minorProtocolVersion).arg(c_databaseVersion).arg(QString::fromStdString(ethereum()->sealEngine()->name())).arg(ethereum()->sealEngine()->revision()).arg(dev::Version));
m_httpConnector.reset(new jsonrpc::HttpServer(SensibleHttpPort, "", "", dev::SensibleHttpThreads)); m_httpConnector.reset(new jsonrpc::HttpServer(SensibleHttpPort, "", "", dev::SensibleHttpThreads));
auto w3ss = new OurWebThreeStubServer(*m_httpConnector, this); auto w3ss = new OurWebThreeStubServer(*m_httpConnector, this);
m_server.reset(w3ss); m_server.reset(w3ss);
@ -1124,7 +1125,7 @@ void Main::refreshMining()
QString t; QString t;
if (gp.first != EthashAux::NotGenerating) if (gp.first != EthashAux::NotGenerating)
t = QString("DAG for #%1-#%2: %3% complete; ").arg(gp.first).arg(gp.first + ETHASH_EPOCH_LENGTH - 1).arg(gp.second); t = QString("DAG for #%1-#%2: %3% complete; ").arg(gp.first).arg(gp.first + ETHASH_EPOCH_LENGTH - 1).arg(gp.second);
MiningProgress p = ethereum()->miningProgress(); WorkingProgress p = ethereum()->miningProgress();
ui->mineStatus->setText(t + (ethereum()->isMining() ? p.hashes > 0 ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Awaiting DAG" : "Not mining")); ui->mineStatus->setText(t + (ethereum()->isMining() ? p.hashes > 0 ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Awaiting DAG" : "Not mining"));
if (ethereum()->isMining() && p.hashes > 0) if (ethereum()->isMining() && p.hashes > 0)
{ {
@ -1629,7 +1630,7 @@ void Main::on_transactionQueue_currentItemChanged()
else else
s << "<div>Log Bloom: <b><i>Uneventful</i></b></div>"; s << "<div>Log Bloom: <b><i>Uneventful</i></b></div>";
s << "<div>Gas Used: <b>" << receipt.gasUsed() << "</b></div>"; s << "<div>Gas Used: <b>" << receipt.gasUsed() << "</b></div>";
s << "<div>End State: <b>" << receipt.stateRoot()().abridged() << "</b></div>"; s << "<div>End State: <b>" << receipt.stateRoot().abridged() << "</b></div>";
auto r = receipt.rlp(); auto r = receipt.rlp();
s << "<div>Receipt: " << toString(RLP(r)) << "</div>"; s << "<div>Receipt: " << toString(RLP(r)) << "</div>";
s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>"; s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>";
@ -1699,7 +1700,7 @@ void Main::on_blocks_currentItemChanged()
auto details = ethereum()->blockChain().details(h); auto details = ethereum()->blockChain().details(h);
auto blockData = ethereum()->blockChain().block(h); auto blockData = ethereum()->blockChain().block(h);
auto block = RLP(blockData); auto block = RLP(blockData);
BlockInfo info(blockData); Ethash::BlockHeader info(blockData);
stringstream s; stringstream s;
@ -1709,21 +1710,21 @@ void Main::on_blocks_currentItemChanged()
time_t rawTime = (time_t)(uint64_t)info.timestamp(); time_t rawTime = (time_t)(uint64_t)info.timestamp();
strftime(timestamp, 64, "%c", localtime(&rawTime)); strftime(timestamp, 64, "%c", localtime(&rawTime));
s << "<h3>" << h << "</h3>"; s << "<h3>" << h << "</h3>";
s << "<h4>#" << info.number; s << "<h4>#" << info.number();
s << "&nbsp;&emsp;&nbsp;<b>" << timestamp << "</b></h4>"; s << "&nbsp;&emsp;&nbsp;<b>" << timestamp << "</b></h4>";
s << "<div>D/TD: <b>" << info.difficulty << "</b>/<b>" << details.totalDifficulty << "</b> = 2^" << log2((double)info.difficulty) << "/2^" << log2((double)details.totalDifficulty) << "</div>"; s << "<div>D/TD: <b>" << info.difficulty() << "</b>/<b>" << details.totalDifficulty << "</b> = 2^" << log2((double)info.difficulty()) << "/2^" << log2((double)details.totalDifficulty) << "</div>";
s << "&nbsp;&emsp;&nbsp;Children: <b>" << details.children.size() << "</b></div>"; s << "&nbsp;&emsp;&nbsp;Children: <b>" << details.children.size() << "</b></div>";
s << "<div>Gas used/limit: <b>" << info.gasUsed << "</b>/<b>" << info.gasLimit << "</b>" << "</div>"; s << "<div>Gas used/limit: <b>" << info.gasUsed() << "</b>/<b>" << info.gasLimit() << "</b>" << "</div>";
s << "<div>Beneficiary: <b>" << htmlEscaped(pretty(info.coinbaseAddress())) << " " << info.coinbaseAddress() << "</b>" << "</div>"; s << "<div>Beneficiary: <b>" << htmlEscaped(pretty(info.coinbaseAddress())) << " " << info.coinbaseAddress() << "</b>" << "</div>";
s << "<div>Seed hash: <b>" << info.seedHash() << "</b>" << "</div>"; s << "<div>Seed hash: <b>" << info.seedHash() << "</b>" << "</div>";
s << "<div>Mix hash: <b>" << info.mixHash << "</b>" << "</div>"; s << "<div>Mix hash: <b>" << info.mixHash() << "</b>" << "</div>";
s << "<div>Nonce: <b>" << info.nonce << "</b>" << "</div>"; s << "<div>Nonce: <b>" << info.nonce() << "</b>" << "</div>";
s << "<div>Hash w/o nonce: <b>" << info.headerHash(WithoutProof) << "</b>" << "</div>"; s << "<div>Hash w/o nonce: <b>" << info.hashWithout() << "</b>" << "</div>";
s << "<div>Difficulty: <b>" << info.difficulty << "</b>" << "</div>"; s << "<div>Difficulty: <b>" << info.difficulty() << "</b>" << "</div>";
if (info.number) if (info.number())
{ {
auto e = EthashAux::eval(info); auto e = EthashAux::eval(info.seedHash(), info.hashWithout(), info.nonce());
s << "<div>Proof-of-Work: <b>" << e.value << " &lt;= " << (h256)u256((bigint(1) << 256) / info.difficulty) << "</b> (mixhash: " << e.mixHash.abridged() << ")" << "</div>"; s << "<div>Proof-of-Work: <b>" << e.value << " &lt;= " << (h256)u256((bigint(1) << 256) / info.difficulty()) << "</b> (mixhash: " << e.mixHash.abridged() << ")" << "</div>";
s << "<div>Parent: <b>" << info.parentHash() << "</b>" << "</div>"; s << "<div>Parent: <b>" << info.parentHash() << "</b>" << "</div>";
} }
else else
@ -1740,19 +1741,19 @@ void Main::on_blocks_currentItemChanged()
s << "<div>Uncles: <b>" << block[2].itemCount() << "</b> @<b>" << info.sha3Uncles() << "</b>" << "</div>"; s << "<div>Uncles: <b>" << block[2].itemCount() << "</b> @<b>" << info.sha3Uncles() << "</b>" << "</div>";
for (auto u: block[2]) for (auto u: block[2])
{ {
BlockInfo uncle = BlockInfo::fromHeader(u.data()); Ethash::BlockHeader uncle(u.data(), CheckNothing, h256(), HeaderData);
char const* line = "<div><span style=\"margin-left: 2em\">&nbsp;</span>"; char const* line = "<div><span style=\"margin-left: 2em\">&nbsp;</span>";
s << line << "Hash: <b>" << uncle.hash() << "</b>" << "</div>"; s << line << "Hash: <b>" << uncle.hash() << "</b>" << "</div>";
s << line << "Parent: <b>" << uncle.parentHash() << "</b>" << "</div>"; s << line << "Parent: <b>" << uncle.parentHash() << "</b>" << "</div>";
s << line << "Number: <b>" << uncle.number << "</b>" << "</div>"; s << line << "Number: <b>" << uncle.number() << "</b>" << "</div>";
s << line << "Coinbase: <b>" << htmlEscaped(pretty(uncle.coinbaseAddress())) << " " << uncle.coinbaseAddress() << "</b>" << "</div>"; s << line << "Coinbase: <b>" << htmlEscaped(pretty(uncle.coinbaseAddress())) << " " << uncle.coinbaseAddress() << "</b>" << "</div>";
s << line << "Seed hash: <b>" << uncle.seedHash() << "</b>" << "</div>"; s << line << "Seed hash: <b>" << uncle.seedHash() << "</b>" << "</div>";
s << line << "Mix hash: <b>" << uncle.mixHash << "</b>" << "</div>"; s << line << "Mix hash: <b>" << uncle.mixHash() << "</b>" << "</div>";
s << line << "Nonce: <b>" << uncle.nonce << "</b>" << "</div>"; s << line << "Nonce: <b>" << uncle.nonce() << "</b>" << "</div>";
s << line << "Hash w/o nonce: <b>" << uncle.headerHash(WithoutProof) << "</b>" << "</div>"; s << line << "Hash w/o nonce: <b>" << uncle.headerHash(WithoutProof) << "</b>" << "</div>";
s << line << "Difficulty: <b>" << uncle.difficulty << "</b>" << "</div>"; s << line << "Difficulty: <b>" << uncle.difficulty() << "</b>" << "</div>";
auto e = EthashAux::eval(uncle); auto e = EthashAux::eval(uncle.seedHash(), uncle.hashWithout(), uncle.nonce());
s << line << "Proof-of-Work: <b>" << e.value << " &lt;= " << (h256)u256((bigint(1) << 256) / uncle.difficulty) << "</b> (mixhash: " << e.mixHash.abridged() << ")" << "</div>"; s << line << "Proof-of-Work: <b>" << e.value << " &lt;= " << (h256)u256((bigint(1) << 256) / uncle.difficulty()) << "</b> (mixhash: " << e.mixHash.abridged() << ")" << "</div>";
} }
if (info.parentHash()) if (info.parentHash())
s << "<div>Pre: <b>" << BlockInfo(ethereum()->blockChain().block(info.parentHash())).stateRoot() << "</b>" << "</div>"; s << "<div>Pre: <b>" << BlockInfo(ethereum()->blockChain().block(info.parentHash())).stateRoot() << "</b>" << "</div>";
@ -1764,7 +1765,7 @@ void Main::on_blocks_currentItemChanged()
unsigned ii = 0; unsigned ii = 0;
for (auto const& i: block[1]) for (auto const& i: block[1])
{ {
s << "<div>" << sha3(i.data()).abridged() << ": <b>" << receipts.receipts[ii].stateRoot()() << "</b> [<b>" << receipts.receipts[ii].gasUsed() << "</b> used]" << "</div>"; s << "<div>" << sha3(i.data()).abridged() << ": <b>" << receipts.receipts[ii].stateRoot() << "</b> [<b>" << receipts.receipts[ii].gasUsed() << "</b> used]" << "</div>";
++ii; ++ii;
} }
s << "<div>Post: <b>" << info.stateRoot() << "</b>" << "</div>"; s << "<div>Post: <b>" << info.stateRoot() << "</b>" << "</div>";
@ -1807,7 +1808,7 @@ void Main::on_blocks_currentItemChanged()
else else
s << "<div>Log Bloom: <b><i>Uneventful</i></b></div>"; s << "<div>Log Bloom: <b><i>Uneventful</i></b></div>";
s << "<div>Gas Used: <b>" << receipt.gasUsed() << "</b></div>"; s << "<div>Gas Used: <b>" << receipt.gasUsed() << "</b></div>";
s << "<div>End State: <b>" << receipt.stateRoot()().abridged() << "</b></div>"; s << "<div>End State: <b>" << receipt.stateRoot().abridged() << "</b></div>";
auto r = receipt.rlp(); auto r = receipt.rlp();
s << "<div>Receipt: " << toString(RLP(r)) << "</div>"; s << "<div>Receipt: " << toString(RLP(r)) << "</div>";
s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>"; s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>";

4
alethzero/MiningView.cpp

@ -36,7 +36,7 @@ using namespace dev::eth;
// types // types
using dev::eth::MineInfo; using dev::eth::MineInfo;
using dev::eth::MiningProgress; using dev::eth::WorkingProgress;
// functions // functions
using dev::toString; using dev::toString;
@ -50,7 +50,7 @@ MiningView::MiningView(QWidget* _p): QWidget(_p)
{ {
} }
void MiningView::appendStats(list<MineInfo> const& _i, MiningProgress const& _p) void MiningView::appendStats(list<MineInfo> const& _i, WorkingProgress const& _p)
{ {
(void)_p; (void)_p;
if (_i.empty()) if (_i.empty())

4
alethzero/MiningView.h

@ -42,14 +42,14 @@ class MiningView: public QWidget
public: public:
MiningView(QWidget* _p = nullptr); MiningView(QWidget* _p = nullptr);
void appendStats(std::list<dev::eth::MineInfo> const& _l, dev::eth::MiningProgress const& _p); void appendStats(std::list<dev::eth::MineInfo> const& _l, dev::eth::WorkingProgress const& _p);
void resetStats(); void resetStats();
protected: protected:
virtual void paintEvent(QPaintEvent*); virtual void paintEvent(QPaintEvent*);
private: private:
dev::eth::MiningProgress m_progress; dev::eth::WorkingProgress m_progress;
unsigned m_duration = 300; unsigned m_duration = 300;
std::vector<float> m_values; std::vector<float> m_values;
std::vector<float> m_bests; std::vector<float> m_bests;

2
eth/main.cpp

@ -1311,7 +1311,7 @@ int main(int argc, char** argv)
{ {
try try
{ {
CanonBlockChain::setGenesisNonce(Nonce(argv[++i])); CanonBlockChain<Ethash>::setGenesisNonce(Nonce(argv[++i]));
} }
catch (...) catch (...)
{ {

26
ethminer/MinerAux.h

@ -397,17 +397,16 @@ public:
private: private:
void doInitDAG(unsigned _n) void doInitDAG(unsigned _n)
{ {
BlockInfo bi; h256 seedHash = EthashAux::seedHash(_n);
bi.number() = _n; cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl;
cout << "Initializing DAG for epoch beginning #" << (bi.number() / 30000 * 30000) << " (seedhash " << bi.proofCache().abridged() << "). This will take a while." << endl; EthashAux::full(seedHash, true);
Ethash::prep(bi);
exit(0); exit(0);
} }
void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5) void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5)
{ {
BlockInfo genesis; Ethash::BlockHeader genesis;
genesis.difficulty = 1 << 18; genesis.setDifficulty(1 << 18);
cdebug << genesis.boundary(); cdebug << genesis.boundary();
GenericFarm<EthashProofOfWork> f; GenericFarm<EthashProofOfWork> f;
@ -417,17 +416,16 @@ private:
cout << "Benchmarking on platform: " << platformInfo << endl; cout << "Benchmarking on platform: " << platformInfo << endl;
cout << "Preparing DAG..." << endl; cout << "Preparing DAG..." << endl;
Ethash::prep(genesis); genesis.prep();
genesis.difficulty = u256(1) << 63; genesis.setDifficulty(u256(1) << 63);
genesis.noteDirty();
f.setWork(genesis); f.setWork(genesis);
if (_m == MinerType::CPU) if (_m == MinerType::CPU)
f.startCPU(); f.start("cpu");
else if (_m == MinerType::GPU) else if (_m == MinerType::GPU)
f.startGPU(); f.start("opencl");
map<uint64_t, MiningProgress> results; map<uint64_t, WorkingProgress> results;
uint64_t mean = 0; uint64_t mean = 0;
uint64_t innerMean = 0; uint64_t innerMean = 0;
for (unsigned i = 0; i <= _trials; ++i) for (unsigned i = 0; i <= _trials; ++i)
@ -488,9 +486,9 @@ private:
Farm rpc(client); Farm rpc(client);
GenericFarm<EthashProofOfWork> f; GenericFarm<EthashProofOfWork> f;
if (_m == MinerType::CPU) if (_m == MinerType::CPU)
f.startCPU(); f.start("cpu");
else if (_m == MinerType::GPU) else if (_m == MinerType::GPU)
f.startGPU(); f.start("opencl");
EthashProofOfWork::WorkPackage current; EthashProofOfWork::WorkPackage current;
EthashAux::FullType dag; EthashAux::FullType dag;

12
evmjit/libevmjit-cpp/JitVM.cpp

@ -23,8 +23,8 @@ bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _on
// TODO: Rejecting transactions with gas limit > 2^63 can be used by attacker to take JIT out of scope // TODO: Rejecting transactions with gas limit > 2^63 can be used by attacker to take JIT out of scope
rejected |= io_gas > std::numeric_limits<decltype(m_data.gas)>::max(); // Do not accept requests with gas > 2^63 (int64 max) rejected |= io_gas > std::numeric_limits<decltype(m_data.gas)>::max(); // Do not accept requests with gas > 2^63 (int64 max)
rejected |= _ext.gasPrice > std::numeric_limits<decltype(m_data.gasPrice)>::max(); rejected |= _ext.gasPrice > std::numeric_limits<decltype(m_data.gasPrice)>::max();
rejected |= _ext.currentBlock.number > std::numeric_limits<decltype(m_data.number)>::max(); rejected |= _ext.currentBlock.number() > std::numeric_limits<decltype(m_data.number)>::max();
rejected |= _ext.currentBlock.timestamp() > std::numeric_limits<decltype(m_data.timestamp())>::max(); rejected |= _ext.currentBlock.timestamp() > std::numeric_limits<decltype(m_data.timestamp)>::max();
if (rejected) if (rejected)
{ {
@ -42,10 +42,10 @@ bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _on
m_data.origin = eth2jit(fromAddress(_ext.origin)); m_data.origin = eth2jit(fromAddress(_ext.origin));
m_data.callValue = eth2jit(_ext.value); m_data.callValue = eth2jit(_ext.value);
m_data.coinBase = eth2jit(fromAddress(_ext.currentBlock.coinbaseAddress())); m_data.coinBase = eth2jit(fromAddress(_ext.currentBlock.coinbaseAddress()));
m_data.difficulty = eth2jit(_ext.currentBlock.difficulty); m_data.difficulty = eth2jit(_ext.currentBlock.difficulty());
m_data.gasLimit = eth2jit(_ext.currentBlock.gasLimit); m_data.gasLimit = eth2jit(_ext.currentBlock.gasLimit());
m_data.number = static_cast<decltype(m_data.number)>(_ext.currentBlock.number); m_data.number = static_cast<decltype(m_data.number)>(_ext.currentBlock.number());
m_data.timestamp() = static_cast<decltype(m_data.timestamp())>(_ext.currentBlock.timestamp()); m_data.timestamp = static_cast<decltype(m_data.timestamp)>(_ext.currentBlock.timestamp());
m_data.code = _ext.code.data(); m_data.code = _ext.code.data();
m_data.codeSize = _ext.code.size(); m_data.codeSize = _ext.code.size();
m_data.codeHash = eth2jit(_ext.codeHash); m_data.codeHash = eth2jit(_ext.codeHash);

4
exp/CMakeLists.txt

@ -21,10 +21,10 @@ if (READLINE_FOUND)
endif() endif()
if (JSONRPC) if (JSONRPC)
# target_link_libraries(${EXECUTABLE} web3jsonrpc) target_link_libraries(${EXECUTABLE} web3jsonrpc)
endif() endif()
#target_link_libraries(${EXECUTABLE} webthree) target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} p2p) target_link_libraries(${EXECUTABLE} p2p)
if (ETHASHCL) if (ETHASHCL)

1
libethcore/BlockInfo.h

@ -128,6 +128,7 @@ public:
void setGasUsed(u256 const& _v) { m_gasUsed = _v; noteDirty(); } void setGasUsed(u256 const& _v) { m_gasUsed = _v; noteDirty(); }
void setExtraData(bytes const& _v) { m_extraData = _v; noteDirty(); } void setExtraData(bytes const& _v) { m_extraData = _v; noteDirty(); }
void setLogBloom(LogBloom const& _v) { m_logBloom = _v; noteDirty(); } void setLogBloom(LogBloom const& _v) { m_logBloom = _v; noteDirty(); }
void setDifficulty(u256 const& _v) { m_difficulty = _v; noteDirty(); }
Address const& coinbaseAddress() const { return m_coinbaseAddress; } Address const& coinbaseAddress() const { return m_coinbaseAddress; }
h256 const& stateRoot() const { return m_stateRoot; } h256 const& stateRoot() const { return m_stateRoot; }

3
libethcore/Common.h

@ -130,9 +130,10 @@ struct ImportRequirements
TransactionBasic = 8, ///< Check the basic structure of the transactions. TransactionBasic = 8, ///< Check the basic structure of the transactions.
UncleSeals = 16, ///< Check the basic structure of the uncles. UncleSeals = 16, ///< Check the basic structure of the uncles.
TransactionSignatures = 32, ///< Check the basic structure of the transactions. TransactionSignatures = 32, ///< Check the basic structure of the transactions.
Parent = 64, ///< Check parent block header
CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals
CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures
Default = ValidSeal | DontHave | CheckUncles | CheckTransactions, Everything = ValidSeal | DontHave | CheckUncles | CheckTransactions | Parent,
None = 0 None = 0
}; };
}; };

3
libethereum/BlockChain.cpp

@ -137,7 +137,6 @@ BlockChain::BlockChain(bytes const& _genesisBlock, std::unordered_map<Address, A
// Initialise with the genesis as the last block on the longest chain. // Initialise with the genesis as the last block on the longest chain.
m_genesisBlock = _genesisBlock; m_genesisBlock = _genesisBlock;
m_genesisHash = sha3(RLP(m_genesisBlock)[0].data()); m_genesisHash = sha3(RLP(m_genesisBlock)[0].data());
m_genesisState = _genesisState;
// remove the next line real soon. we don't need to be supporting this forever. // remove the next line real soon. we don't need to be supporting this forever.
upgradeDatabase(_path, genesisHash()); upgradeDatabase(_path, genesisHash());
@ -356,7 +355,7 @@ tuple<ImportRoute, bool, unsigned> BlockChain::sync(BlockQueue& _bq, OverlayDB c
// Nonce & uncle nonces already verified in verification thread at this point. // Nonce & uncle nonces already verified in verification thread at this point.
ImportRoute r; ImportRoute r;
DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number()), 500) DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number()), 500)
r = import(block.verified, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidSeal & ~ImportRequirements::CheckUncles); r = import(block.verified, _stateDB, ImportRequirements::Everything & ~ImportRequirements::ValidSeal & ~ImportRequirements::CheckUncles);
fresh += r.liveBlocks; fresh += r.liveBlocks;
dead += r.deadBlocks; dead += r.deadBlocks;
goodTransactions += r.goodTranactions; goodTransactions += r.goodTranactions;

9
libethereum/BlockChain.h

@ -118,12 +118,12 @@ public:
/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB. /// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB.
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
std::pair<ImportResult, ImportRoute> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default) noexcept; std::pair<ImportResult, ImportRoute> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything) noexcept;
/// Import block into disk-backed DB /// Import block into disk-backed DB
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
ImportRoute import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default); ImportRoute import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything);
ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir = ImportRequirements::Default); ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir = ImportRequirements::Everything);
/// Returns true if the given block is known (though not necessarily a part of the canon chain). /// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 const& _hash) const; bool isKnown(h256 const& _hash) const;
@ -391,7 +391,8 @@ public:
{ {
BlockHeader h(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce); BlockHeader h(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce);
h.verifyInternals(_block); h.verifyInternals(_block);
h.verifyParent(header(h.parentHash())); if ((_ir & ImportRequirements::Parent) != 0)
h.verifyParent(header(h.parentHash()));
res.info = static_cast<BlockInfo&>(h); res.info = static_cast<BlockInfo&>(h);
} }
catch (Exception& ex) catch (Exception& ex)

2
libethereum/BlockQueue.cpp

@ -110,7 +110,7 @@ void BlockQueue::verifierBody()
swap(work.block, res.blockData); swap(work.block, res.blockData);
try try
{ {
res.verified = m_bc->verifyBlock(&res.blockData, m_onBad, CheckEverything); res.verified = m_bc->verifyBlock(&res.blockData, m_onBad, ImportRequirements::Everything & ~ImportRequirements::Parent);
} }
catch (...) catch (...)
{ {

3
libethereum/Client.cpp

@ -84,10 +84,9 @@ void Client::init(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _
// TODO: consider returning the upgrade mechanism here. will delaying the opening of the blockchain database // TODO: consider returning the upgrade mechanism here. will delaying the opening of the blockchain database
// until after the construction. // until after the construction.
m_stateDB = State::openDB(_dbPath, bc().genesisHash(), _forceAction); m_stateDB = State::openDB(_dbPath, bc().genesisHash(), _forceAction);
m_preMine = State(m_stateDB);
m_postMine = State(m_stateDB);
// LAZY. TODO: move genesis state construction/commiting to stateDB openning and have this just take the root from the genesis block. // LAZY. TODO: move genesis state construction/commiting to stateDB openning and have this just take the root from the genesis block.
m_preMine = bc().genesisState(m_stateDB); m_preMine = bc().genesisState(m_stateDB);
m_postMine = m_preMine;
m_bq.setChain(bc()); m_bq.setChain(bc());

6
libethereum/Client.h

@ -77,7 +77,7 @@ std::ostream& operator<<(std::ostream& _out, ActivityReport const& _r);
* @brief Main API hub for interfacing with Ethereum. * @brief Main API hub for interfacing with Ethereum.
* Not to be used directly - subclass. * Not to be used directly - subclass.
*/ */
class Client: public ClientBase, Worker class Client: public ClientBase, protected Worker
{ {
public: public:
/// New-style Constructor. /// New-style Constructor.
@ -342,6 +342,8 @@ public:
init(_host, _dbPath, _forceAction, _networkId); init(_host, _dbPath, _forceAction, _networkId);
} }
virtual ~SpecialisedClient() { stopWorking(); }
/// Get the object representing the current canonical blockchain. /// Get the object representing the current canonical blockchain.
CanonBlockChain<Sealer> const& blockChain() const { return m_bc; } CanonBlockChain<Sealer> const& blockChain() const { return m_bc; }
@ -365,6 +367,8 @@ public:
u256 _networkId = 0 u256 _networkId = 0
): SpecialisedClient<Ethash>(_host, _gpForAdoption, _dbPath, _forceAction, _networkId) {} ): SpecialisedClient<Ethash>(_host, _gpForAdoption, _dbPath, _forceAction, _networkId) {}
virtual ~EthashClient() { stopWorking(); }
/// Update to the latest transactions and get hash of the current block to be mined minus the /// Update to the latest transactions and get hash of the current block to be mined minus the
/// nonce (the 'work hash') and the difficulty to be met. /// nonce (the 'work hash') and the difficulty to be met.
virtual std::tuple<h256, h256, h256> getEthashWork() override; virtual std::tuple<h256, h256, h256> getEthashWork() override;

3
libtestutils/BlockChainLoader.cpp

@ -19,6 +19,7 @@
* @date 2015 * @date 2015
*/ */
#include <libethereum/CanonBlockChain.h>
#include "BlockChainLoader.h" #include "BlockChainLoader.h"
#include "StateLoader.h" #include "StateLoader.h"
#include "Common.h" #include "Common.h"
@ -35,7 +36,7 @@ BlockChainLoader::BlockChainLoader(Json::Value const& _json)
m_state = sl.state(); m_state = sl.state();
// load genesisBlock // load genesisBlock
m_bc.reset(new BlockChain(fromHex(_json["genesisRLP"].asString()), m_dir.path(), WithExisting::Kill)); m_bc.reset(new FullBlockChain<Ethash>(fromHex(_json["genesisRLP"].asString()), sl.stateDefinition(), m_dir.path(), WithExisting::Kill));
assert(m_state.rootHash() == m_bc->info().stateRoot()); assert(m_state.rootHash() == m_bc->info().stateRoot());
// load blocks // load blocks

2
libtestutils/StateLoader.cpp

@ -27,7 +27,7 @@ using namespace dev::eth;
using namespace dev::test; using namespace dev::test;
StateLoader::StateLoader(Json::Value const& _json, std::string const& _dbPath): StateLoader::StateLoader(Json::Value const& _json, std::string const& _dbPath):
m_state(State::openDB(_dbPath, WithExisting::Kill), BaseState::Empty) m_state(State::openDB(_dbPath, h256{}, WithExisting::Kill), BaseState::Empty)
{ {
for (string const& name: _json.getMemberNames()) for (string const& name: _json.getMemberNames())
{ {

2
libtestutils/StateLoader.h

@ -24,6 +24,7 @@
#include <json/json.h> #include <json/json.h>
#include <libdevcore/TransientDirectory.h> #include <libdevcore/TransientDirectory.h>
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libethereum/BlockChain.h>
namespace dev namespace dev
{ {
@ -38,6 +39,7 @@ class StateLoader
public: public:
StateLoader(Json::Value const& _json, std::string const& _dbPath); StateLoader(Json::Value const& _json, std::string const& _dbPath);
eth::State const& state() const { return m_state; } eth::State const& state() const { return m_state; }
eth::StateDefinition const& stateDefinition() const { return m_state.m_cache; }
private: private:
eth::State m_state; eth::State m_state;

8
libweb3jsonrpc/JsonHelper.cpp

@ -93,10 +93,10 @@ Json::Value toJson(dev::eth::BlockInfo const& _bi)
res["miner"] = toJS(_bi.coinbaseAddress()); res["miner"] = toJS(_bi.coinbaseAddress());
res["stateRoot"] = toJS(_bi.stateRoot()); res["stateRoot"] = toJS(_bi.stateRoot());
res["transactionsRoot"] = toJS(_bi.transactionsRoot()); res["transactionsRoot"] = toJS(_bi.transactionsRoot());
res["difficulty"] = toJS(_bi.difficulty); res["difficulty"] = toJS(_bi.difficulty());
res["number"] = toJS(_bi.number()); res["number"] = toJS(_bi.number());
res["gasUsed"] = toJS(_bi.gasUsed); res["gasUsed"] = toJS(_bi.gasUsed());
res["gasLimit"] = toJS(_bi.gasLimit); res["gasLimit"] = toJS(_bi.gasLimit());
res["timestamp"] = toJS(_bi.timestamp()); res["timestamp"] = toJS(_bi.timestamp());
res["extraData"] = toJS(_bi.extraData()); res["extraData"] = toJS(_bi.extraData());
res["logsBloom"] = toJS(_bi.logBloom()); res["logsBloom"] = toJS(_bi.logBloom());
@ -176,7 +176,7 @@ Json::Value toJson(dev::eth::TransactionSkeleton const& _t)
Json::Value toJson(dev::eth::TransactionReceipt const& _t) Json::Value toJson(dev::eth::TransactionReceipt const& _t)
{ {
Json::Value res; Json::Value res;
res["stateRoot"] = toJS(_t.stateRoot()()); res["stateRoot"] = toJS(_t.stateRoot());
res["gasUsed"] = toJS(_t.gasUsed()); res["gasUsed"] = toJS(_t.gasUsed());
res["bloom"] = toJS(_t.bloom()); res["bloom"] = toJS(_t.bloom());
res["log"] = dev::toJson(_t.log()); res["log"] = dev::toJson(_t.log());

2
libweb3jsonrpc/WebThreeStubServer.cpp

@ -106,7 +106,7 @@ bool WebThreeStubServer::admin_eth_setBidPrice(std::string const& _wei, std::str
return true; return true;
} }
dev::eth::CanonBlockChain const& WebThreeStubServer::bc() const dev::eth::BlockChain const& WebThreeStubServer::bc() const
{ {
return m_web3.ethereum()->blockChain(); return m_web3.ethereum()->blockChain();
} }

4
libweb3jsonrpc/WebThreeStubServer.h

@ -34,7 +34,7 @@ namespace eth
{ {
class KeyManager; class KeyManager;
class TrivialGasPricer; class TrivialGasPricer;
class CanonBlockChain; class BlockChain;
class BlockQueue; class BlockQueue;
} }
@ -89,7 +89,7 @@ private:
private: private:
h256 blockHash(std::string const& _blockNumberOrHash) const; h256 blockHash(std::string const& _blockNumberOrHash) const;
dev::eth::CanonBlockChain const& bc() const; dev::eth::BlockChain const& bc() const;
dev::eth::BlockQueue const& bq() const; dev::eth::BlockQueue const& bq() const;
dev::WebThreeDirect& m_web3; dev::WebThreeDirect& m_web3;

2
libwebthree/WebThree.cpp

@ -52,7 +52,7 @@ WebThreeDirect::WebThreeDirect(
Defaults::setDBPath(_dbPath); Defaults::setDBPath(_dbPath);
if (_interfaces.count("eth")) if (_interfaces.count("eth"))
{ {
m_ethereum.reset(new eth::Client(&m_net, _dbPath, _we, 0)); m_ethereum.reset(new eth::EthashClient(&m_net, shared_ptr<GasPricer>(), _dbPath, _we, 0));
m_ethereum->setExtraData(rlpList(0, _clientVersion, m_net.id())); m_ethereum->setExtraData(rlpList(0, _clientVersion, m_net.id()));
} }

4
mix/ClientModel.cpp

@ -686,9 +686,9 @@ RecordLogEntry* ClientModel::lastBlock() const
{ {
eth::BlockInfo blockInfo = m_client->blockInfo(); eth::BlockInfo blockInfo = m_client->blockInfo();
stringstream strGas; stringstream strGas;
strGas << blockInfo.gasUsed; strGas << blockInfo.gasUsed();
stringstream strNumber; stringstream strNumber;
strNumber << blockInfo.number; strNumber << blockInfo.number();
RecordLogEntry* record = new RecordLogEntry(0, QString::fromStdString(strNumber.str()), tr(" - Block - "), tr("Hash: ") + QString(QString::fromStdString(dev::toHex(blockInfo.hash().ref()))), QString(), QString(), QString(), false, RecordLogEntry::RecordType::Block, QString::fromStdString(strGas.str()), QString(), tr("Block"), QVariantMap(), QVariantMap(), QVariantList()); RecordLogEntry* record = new RecordLogEntry(0, QString::fromStdString(strNumber.str()), tr(" - Block - "), tr("Hash: ") + QString(QString::fromStdString(dev::toHex(blockInfo.hash().ref()))), QString(), QString(), QString(), false, RecordLogEntry::RecordType::Block, QString::fromStdString(strGas.str()), QString(), tr("Block"), QVariantMap(), QVariantMap(), QVariantList());
QQmlEngine::setObjectOwnership(record, QQmlEngine::JavaScriptOwnership); QQmlEngine::setObjectOwnership(record, QQmlEngine::JavaScriptOwnership);
return record; return record;

36
mix/MixClient.cpp

@ -24,12 +24,13 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include <libethcore/Params.h>
#include <libethcore/BasicAuthority.h>
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include <libethereum/Transaction.h> #include <libethereum/Transaction.h>
#include <libethereum/Executive.h> #include <libethereum/Executive.h>
#include <libethereum/ExtVM.h> #include <libethereum/ExtVM.h>
#include <libethereum/BlockChain.h> #include <libethereum/BlockChain.h>
#include <libethcore/Params.h>
#include <libevm/VM.h> #include <libevm/VM.h>
#include "Exceptions.h" #include "Exceptions.h"
using namespace std; using namespace std;
@ -45,22 +46,20 @@ u256 const c_mixGenesisDifficulty = 131072; //TODO: make it lower for Mix someho
namespace namespace
{ {
}
struct MixPow //dummy POW MixBlockChain::MixBlockChain(std::string const& _path, h256 _stateRoot):
FullBlockChain<NoProof>(createGenesisBlock(_stateRoot), std::unordered_map<Address, Account>(), _path, WithExisting::Kill)
{ {
typedef int Solution;
static bool verify(BlockInfo const&) { return true; }
};
} }
bytes MixBlockChain::createGenesisBlock(h256 _stateRoot) bytes MixBlockChain::createGenesisBlock(h256 _stateRoot)
{ {
RLPStream block(3); RLPStream block(3);
block.appendList(15) block.appendList(13)
<< h256() << EmptyListSHA3 << h160() << _stateRoot << EmptyTrie << EmptyTrie << h256() << EmptyListSHA3 << h160() << _stateRoot << EmptyTrie << EmptyTrie
<< LogBloom() << c_mixGenesisDifficulty << 0 << c_genesisGasLimit << 0 << (unsigned)0 << LogBloom() << c_mixGenesisDifficulty << 0 << c_genesisGasLimit << 0 << (unsigned)0
<< std::string() << h256() << h64(u64(42)); << std::string();
block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList);
block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList);
return block.out(); return block.out();
@ -78,7 +77,6 @@ MixClient::~MixClient()
void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner) void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner)
{ {
WriteGuard l(x_state); WriteGuard l(x_state);
Guard fl(x_filtersWatches); Guard fl(x_filtersWatches);
@ -91,12 +89,13 @@ void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts
SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB);
accountState.init(); accountState.init();
dev::eth::commit(_accounts, static_cast<MemoryDB&>(m_stateDB), accountState); dev::eth::commit(_accounts, accountState);
h256 stateRoot = accountState.root(); h256 stateRoot = accountState.root();
m_bc.reset(); m_bc.reset();
m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot));
m_state = eth::State(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); State s(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address());
m_state.sync(bc()); s.sync(bc());
m_state = s;
m_startState = m_state; m_startState = m_state;
WriteGuard lx(x_executions); WriteGuard lx(x_executions);
m_executions.clear(); m_executions.clear();
@ -275,11 +274,14 @@ void MixClient::mine()
{ {
WriteGuard l(x_state); WriteGuard l(x_state);
m_state.commitToMine(bc()); m_state.commitToMine(bc());
m_state.completeMine<MixPow>(0);
bc().import(m_state.blockData(), m_state.db(), ImportRequirements::Default & ~ImportRequirements::ValidNonce); NoProof::BlockHeader h(m_state.info());
RLPStream header;
h.streamRLP(header);
m_state.sealBlock(header.out());
bc().import(m_state.blockData(), m_state.db(), ImportRequirements::Everything & ~ImportRequirements::ValidSeal);
m_state.sync(bc()); m_state.sync(bc());
m_startState = m_state; m_startState = m_state;
h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };
} }
ExecutionResult MixClient::lastExecution() const ExecutionResult MixClient::lastExecution() const
@ -383,9 +385,9 @@ uint64_t MixClient::hashrate() const
return 0; return 0;
} }
eth::MiningProgress MixClient::miningProgress() const eth::WorkingProgress MixClient::miningProgress() const
{ {
return eth::MiningProgress(); return eth::WorkingProgress();
} }
} }

36
mix/MixClient.h

@ -25,6 +25,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <libethcore/BasicAuthority.h>
#include <libethereum/ExtVM.h> #include <libethereum/ExtVM.h>
#include <libethereum/ClientBase.h> #include <libethereum/ClientBase.h>
#include <libethereum/Client.h> #include <libethereum/Client.h>
@ -32,13 +33,40 @@
namespace dev namespace dev
{ {
namespace mix namespace mix
{ {
class MixBlockChain: public dev::eth::BlockChain class NoProof
{
class BlockHeaderRaw: public dev::eth::BlockInfo
{
public:
static const unsigned SealFields = 0;
protected:
BlockHeaderRaw() = default;
BlockHeaderRaw(BlockInfo const& _bi): BlockInfo(_bi) {}
void populateFromHeader(RLP const& _header, dev::eth::Strictness _s) { (void) _header; (void) _s; }
void populateFromParent(BlockHeaderRaw const& _parent) { (void)_parent; }
void streamRLPFields(RLPStream& _s) const { (void) _s; }
};
public:
static std::string name() { return "NoProof"; }
static unsigned revision() { return 0; }
using BlockHeader = dev::eth::BlockHeaderPolished<BlockHeaderRaw>;
private:
static AddressHash s_authorities;
};
class MixBlockChain: public dev::eth::FullBlockChain<NoProof>
{ {
public: public:
MixBlockChain(std::string const& _path, h256 _stateRoot): BlockChain(createGenesisBlock(_stateRoot), _path, WithExisting::Kill) {} MixBlockChain(std::string const& _path, h256 _stateRoot);
static bytes createGenesisBlock(h256 _stateRoot); static bytes createGenesisBlock(h256 _stateRoot);
}; };
@ -67,9 +95,7 @@ public:
void stopMining() override; void stopMining() override;
bool isMining() const override; bool isMining() const override;
uint64_t hashrate() const override; uint64_t hashrate() const override;
eth::MiningProgress miningProgress() const override; eth::WorkingProgress miningProgress() const override;
eth::ProofOfWork::WorkPackage getWork() override { return eth::ProofOfWork::WorkPackage(); }
bool submitWork(eth::ProofOfWork::Solution const&) override { return false; }
virtual void flushTransactions() override {} virtual void flushTransactions() override {}
/// @returns the last mined block information /// @returns the last mined block information

17
test/TestHelper.cpp

@ -23,6 +23,7 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <libethcore/EthashAux.h>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include <liblll/Compiler.h> #include <liblll/Compiler.h>
#include <libevm/VMFactory.h> #include <libevm/VMFactory.h>
@ -63,11 +64,17 @@ void connectClients(Client& c1, Client& c2)
void mine(State& s, BlockChain const& _bc) void mine(State& s, BlockChain const& _bc)
{ {
s.commitToMine(_bc); s.commitToMine(_bc);
GenericFarm<ProofOfWork> f; GenericFarm<EthashProofOfWork> f;
bool completed = false; bool completed = false;
f.onSolutionFound([&](ProofOfWork::Solution sol) Ethash::BlockHeader header(s.info);
f.onSolutionFound([&](EthashProofOfWork::Solution sol)
{ {
return completed = s.completeMine<ProofOfWork>(sol); header.m_mixHash = sol.mixHash;
header.m_nonce = sol.nonce;
RLPStream ret;
header.streamRLP(ret);
s.sealBlock(ret);
return true;
}); });
f.setWork(s.info()); f.setWork(s.info());
f.startCPU(); f.startCPU();
@ -77,9 +84,9 @@ void mine(State& s, BlockChain const& _bc)
void mine(BlockInfo& _bi) void mine(BlockInfo& _bi)
{ {
GenericFarm<ProofOfWork> f; GenericFarm<EthashProofOfWork> f;
bool completed = false; bool completed = false;
f.onSolutionFound([&](ProofOfWork::Solution sol) f.onSolutionFound([&](EthashProofOfWork::Solution sol)
{ {
_bi.proof = sol; _bi.proof = sol;
return completed = true; return completed = true;

10
test/libethcore/dagger.cpp

@ -54,11 +54,11 @@ BOOST_AUTO_TEST_CASE(basic_test)
cnote << i.first; cnote << i.first;
js::mObject& o = i.second.get_obj(); js::mObject& o = i.second.get_obj();
vector<pair<string, string>> ss; vector<pair<string, string>> ss;
BlockInfo header = BlockInfo::fromHeader(fromHex(o["header"].get_str()), CheckNothing); Ethash::BlockHeader header(fromHex(o["header"].get_str()), CheckNothing);
h256 headerHash(o["header_hash"].get_str()); h256 headerHash(o["header_hash"].get_str());
Nonce nonce(o["nonce"].get_str()); Nonce nonce(o["nonce"].get_str());
BOOST_REQUIRE_EQUAL(headerHash, header.headerHash(WithoutNonce)); BOOST_REQUIRE_EQUAL(headerHash, header.hashWithout());
BOOST_REQUIRE_EQUAL(nonce, header.nonce); BOOST_REQUIRE_EQUAL(nonce, header.nonce());
unsigned cacheSize(o["cache_size"].get_int()); unsigned cacheSize(o["cache_size"].get_int());
h256 cacheHash(o["cache_hash"].get_str()); h256 cacheHash(o["cache_hash"].get_str());
@ -73,9 +73,9 @@ BOOST_AUTO_TEST_CASE(basic_test)
#endif #endif
h256 result(o["result"].get_str()); h256 result(o["result"].get_str());
EthashProofOfWork::Result r = EthashAux::eval(header); EthashProofOfWork::Result r = EthashAux::eval(header.seedHash(), header.hashWithout(), header.nonce());
BOOST_REQUIRE_EQUAL(r.value, result); BOOST_REQUIRE_EQUAL(r.value, result);
BOOST_REQUIRE_EQUAL(r.mixHash, header.mixHash); BOOST_REQUIRE_EQUAL(r.mixHash, header.mixHash());
} }
} }

18
test/libethereum/ClientBase.cpp

@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(blocks)
ETH_CHECK_EQUAL(expectedHashFromNumber, hashFromNumber); ETH_CHECK_EQUAL(expectedHashFromNumber, hashFromNumber);
// blockInfo // blockInfo
auto compareBlockInfos = [](Json::Value const& _b, BlockInfo _blockInfo) -> void auto compareBlockInfos = [](Json::Value const& _b, Ethash::BlockHeader _blockInfo) -> void
{ {
LogBloom expectedBlockInfoBloom = LogBloom(fromHex(_b["bloom"].asString())); LogBloom expectedBlockInfoBloom = LogBloom(fromHex(_b["bloom"].asString()));
Address expectedBlockInfoCoinbase = Address(fromHex(_b["coinbase"].asString())); Address expectedBlockInfoCoinbase = Address(fromHex(_b["coinbase"].asString()));
@ -119,27 +119,27 @@ BOOST_AUTO_TEST_CASE(blocks)
h256 expectedBlockInfoUncldeHash = h256(fromHex(_b["uncleHash"].asString())); h256 expectedBlockInfoUncldeHash = h256(fromHex(_b["uncleHash"].asString()));
ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom()); ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom());
ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress()); ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress());
ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty); ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty());
ETH_CHECK_EQUAL_COLLECTIONS( ETH_CHECK_EQUAL_COLLECTIONS(
expectedBlockInfoExtraData.begin(), expectedBlockInfoExtraData.begin(),
expectedBlockInfoExtraData.end(), expectedBlockInfoExtraData.end(),
_blockInfo.extraData().begin(), _blockInfo.extraData().begin(),
_blockInfo.extraData().end() _blockInfo.extraData().end()
); );
ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit); ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit());
ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed); ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed());
ETH_CHECK_EQUAL(expectedBlockInfoHash, _blockInfo.hash()); ETH_CHECK_EQUAL(expectedBlockInfoHash, _blockInfo.hash());
ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash); ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash());
ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce); ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce());
ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number); ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number());
ETH_CHECK_EQUAL(expectedBlockInfoParentHash, _blockInfo.parentHash()); ETH_CHECK_EQUAL(expectedBlockInfoParentHash, _blockInfo.parentHash());
ETH_CHECK_EQUAL(expectedBlockInfoReceiptsRoot, _blockInfo..receiptsRoot()); ETH_CHECK_EQUAL(expectedBlockInfoReceiptsRoot, _blockInfo.receiptsRoot());
ETH_CHECK_EQUAL(expectedBlockInfoTimestamp, _blockInfo.timestamp()); ETH_CHECK_EQUAL(expectedBlockInfoTimestamp, _blockInfo.timestamp());
ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot()); ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot());
ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles()); ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles());
}; };
BlockInfo blockInfo = _client.blockInfo(blockHash); Ethash::BlockHeader blockInfo(_client.bc().headerData(blockHash));
compareBlockInfos(blockHeader, blockInfo); compareBlockInfos(blockHeader, blockInfo);
// blockDetails // blockDetails

3
test/libethereum/gaspricer.cpp

@ -20,6 +20,7 @@
*/ */
#include <libtestutils/BlockChainLoader.h> #include <libtestutils/BlockChainLoader.h>
#include <libethcore/Ethash.h>
#include <libethereum/BlockChain.h> #include <libethereum/BlockChain.h>
#include <libethereum/GasPricer.h> #include <libethereum/GasPricer.h>
#include <libethereum/BasicGasPricer.h> #include <libethereum/BasicGasPricer.h>
@ -54,7 +55,7 @@ BOOST_AUTO_TEST_CASE(trivialGasPricer)
std::shared_ptr<dev::eth::GasPricer> gp(new TrivialGasPricer); std::shared_ptr<dev::eth::GasPricer> gp(new TrivialGasPricer);
BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo); BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo);
BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo); BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo);
gp->update(BlockChain(bytes(), TransientDirectory().path(), WithExisting::Kill)); gp->update(FullBlockChain<Ethash>(bytes(), StateDefinition(), TransientDirectory().path(), WithExisting::Kill));
BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo); BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo);
BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo); BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo);
} }

6
test/libethereum/genesis.cpp

@ -60,9 +60,9 @@ BOOST_AUTO_TEST_CASE(genesis_tests)
js::mObject o = v.get_obj(); js::mObject o = v.get_obj();
BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot(), h256(o["genesis_state_root"].get_str())); BOOST_CHECK_EQUAL(CanonBlockChain<Ethash>::genesis().stateRoot(), h256(o["genesis_state_root"].get_str()));
BOOST_CHECK_EQUAL(toHex(CanonBlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); BOOST_CHECK_EQUAL(toHex(CanonBlockChain<Ethash>::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str())));
BOOST_CHECK_EQUAL(BlockInfo::headerHash(CanonBlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); BOOST_CHECK_EQUAL(Ethash::BlockHeader(CanonBlockChain<Ethash>::createGenesisBlock()).hashWithout(), h256(o["genesis_hash"].get_str()));
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

5
test/libethereum/stateOriginal.cpp

@ -25,6 +25,7 @@
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libethcore/Farm.h> #include <libethcore/Farm.h>
#include <libethcore/BasicAuthority.h>
#include <libethereum/Defaults.h> #include <libethereum/Defaults.h>
#include <test/TestHelper.h> #include <test/TestHelper.h>
@ -59,8 +60,8 @@ BOOST_AUTO_TEST_CASE(Complex)
Defaults::setDBPath(boost::filesystem::temp_directory_path().string() + "/" + toString(chrono::system_clock::now().time_since_epoch().count())); Defaults::setDBPath(boost::filesystem::temp_directory_path().string() + "/" + toString(chrono::system_clock::now().time_since_epoch().count()));
OverlayDB stateDB = State::openDB(); OverlayDB stateDB = State::openDB(h256());
CanonBlockChain bc; CanonBlockChain<BasicAuthority> bc;
cout << bc; cout << bc;
State s = bc.genesisState(stateDB); State s = bc.genesisState(stateDB);

10
test/libevm/vm.cpp

@ -33,7 +33,7 @@ using namespace dev::eth;
using namespace dev::test; using namespace dev::test;
FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix. FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix.
ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), EmptySHA3, _previousBlock, _currentBlock, test::lastHashes(_currentBlock.number), _depth) {} ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), EmptySHA3, _previousBlock, _currentBlock, test::lastHashes(_currentBlock.number()), _depth) {}
h160 FakeExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _init, OnOpFunc const&) h160 FakeExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _init, OnOpFunc const&)
{ {
@ -84,11 +84,11 @@ mObject FakeExtVM::exportEnv()
{ {
mObject ret; mObject ret;
ret["previousHash"] = toString(currentBlock.parentHash()); ret["previousHash"] = toString(currentBlock.parentHash());
ret["currentDifficulty"] = toCompactHex(currentBlock.difficulty, HexPrefix::Add, 1); ret["currentDifficulty"] = toCompactHex(currentBlock.difficulty(), HexPrefix::Add, 1);
ret["currentTimestamp"] = toCompactHex(currentBlock.timestamp(), HexPrefix::Add, 1); ret["currentTimestamp"] = toCompactHex(currentBlock.timestamp(), HexPrefix::Add, 1);
ret["currentCoinbase"] = toString(currentBlock.coinbaseAddress()); ret["currentCoinbase"] = toString(currentBlock.coinbaseAddress());
ret["currentNumber"] = toCompactHex(currentBlock.number, HexPrefix::Add, 1); ret["currentNumber"] = toCompactHex(currentBlock.number(), HexPrefix::Add, 1);
ret["currentGasLimit"] = toCompactHex(currentBlock.gasLimit, HexPrefix::Add, 1); ret["currentGasLimit"] = toCompactHex(currentBlock.gasLimit(), HexPrefix::Add, 1);
return ret; return ret;
} }
@ -107,7 +107,7 @@ void FakeExtVM::importEnv(mObject& _o)
lastHashes = test::lastHashes(currentBlock.number); lastHashes = test::lastHashes(currentBlock.number);
currentBlock.gasLimit = toInt(_o["currentGasLimit"]); currentBlock.gasLimit = toInt(_o["currentGasLimit"]);
currentBlock.difficulty = toInt(_o["currentDifficulty"]); currentBlock.difficulty = toInt(_o["currentDifficulty"]);
currentBlock.timestamp() = toInt(_o["currentTimestamp"]); currentBlock.timestamp = toInt(_o["currentTimestamp"]);
currentBlock.coinbaseAddress() = Address(_o["currentCoinbase"].get_str()); currentBlock.coinbaseAddress() = Address(_o["currentCoinbase"].get_str());
} }

Loading…
Cancel
Save