Browse Source

eth working

cl-refactor
arkpar 9 years ago
parent
commit
9d8f9e3517
  1. 2
      eth/main.cpp
  2. 26
      ethminer/MinerAux.h
  3. 1
      libethcore/BlockInfo.h
  4. 6
      libethereum/Client.h
  5. 17
      test/TestHelper.cpp
  6. 6
      test/libethcore/dagger.cpp
  7. 4
      test/libethereum/ClientBase.cpp
  8. 3
      test/libethereum/gaspricer.cpp
  9. 10
      test/libevm/vm.cpp

2
eth/main.cpp

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

26
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<EthashProofOfWork> 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<uint64_t, MiningProgress> results;
map<uint64_t, WorkingProgress> 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<EthashProofOfWork> 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;

1
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; }

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.
* 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<Sealer> const& blockChain() const { return m_bc; }
@ -365,6 +367,8 @@ public:
u256 _networkId = 0
): 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
/// nonce (the 'work hash') and the difficulty to be met.
virtual std::tuple<h256, h256, h256> getEthashWork() override;

17
test/TestHelper.cpp

@ -23,6 +23,7 @@
#include <thread>
#include <chrono>
#include <libethcore/EthashAux.h>
#include <libethereum/Client.h>
#include <liblll/Compiler.h>
#include <libevm/VMFactory.h>
@ -63,11 +64,17 @@ void connectClients(Client& c1, Client& c2)
void mine(State& s, BlockChain const& _bc)
{
s.commitToMine(_bc);
GenericFarm<Ethash> f;
GenericFarm<EthashProofOfWork> f;
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.startCPU();
@ -77,9 +84,9 @@ void mine(State& s, BlockChain const& _bc)
void mine(BlockInfo& _bi)
{
GenericFarm<ProofOfWork> f;
GenericFarm<EthashProofOfWork> f;
bool completed = false;
f.onSolutionFound([&](ProofOfWork::Solution sol)
f.onSolutionFound([&](EthashProofOfWork::Solution sol)
{
_bi.proof = sol;
return completed = true;

6
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());
}
}

4
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

3
test/libethereum/gaspricer.cpp

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

10
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());
}

Loading…
Cancel
Save