diff --git a/eth/main.cpp b/eth/main.cpp index 8bbec9f00..4a8501a97 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1311,7 +1311,7 @@ int main(int argc, char** argv) { try { - CanonBlockChain::setGenesisNonce(Nonce(argv[++i])); + CanonBlockChain::setGenesisNonce(Nonce(argv[++i])); } catch (...) { diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 0d227b1ef..01083012f 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -397,17 +397,16 @@ public: private: void doInitDAG(unsigned _n) { - BlockInfo bi; - bi.number() = _n; - cout << "Initializing DAG for epoch beginning #" << (bi.number() / 30000 * 30000) << " (seedhash " << bi.proofCache().abridged() << "). This will take a while." << endl; - Ethash::prep(bi); + h256 seedHash = EthashAux::seedHash(_n); + cout << "Initializing DAG for epoch beginning #" << (_n / 30000 * 30000) << " (seedhash " << seedHash.abridged() << "). This will take a while." << endl; + EthashAux::full(seedHash, true); exit(0); } void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5) { - BlockInfo genesis; - genesis.difficulty = 1 << 18; + Ethash::BlockHeader genesis; + genesis.setDifficulty(1 << 18); cdebug << genesis.boundary(); GenericFarm f; @@ -417,17 +416,16 @@ private: cout << "Benchmarking on platform: " << platformInfo << endl; cout << "Preparing DAG..." << endl; - Ethash::prep(genesis); + genesis.prep(); - genesis.difficulty = u256(1) << 63; - genesis.noteDirty(); + genesis.setDifficulty(u256(1) << 63); f.setWork(genesis); if (_m == MinerType::CPU) - f.startCPU(); + f.start("cpu"); else if (_m == MinerType::GPU) - f.startGPU(); + f.start("opencl"); - map results; + map results; uint64_t mean = 0; uint64_t innerMean = 0; for (unsigned i = 0; i <= _trials; ++i) @@ -488,9 +486,9 @@ private: Farm rpc(client); GenericFarm f; if (_m == MinerType::CPU) - f.startCPU(); + f.start("cpu"); else if (_m == MinerType::GPU) - f.startGPU(); + f.start("opencl"); EthashProofOfWork::WorkPackage current; EthashAux::FullType dag; diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index 67a5397f4..c310b3dd9 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -128,6 +128,7 @@ public: void setGasUsed(u256 const& _v) { m_gasUsed = _v; noteDirty(); } void setExtraData(bytes const& _v) { m_extraData = _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; } h256 const& stateRoot() const { return m_stateRoot; } diff --git a/libethereum/Client.h b/libethereum/Client.h index 73609bd71..4523d324b 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -77,7 +77,7 @@ std::ostream& operator<<(std::ostream& _out, ActivityReport const& _r); * @brief Main API hub for interfacing with Ethereum. * Not to be used directly - subclass. */ -class Client: public ClientBase, Worker +class Client: public ClientBase, protected Worker { public: /// New-style Constructor. @@ -342,6 +342,8 @@ public: init(_host, _dbPath, _forceAction, _networkId); } + virtual ~SpecialisedClient() { stopWorking(); } + /// Get the object representing the current canonical blockchain. CanonBlockChain const& blockChain() const { return m_bc; } @@ -365,6 +367,8 @@ public: u256 _networkId = 0 ): SpecialisedClient(_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 /// nonce (the 'work hash') and the difficulty to be met. virtual std::tuple getEthashWork() override; diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index 30f323369..c29788b9f 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -63,11 +64,17 @@ void connectClients(Client& c1, Client& c2) void mine(State& s, BlockChain const& _bc) { s.commitToMine(_bc); - GenericFarm f; + GenericFarm f; bool completed = false; - f.onSolutionFound([&](ProofOfWork::Solution sol) + Ethash::BlockHeader header(s.info); + f.onSolutionFound([&](EthashProofOfWork::Solution sol) { - return completed = s.completeMine(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.startCPU(); @@ -77,9 +84,9 @@ void mine(State& s, BlockChain const& _bc) void mine(BlockInfo& _bi) { - GenericFarm f; + GenericFarm f; bool completed = false; - f.onSolutionFound([&](ProofOfWork::Solution sol) + f.onSolutionFound([&](EthashProofOfWork::Solution sol) { _bi.proof = sol; return completed = true; diff --git a/test/libethcore/dagger.cpp b/test/libethcore/dagger.cpp index 8d4cba933..c3cd75b0d 100644 --- a/test/libethcore/dagger.cpp +++ b/test/libethcore/dagger.cpp @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(basic_test) h256 headerHash(o["header_hash"].get_str()); Nonce nonce(o["nonce"].get_str()); 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()); h256 cacheHash(o["cache_hash"].get_str()); @@ -73,9 +73,9 @@ BOOST_AUTO_TEST_CASE(basic_test) #endif 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.mixHash, header.mixHash); + BOOST_REQUIRE_EQUAL(r.mixHash, header.mixHash()); } } diff --git a/test/libethereum/ClientBase.cpp b/test/libethereum/ClientBase.cpp index a426ff53f..f9d83e9c6 100644 --- a/test/libethereum/ClientBase.cpp +++ b/test/libethereum/ClientBase.cpp @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(blocks) ETH_CHECK_EQUAL(expectedHashFromNumber, hashFromNumber); // 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())); Address expectedBlockInfoCoinbase = Address(fromHex(_b["coinbase"].asString())); @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(blocks) ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles()); }; - BlockInfo blockInfo = _client.blockInfo(blockHash); + Ethash::BlockHeader blockInfo(_client.bc().headerData(blockHash)); compareBlockInfos(blockHeader, blockInfo); // blockDetails diff --git a/test/libethereum/gaspricer.cpp b/test/libethereum/gaspricer.cpp index ce49a4a20..050ab2d25 100644 --- a/test/libethereum/gaspricer.cpp +++ b/test/libethereum/gaspricer.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include #include @@ -54,7 +55,7 @@ BOOST_AUTO_TEST_CASE(trivialGasPricer) std::shared_ptr gp(new TrivialGasPricer); BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo); BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo); - gp->update(BlockChain(bytes(), TransientDirectory().path(), WithExisting::Kill)); + gp->update(FullBlockChain(bytes(), StateDefinition(), TransientDirectory().path(), WithExisting::Kill)); BOOST_CHECK_EQUAL(gp->ask(State()), 10 * szabo); BOOST_CHECK_EQUAL(gp->bid(), 10 * szabo); } diff --git a/test/libevm/vm.cpp b/test/libevm/vm.cpp index 28b2e43ab..badabd70c 100644 --- a/test/libevm/vm.cpp +++ b/test/libevm/vm.cpp @@ -33,7 +33,7 @@ using namespace dev::eth; using namespace dev::test; 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&) { @@ -84,11 +84,11 @@ mObject FakeExtVM::exportEnv() { mObject ret; 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["currentCoinbase"] = toString(currentBlock.coinbaseAddress()); - ret["currentNumber"] = toCompactHex(currentBlock.number, HexPrefix::Add, 1); - ret["currentGasLimit"] = toCompactHex(currentBlock.gasLimit, HexPrefix::Add, 1); + ret["currentNumber"] = toCompactHex(currentBlock.number(), HexPrefix::Add, 1); + ret["currentGasLimit"] = toCompactHex(currentBlock.gasLimit(), HexPrefix::Add, 1); return ret; } @@ -107,7 +107,7 @@ void FakeExtVM::importEnv(mObject& _o) lastHashes = test::lastHashes(currentBlock.number); currentBlock.gasLimit = toInt(_o["currentGasLimit"]); currentBlock.difficulty = toInt(_o["currentDifficulty"]); - currentBlock.timestamp() = toInt(_o["currentTimestamp"]); + currentBlock.timestamp = toInt(_o["currentTimestamp"]); currentBlock.coinbaseAddress() = Address(_o["currentCoinbase"].get_str()); }