From bc9ad046e314a16cd09d99b2730c7ed808718f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 30 May 2017 20:14:39 +0200 Subject: [PATCH 1/4] De-template Miner and Farm classes --- ethminer/MinerAux.h | 32 +++++++++++++++---------------- libethcore/EthashCUDAMiner.cpp | 2 +- libethcore/EthashCUDAMiner.h | 4 ++-- libethcore/EthashGPUMiner.cpp | 2 +- libethcore/EthashGPUMiner.h | 4 ++-- libethcore/Farm.h | 9 ++++----- libethcore/Miner.cpp | 12 ++++-------- libethcore/Miner.h | 23 +++++++++++----------- libstratum/EthStratumClient.cpp | 2 +- libstratum/EthStratumClient.h | 4 ++-- libstratum/EthStratumClientV2.cpp | 2 +- libstratum/EthStratumClientV2.h | 4 ++-- 12 files changed, 47 insertions(+), 53 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index f6c28cf89..dbb7ea34b 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -604,13 +604,13 @@ private: genesis.setDifficulty(1 << 18); cdebug << genesis.boundary(); - GenericFarm f; - map::SealerDescriptor> sealers; + GenericFarm f; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; + sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif f.setSealers(sealers); f.onSolutionFound([&](EthashProofOfWork::Solution) { return false; }); @@ -670,13 +670,13 @@ private: genesis.setDifficulty(1 << 18); cdebug << genesis.boundary(); - GenericFarm f; - map::SealerDescriptor> sealers; + GenericFarm f; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; + sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif f.setSealers(sealers); @@ -750,12 +750,12 @@ private: void doFarm(MinerType _m, string & _remote, unsigned _recheckPeriod) { - map::SealerDescriptor> sealers; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; + sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif (void)_m; (void)_remote; @@ -768,7 +768,7 @@ private: FarmClient * prpc = &rpc; h256 id = h256::random(); - GenericFarm f; + GenericFarm f; f.setSealers(sealers); if (_m == MinerType::CPU) f.start("cpu", false); @@ -902,17 +902,17 @@ private: #if ETH_STRATUM void doStratum() { - map::SealerDescriptor> sealers; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; + sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif if (!m_farmRecheckSet) m_farmRecheckPeriod = m_defaultStratumFarmRecheckPeriod; - GenericFarm f; + GenericFarm f; // this is very ugly, but if Stratum Client V2 tunrs out to be a success, V1 will be completely removed anyway if (m_stratumClientVersion == 1) { diff --git a/libethcore/EthashCUDAMiner.cpp b/libethcore/EthashCUDAMiner.cpp index 359b7b45f..0721d8302 100644 --- a/libethcore/EthashCUDAMiner.cpp +++ b/libethcore/EthashCUDAMiner.cpp @@ -108,7 +108,7 @@ unsigned EthashCUDAMiner::s_numInstances = 0; int EthashCUDAMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) : - GenericMiner(_ci), + GenericMiner(_ci), Worker("cudaminer" + toString(index())), m_hook( new EthashCUDAHook(this)) { diff --git a/libethcore/EthashCUDAMiner.h b/libethcore/EthashCUDAMiner.h index e5217d8b6..4d53c5d33 100644 --- a/libethcore/EthashCUDAMiner.h +++ b/libethcore/EthashCUDAMiner.h @@ -36,7 +36,7 @@ namespace eth { class EthashCUDAHook; - class EthashCUDAMiner : public GenericMiner, Worker + class EthashCUDAMiner : public GenericMiner, Worker { friend class dev::eth::EthashCUDAHook; @@ -80,7 +80,7 @@ class EthashCUDAHook; void workLoop() override; bool report(uint64_t _nonce); - using GenericMiner::accumulateHashes; + using GenericMiner::accumulateHashes; EthashCUDAHook* m_hook = nullptr; ethash_cuda_miner* m_miner = nullptr; diff --git a/libethcore/EthashGPUMiner.cpp b/libethcore/EthashGPUMiner.cpp index e9376f854..e991d8898 100644 --- a/libethcore/EthashGPUMiner.cpp +++ b/libethcore/EthashGPUMiner.cpp @@ -107,7 +107,7 @@ unsigned EthashGPUMiner::s_numInstances = 0; int EthashGPUMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; EthashGPUMiner::EthashGPUMiner(ConstructionInfo const& _ci): - GenericMiner(_ci), + GenericMiner(_ci), Worker("openclminer" + toString(index())), m_hook(new EthashCLHook(this)) { diff --git a/libethcore/EthashGPUMiner.h b/libethcore/EthashGPUMiner.h index 6e39bb747..f5fb7e084 100644 --- a/libethcore/EthashGPUMiner.h +++ b/libethcore/EthashGPUMiner.h @@ -36,7 +36,7 @@ namespace eth { class EthashCLHook; -class EthashGPUMiner: public GenericMiner, Worker +class EthashGPUMiner: public GenericMiner, Worker { friend class dev::eth::EthashCLHook; @@ -76,7 +76,7 @@ private: void workLoop() override; bool report(uint64_t _nonce); - using GenericMiner::accumulateHashes; + using GenericMiner::accumulateHashes; EthashCLHook* m_hook = nullptr; ethash_cl_miner* m_miner = nullptr; diff --git a/libethcore/Farm.h b/libethcore/Farm.h index 087a4e99f..c02a6629d 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -41,13 +41,12 @@ namespace eth * Miners ask for work, then submit proofs * @threadsafe */ -template -class GenericFarm: public GenericFarmFace +class GenericFarm: public GenericFarmFace { public: - using WorkPackage = typename PoW::WorkPackage; - using Solution = typename PoW::Solution; - using Miner = GenericMiner; + using WorkPackage = EthashProofOfWork::WorkPackage; + using Solution = EthashProofOfWork::Solution; + using Miner = GenericMiner; struct SealerDescriptor { diff --git a/libethcore/Miner.cpp b/libethcore/Miner.cpp index c182d8456..e15746e97 100644 --- a/libethcore/Miner.cpp +++ b/libethcore/Miner.cpp @@ -4,16 +4,12 @@ using namespace dev; using namespace eth; -template <> -unsigned dev::eth::GenericMiner::s_dagLoadMode = 0; +unsigned dev::eth::GenericMiner::s_dagLoadMode = 0; -template <> -volatile unsigned dev::eth::GenericMiner::s_dagLoadIndex = 0; +volatile unsigned dev::eth::GenericMiner::s_dagLoadIndex = 0; -template <> -unsigned dev::eth::GenericMiner::s_dagCreateDevice = 0; +unsigned dev::eth::GenericMiner::s_dagCreateDevice = 0; -template <> -volatile void* dev::eth::GenericMiner::s_dagInHostMemory = NULL; +volatile void* dev::eth::GenericMiner::s_dagInHostMemory = NULL; diff --git a/libethcore/Miner.h b/libethcore/Miner.h index 126d3c430..5c9d77833 100644 --- a/libethcore/Miner.h +++ b/libethcore/Miner.h @@ -30,6 +30,7 @@ #include #include #include +#include "EthashAux.h" #define MINER_WAIT_STATE_UNKNOWN 0 #define MINER_WAIT_STATE_WORK 1 @@ -67,8 +68,6 @@ enum class MinerType Mixed }; -struct MineInfo: public WorkingProgress {}; - inline std::ostream& operator<<(std::ostream& _out, WorkingProgress _p) { float mh = _p.rate() / 1000000.0f; @@ -109,7 +108,7 @@ inline std::ostream& operator<<(std::ostream& os, SolutionStats s) return os << "[A" << s.getAccepts() << "+" << s.getAcceptedStales() << ":R" << s.getRejects() << "+" << s.getRejectedStales() << ":F" << s.getFailures() << "]"; } -template class GenericMiner; +class GenericMiner; /** @@ -117,14 +116,14 @@ template class GenericMiner; * @warning Must be implemented in a threadsafe manner since it will be called from multiple * miner threads. */ -template class GenericFarmFace +class GenericFarmFace { public: - using WorkPackage = typename PoW::WorkPackage; - using Solution = typename PoW::Solution; - using Miner = GenericMiner; + using WorkPackage = EthashProofOfWork::WorkPackage; + using Solution = EthashProofOfWork::Solution; + using Miner = GenericMiner; - virtual ~GenericFarmFace() {} + virtual ~GenericFarmFace() = default; /** * @brief Called from a Miner to note a WorkPackage has a solution. @@ -140,12 +139,12 @@ public: * @brief A miner - a member and adoptee of the Farm. * @warning Not threadsafe. It is assumed Farm will synchronise calls to/from this class. */ -template class GenericMiner +class GenericMiner { public: - using WorkPackage = typename PoW::WorkPackage; - using Solution = typename PoW::Solution; - using FarmFace = GenericFarmFace; + using WorkPackage = EthashProofOfWork::WorkPackage; + using Solution = EthashProofOfWork::Solution; + using FarmFace = GenericFarmFace; using ConstructionInfo = std::pair; GenericMiner(ConstructionInfo const& _ci): diff --git a/libstratum/EthStratumClient.cpp b/libstratum/EthStratumClient.cpp index e73863e36..d15e29105 100644 --- a/libstratum/EthStratumClient.cpp +++ b/libstratum/EthStratumClient.cpp @@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff) } -EthStratumClient::EthStratumClient(GenericFarm * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) +EthStratumClient::EthStratumClient(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) : m_socket(m_io_service) { m_minerType = m; diff --git a/libstratum/EthStratumClient.h b/libstratum/EthStratumClient.h index 6b4e49bae..b5f33e04b 100644 --- a/libstratum/EthStratumClient.h +++ b/libstratum/EthStratumClient.h @@ -21,7 +21,7 @@ using namespace dev::eth; class EthStratumClient { public: - EthStratumClient(GenericFarm * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); + EthStratumClient(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); ~EthStratumClient(); void setFailover(string const & host, string const & port); @@ -68,7 +68,7 @@ private: std::mutex x_pending; int m_pending; - GenericFarm * p_farm; + GenericFarm* p_farm; std::mutex x_current; EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_previous; diff --git a/libstratum/EthStratumClientV2.cpp b/libstratum/EthStratumClientV2.cpp index acd192fc5..b2548a7e9 100644 --- a/libstratum/EthStratumClientV2.cpp +++ b/libstratum/EthStratumClientV2.cpp @@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff) } -EthStratumClientV2::EthStratumClientV2(GenericFarm * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) +EthStratumClientV2::EthStratumClientV2(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) : Worker("stratum"), m_socket(m_io_service) { diff --git a/libstratum/EthStratumClientV2.h b/libstratum/EthStratumClientV2.h index cb26c9954..24438c893 100644 --- a/libstratum/EthStratumClientV2.h +++ b/libstratum/EthStratumClientV2.h @@ -22,7 +22,7 @@ using namespace dev::eth; class EthStratumClientV2 : public Worker { public: - EthStratumClientV2(GenericFarm * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); + EthStratumClientV2(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); ~EthStratumClientV2(); void setFailover(string const & host, string const & port); @@ -64,7 +64,7 @@ private: string m_response; - GenericFarm * p_farm; + GenericFarm* p_farm; mutex x_current; EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_previous; From a67ce0cf2b52663f8495f98c071a768d37641bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 30 May 2017 20:20:09 +0200 Subject: [PATCH 2/4] Remove Generic name prefix --- ethminer/MinerAux.h | 32 +++++++++++++++---------------- libethcore/EthashCUDAMiner.cpp | 2 +- libethcore/EthashCUDAMiner.h | 4 ++-- libethcore/EthashGPUMiner.cpp | 2 +- libethcore/EthashGPUMiner.h | 4 ++-- libethcore/Farm.h | 7 +++---- libethcore/Miner.cpp | 8 ++++---- libethcore/Miner.h | 14 ++++++-------- libstratum/EthStratumClient.cpp | 2 +- libstratum/EthStratumClient.h | 4 ++-- libstratum/EthStratumClientV2.cpp | 2 +- libstratum/EthStratumClientV2.h | 4 ++-- 12 files changed, 41 insertions(+), 44 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index dbb7ea34b..cdd228c9f 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -604,13 +604,13 @@ private: genesis.setDifficulty(1 << 18); cdebug << genesis.boundary(); - GenericFarm f; - map sealers; + Farm f; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; + sealers["opencl"] = Farm::SealerDescriptor{&EthashGPUMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = Farm::SealerDescriptor{ &EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif f.setSealers(sealers); f.onSolutionFound([&](EthashProofOfWork::Solution) { return false; }); @@ -670,13 +670,13 @@ private: genesis.setDifficulty(1 << 18); cdebug << genesis.boundary(); - GenericFarm f; - map sealers; + Farm f; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; + sealers["opencl"] = Farm::SealerDescriptor{ &EthashGPUMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = Farm::SealerDescriptor{ &EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif f.setSealers(sealers); @@ -750,12 +750,12 @@ private: void doFarm(MinerType _m, string & _remote, unsigned _recheckPeriod) { - map sealers; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; + sealers["opencl"] = Farm::SealerDescriptor{&EthashGPUMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = Farm::SealerDescriptor{ &EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif (void)_m; (void)_remote; @@ -768,7 +768,7 @@ private: FarmClient * prpc = &rpc; h256 id = h256::random(); - GenericFarm f; + Farm f; f.setSealers(sealers); if (_m == MinerType::CPU) f.start("cpu", false); @@ -902,17 +902,17 @@ private: #if ETH_STRATUM void doStratum() { - map sealers; + map sealers; #if ETH_ETHASHCL - sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; + sealers["opencl"] = Farm::SealerDescriptor{ &EthashGPUMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; #endif #if ETH_ETHASHCUDA - sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; + sealers["cuda"] = Farm::SealerDescriptor{ &EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif if (!m_farmRecheckSet) m_farmRecheckPeriod = m_defaultStratumFarmRecheckPeriod; - GenericFarm f; + Farm f; // this is very ugly, but if Stratum Client V2 tunrs out to be a success, V1 will be completely removed anyway if (m_stratumClientVersion == 1) { diff --git a/libethcore/EthashCUDAMiner.cpp b/libethcore/EthashCUDAMiner.cpp index 0721d8302..3f91daf48 100644 --- a/libethcore/EthashCUDAMiner.cpp +++ b/libethcore/EthashCUDAMiner.cpp @@ -108,7 +108,7 @@ unsigned EthashCUDAMiner::s_numInstances = 0; int EthashCUDAMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) : - GenericMiner(_ci), + Miner(_ci), Worker("cudaminer" + toString(index())), m_hook( new EthashCUDAHook(this)) { diff --git a/libethcore/EthashCUDAMiner.h b/libethcore/EthashCUDAMiner.h index 4d53c5d33..e2018af27 100644 --- a/libethcore/EthashCUDAMiner.h +++ b/libethcore/EthashCUDAMiner.h @@ -36,7 +36,7 @@ namespace eth { class EthashCUDAHook; - class EthashCUDAMiner : public GenericMiner, Worker + class EthashCUDAMiner : public Miner, Worker { friend class dev::eth::EthashCUDAHook; @@ -80,7 +80,7 @@ class EthashCUDAHook; void workLoop() override; bool report(uint64_t _nonce); - using GenericMiner::accumulateHashes; + using Miner::accumulateHashes; EthashCUDAHook* m_hook = nullptr; ethash_cuda_miner* m_miner = nullptr; diff --git a/libethcore/EthashGPUMiner.cpp b/libethcore/EthashGPUMiner.cpp index e991d8898..5e5f1edc0 100644 --- a/libethcore/EthashGPUMiner.cpp +++ b/libethcore/EthashGPUMiner.cpp @@ -107,7 +107,7 @@ unsigned EthashGPUMiner::s_numInstances = 0; int EthashGPUMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; EthashGPUMiner::EthashGPUMiner(ConstructionInfo const& _ci): - GenericMiner(_ci), + Miner(_ci), Worker("openclminer" + toString(index())), m_hook(new EthashCLHook(this)) { diff --git a/libethcore/EthashGPUMiner.h b/libethcore/EthashGPUMiner.h index f5fb7e084..5268da8cc 100644 --- a/libethcore/EthashGPUMiner.h +++ b/libethcore/EthashGPUMiner.h @@ -36,7 +36,7 @@ namespace eth { class EthashCLHook; -class EthashGPUMiner: public GenericMiner, Worker +class EthashGPUMiner: public Miner, Worker { friend class dev::eth::EthashCLHook; @@ -76,7 +76,7 @@ private: void workLoop() override; bool report(uint64_t _nonce); - using GenericMiner::accumulateHashes; + using Miner::accumulateHashes; EthashCLHook* m_hook = nullptr; ethash_cl_miner* m_miner = nullptr; diff --git a/libethcore/Farm.h b/libethcore/Farm.h index c02a6629d..a5e40fcc5 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -41,20 +41,19 @@ namespace eth * Miners ask for work, then submit proofs * @threadsafe */ -class GenericFarm: public GenericFarmFace +class Farm: public FarmFace { public: using WorkPackage = EthashProofOfWork::WorkPackage; using Solution = EthashProofOfWork::Solution; - using Miner = GenericMiner; struct SealerDescriptor { std::function instances; - std::function create; + std::function create; }; - ~GenericFarm() + ~Farm() { stop(); } diff --git a/libethcore/Miner.cpp b/libethcore/Miner.cpp index e15746e97..b074411d9 100644 --- a/libethcore/Miner.cpp +++ b/libethcore/Miner.cpp @@ -4,12 +4,12 @@ using namespace dev; using namespace eth; -unsigned dev::eth::GenericMiner::s_dagLoadMode = 0; +unsigned dev::eth::Miner::s_dagLoadMode = 0; -volatile unsigned dev::eth::GenericMiner::s_dagLoadIndex = 0; +volatile unsigned dev::eth::Miner::s_dagLoadIndex = 0; -unsigned dev::eth::GenericMiner::s_dagCreateDevice = 0; +unsigned dev::eth::Miner::s_dagCreateDevice = 0; -volatile void* dev::eth::GenericMiner::s_dagInHostMemory = NULL; +volatile void* dev::eth::Miner::s_dagInHostMemory = NULL; diff --git a/libethcore/Miner.h b/libethcore/Miner.h index 5c9d77833..08a25fa10 100644 --- a/libethcore/Miner.h +++ b/libethcore/Miner.h @@ -108,7 +108,7 @@ inline std::ostream& operator<<(std::ostream& os, SolutionStats s) return os << "[A" << s.getAccepts() << "+" << s.getAcceptedStales() << ":R" << s.getRejects() << "+" << s.getRejectedStales() << ":F" << s.getFailures() << "]"; } -class GenericMiner; +class Miner; /** @@ -116,14 +116,13 @@ class GenericMiner; * @warning Must be implemented in a threadsafe manner since it will be called from multiple * miner threads. */ -class GenericFarmFace +class FarmFace { public: using WorkPackage = EthashProofOfWork::WorkPackage; using Solution = EthashProofOfWork::Solution; - using Miner = GenericMiner; - virtual ~GenericFarmFace() = default; + virtual ~FarmFace() = default; /** * @brief Called from a Miner to note a WorkPackage has a solution. @@ -139,19 +138,18 @@ public: * @brief A miner - a member and adoptee of the Farm. * @warning Not threadsafe. It is assumed Farm will synchronise calls to/from this class. */ -class GenericMiner +class Miner { public: using WorkPackage = EthashProofOfWork::WorkPackage; using Solution = EthashProofOfWork::Solution; - using FarmFace = GenericFarmFace; using ConstructionInfo = std::pair; - GenericMiner(ConstructionInfo const& _ci): + Miner(ConstructionInfo const& _ci): m_farm(_ci.first), m_index(_ci.second) {} - virtual ~GenericMiner() {} + virtual ~Miner() {} // API FOR THE FARM TO CALL IN WITH diff --git a/libstratum/EthStratumClient.cpp b/libstratum/EthStratumClient.cpp index d15e29105..4b5f9594b 100644 --- a/libstratum/EthStratumClient.cpp +++ b/libstratum/EthStratumClient.cpp @@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff) } -EthStratumClient::EthStratumClient(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) +EthStratumClient::EthStratumClient(Farm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) : m_socket(m_io_service) { m_minerType = m; diff --git a/libstratum/EthStratumClient.h b/libstratum/EthStratumClient.h index b5f33e04b..cea303618 100644 --- a/libstratum/EthStratumClient.h +++ b/libstratum/EthStratumClient.h @@ -21,7 +21,7 @@ using namespace dev::eth; class EthStratumClient { public: - EthStratumClient(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); + EthStratumClient(Farm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); ~EthStratumClient(); void setFailover(string const & host, string const & port); @@ -68,7 +68,7 @@ private: std::mutex x_pending; int m_pending; - GenericFarm* p_farm; + Farm* p_farm; std::mutex x_current; EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_previous; diff --git a/libstratum/EthStratumClientV2.cpp b/libstratum/EthStratumClientV2.cpp index b2548a7e9..8b05c0072 100644 --- a/libstratum/EthStratumClientV2.cpp +++ b/libstratum/EthStratumClientV2.cpp @@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff) } -EthStratumClientV2::EthStratumClientV2(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) +EthStratumClientV2::EthStratumClientV2(Farm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) : Worker("stratum"), m_socket(m_io_service) { diff --git a/libstratum/EthStratumClientV2.h b/libstratum/EthStratumClientV2.h index 24438c893..706616eee 100644 --- a/libstratum/EthStratumClientV2.h +++ b/libstratum/EthStratumClientV2.h @@ -22,7 +22,7 @@ using namespace dev::eth; class EthStratumClientV2 : public Worker { public: - EthStratumClientV2(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); + EthStratumClientV2(Farm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); ~EthStratumClientV2(); void setFailover(string const & host, string const & port); @@ -64,7 +64,7 @@ private: string m_response; - GenericFarm* p_farm; + Farm* p_farm; mutex x_current; EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_previous; From d5618a48ebeff1c63b91d455322ad207790f301f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 30 May 2017 20:32:15 +0200 Subject: [PATCH 3/4] Remove EthashProofOfWork namespace --- ethminer/MinerAux.h | 18 +++++----- libethcore/EthashAux.cpp | 8 ++--- libethcore/EthashAux.h | 60 +++++++++++++++---------------- libethcore/EthashCUDAMiner.cpp | 2 +- libethcore/EthashGPUMiner.cpp | 19 +--------- libethcore/Farm.h | 3 -- libethcore/Miner.h | 6 ---- libstratum/EthStratumClient.cpp | 6 ++-- libstratum/EthStratumClient.h | 6 ++-- libstratum/EthStratumClientV2.cpp | 6 ++-- libstratum/EthStratumClientV2.h | 6 ++-- 11 files changed, 55 insertions(+), 85 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index cdd228c9f..271e9df91 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -613,7 +613,7 @@ private: sealers["cuda"] = Farm::SealerDescriptor{ &EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; #endif f.setSealers(sealers); - f.onSolutionFound([&](EthashProofOfWork::Solution) { return false; }); + f.onSolutionFound([&](Solution) { return false; }); string platformInfo = _m == MinerType::CPU ? "CPU" : (_m == MinerType::CL ? "CL" : "CUDA"); cout << "Benchmarking on platform: " << platformInfo << endl; @@ -698,11 +698,11 @@ private: int time = 0; - EthashProofOfWork::WorkPackage current = EthashProofOfWork::WorkPackage(genesis); + WorkPackage current = WorkPackage(genesis); while (true) { bool completed = false; - EthashProofOfWork::Solution solution; - f.onSolutionFound([&](EthashProofOfWork::Solution sol) + Solution solution; + f.onSolutionFound([&](Solution sol) { solution = sol; return completed = true; @@ -776,14 +776,14 @@ private: f.start("opencl", false); else if (_m == MinerType::CUDA) f.start("cuda", false); - EthashProofOfWork::WorkPackage current, previous; + WorkPackage current, previous; std::mutex x_current; while (m_running) try { bool completed = false; - EthashProofOfWork::Solution solution; - f.onSolutionFound([&](EthashProofOfWork::Solution sol) + Solution solution; + f.onSolutionFound([&](Solution sol) { solution = sol; return completed = true; @@ -930,7 +930,7 @@ private: } f.setSealers(sealers); - f.onSolutionFound([&](EthashProofOfWork::Solution sol) + f.onSolutionFound([&](Solution sol) { if (client.isConnected()) { client.submit(sol); @@ -974,7 +974,7 @@ private: } f.setSealers(sealers); - f.onSolutionFound([&](EthashProofOfWork::Solution sol) + f.onSolutionFound([&](Solution sol) { client.submit(sol); return false; diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index 3feffb1ec..6e62af180 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -107,15 +107,15 @@ bytesConstRef EthashAux::LightAllocation::data() const return bytesConstRef((byte const*)light->cache, size); } -EthashProofOfWork::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const +Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const { ethash_return_value r = ethash_light_compute(light, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce); if (!r.success) BOOST_THROW_EXCEPTION(DAGCreationFailure()); - return EthashProofOfWork::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)}; + return Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)}; } -EthashProofOfWork::Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) noexcept +Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) noexcept { try { @@ -123,6 +123,6 @@ EthashProofOfWork::Result EthashAux::eval(h256 const& _seedHash, h256 const& _he } catch(...) { - return EthashProofOfWork::Result{~h256(), h256()}; + return Result{~h256(), h256()}; } } diff --git a/libethcore/EthashAux.h b/libethcore/EthashAux.h index 94ad19f2b..23842eac6 100644 --- a/libethcore/EthashAux.h +++ b/libethcore/EthashAux.h @@ -32,39 +32,35 @@ namespace dev namespace eth { -/// Proof of work definition for Ethash. -struct EthashProofOfWork +struct Solution { - struct Solution - { - Nonce nonce; - h256 mixHash; - }; + Nonce nonce; + h256 mixHash; +}; - struct Result - { - h256 value; - h256 mixHash; - }; +struct Result +{ + h256 value; + h256 mixHash; +}; - struct WorkPackage - { - WorkPackage() = default; - WorkPackage(BlockHeader const& _bh) : - boundary(_bh.boundary()), - headerHash(_bh.hashWithout()), - seedHash(_bh.seedHash()) - { } - void reset() { headerHash = h256(); } - operator bool() const { return headerHash != h256(); } - - h256 boundary; - h256 headerHash; ///< When h256() means "pause until notified a new work package is available". - h256 seedHash; - - uint64_t startNonce = 0; - int exSizeBits = -1; - }; +struct WorkPackage +{ + WorkPackage() = default; + WorkPackage(BlockHeader const& _bh) : + boundary(_bh.boundary()), + headerHash(_bh.hashWithout()), + seedHash(_bh.seedHash()) + { } + void reset() { headerHash = h256(); } + operator bool() const { return headerHash != h256(); } + + h256 boundary; + h256 headerHash; ///< When h256() means "pause until notified a new work package is available". + h256 seedHash; + + uint64_t startNonce = 0; + int exSizeBits = -1; }; class EthashAux @@ -77,7 +73,7 @@ public: LightAllocation(h256 const& _seedHash); ~LightAllocation(); bytesConstRef data() const; - EthashProofOfWork::Result compute(h256 const& _headerHash, Nonce const& _nonce) const; + Result compute(h256 const& _headerHash, Nonce const& _nonce) const; ethash_light_t light; uint64_t size; }; @@ -89,7 +85,7 @@ public: static LightType light(h256 const& _seedHash); - static EthashProofOfWork::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) noexcept; + static Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) noexcept; private: EthashAux() = default; diff --git a/libethcore/EthashCUDAMiner.cpp b/libethcore/EthashCUDAMiner.cpp index 3f91daf48..516628b18 100644 --- a/libethcore/EthashCUDAMiner.cpp +++ b/libethcore/EthashCUDAMiner.cpp @@ -124,7 +124,7 @@ EthashCUDAMiner::~EthashCUDAMiner() bool EthashCUDAMiner::report(uint64_t _nonce) { Nonce n = (Nonce)(u64)_nonce; - EthashProofOfWork::Result r = EthashAux::eval(work().seedHash, work().headerHash, n); + Result r = EthashAux::eval(work().seedHash, work().headerHash, n); if (r.value < work().boundary) return submitProof(Solution{ n, r.mixHash }); return false; diff --git a/libethcore/EthashGPUMiner.cpp b/libethcore/EthashGPUMiner.cpp index 5e5f1edc0..f90c29895 100644 --- a/libethcore/EthashGPUMiner.cpp +++ b/libethcore/EthashGPUMiner.cpp @@ -123,7 +123,7 @@ EthashGPUMiner::~EthashGPUMiner() bool EthashGPUMiner::report(uint64_t _nonce) { Nonce n = (Nonce)(u64)_nonce; - EthashProofOfWork::Result r = EthashAux::eval(work().seedHash, work().headerHash, n); + Result r = EthashAux::eval(work().seedHash, work().headerHash, n); if (r.value < work().boundary) return submitProof(Solution{n, r.mixHash}); return false; @@ -158,23 +158,6 @@ void EthashGPUMiner::workLoop() unsigned device = s_devices[index()] > -1 ? s_devices[index()] : index(); - /* - EthashAux::FullType dag; - while (true) - { - if ((dag = EthashAux::full(w.seedHash, true))) - break; - if (shouldStop()) - { - delete m_miner; - m_miner = nullptr; - return; - } - cnote << "Awaiting DAG"; - this_thread::sleep_for(chrono::milliseconds(500)); - } - */ - EthashAux::LightType light; light = EthashAux::light(w.seedHash); bytesConstRef lightData = light->data(); diff --git a/libethcore/Farm.h b/libethcore/Farm.h index a5e40fcc5..5c94a5f6a 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -44,9 +44,6 @@ namespace eth class Farm: public FarmFace { public: - using WorkPackage = EthashProofOfWork::WorkPackage; - using Solution = EthashProofOfWork::Solution; - struct SealerDescriptor { std::function instances; diff --git a/libethcore/Miner.h b/libethcore/Miner.h index 08a25fa10..d709cdc6e 100644 --- a/libethcore/Miner.h +++ b/libethcore/Miner.h @@ -119,15 +119,11 @@ class Miner; class FarmFace { public: - using WorkPackage = EthashProofOfWork::WorkPackage; - using Solution = EthashProofOfWork::Solution; - virtual ~FarmFace() = default; /** * @brief Called from a Miner to note a WorkPackage has a solution. * @param _p The solution. - * @param _wp The WorkPackage that the Solution is for; this will be reset if the work is accepted. * @param _finder The miner that found it. * @return true iff the solution was good (implying that mining should be . */ @@ -141,8 +137,6 @@ public: class Miner { public: - using WorkPackage = EthashProofOfWork::WorkPackage; - using Solution = EthashProofOfWork::Solution; using ConstructionInfo = std::pair; Miner(ConstructionInfo const& _ci): diff --git a/libstratum/EthStratumClient.cpp b/libstratum/EthStratumClient.cpp index 4b5f9594b..89c114eef 100644 --- a/libstratum/EthStratumClient.cpp +++ b/libstratum/EthStratumClient.cpp @@ -504,11 +504,11 @@ void EthStratumClient::work_timeout_handler(const boost::system::error_code& ec) } } -bool EthStratumClient::submit(EthashProofOfWork::Solution solution) { +bool EthStratumClient::submit(Solution solution) { x_current.lock(); - EthashProofOfWork::WorkPackage tempWork(m_current); + WorkPackage tempWork(m_current); string temp_job = m_job; - EthashProofOfWork::WorkPackage tempPreviousWork(m_previous); + WorkPackage tempPreviousWork(m_previous); string temp_previous_job = m_previousJob; x_current.unlock(); diff --git a/libstratum/EthStratumClient.h b/libstratum/EthStratumClient.h index cea303618..cafa32c13 100644 --- a/libstratum/EthStratumClient.h +++ b/libstratum/EthStratumClient.h @@ -32,7 +32,7 @@ public: h256 currentHeaderHash() { return m_current.headerHash; } bool current() { return m_current; } unsigned waitState() { return m_waitState; } - bool submit(EthashProofOfWork::Solution solution); + bool submit(Solution solution); void reconnect(); private: void connect(); @@ -70,8 +70,8 @@ private: Farm* p_farm; std::mutex x_current; - EthashProofOfWork::WorkPackage m_current; - EthashProofOfWork::WorkPackage m_previous; + WorkPackage m_current; + WorkPackage m_previous; bool m_stale = false; diff --git a/libstratum/EthStratumClientV2.cpp b/libstratum/EthStratumClientV2.cpp index 8b05c0072..5284b9395 100644 --- a/libstratum/EthStratumClientV2.cpp +++ b/libstratum/EthStratumClientV2.cpp @@ -446,11 +446,11 @@ void EthStratumClientV2::work_timeout_handler(const boost::system::error_code& e } } -bool EthStratumClientV2::submit(EthashProofOfWork::Solution solution) { +bool EthStratumClientV2::submit(Solution solution) { x_current.lock(); - EthashProofOfWork::WorkPackage tempWork(m_current); + WorkPackage tempWork(m_current); string temp_job = m_job; - EthashProofOfWork::WorkPackage tempPreviousWork(m_previous); + WorkPackage tempPreviousWork(m_previous); string temp_previous_job = m_previousJob; x_current.unlock(); diff --git a/libstratum/EthStratumClientV2.h b/libstratum/EthStratumClientV2.h index 706616eee..e8040f2f8 100644 --- a/libstratum/EthStratumClientV2.h +++ b/libstratum/EthStratumClientV2.h @@ -33,7 +33,7 @@ public: h256 currentHeaderHash() { return m_current.headerHash; } bool current() { return m_current; } unsigned waitState() { return m_waitState; } - bool submit(EthashProofOfWork::Solution solution); + bool submit(Solution solution); void reconnect(); private: void workLoop() override; @@ -66,8 +66,8 @@ private: Farm* p_farm; mutex x_current; - EthashProofOfWork::WorkPackage m_current; - EthashProofOfWork::WorkPackage m_previous; + WorkPackage m_current; + WorkPackage m_previous; bool m_stale = false; From 5c341235a6bd53ff7779bf5ae3b4538cfa57380b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 30 May 2017 20:43:32 +0200 Subject: [PATCH 4/4] Remove ethcore/Common.h header --- libethcore/BlockInfo.cpp | 1 - libethcore/BlockInfo.h | 11 ++++++- libethcore/Common.h | 66 ---------------------------------------- libethcore/Exceptions.h | 1 - libethcore/Farm.h | 1 - libethcore/Miner.h | 9 +++++- 6 files changed, 18 insertions(+), 71 deletions(-) delete mode 100644 libethcore/Common.h diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 38d1755d7..b05f766dc 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include "EthashAux.h" #include "Exceptions.h" #include "BlockInfo.h" diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index 55bdf2b08..96251c290 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -24,7 +24,6 @@ #include #include #include -#include "Common.h" #include "Exceptions.h" namespace dev @@ -32,6 +31,16 @@ namespace dev namespace eth { +/// An Ethereum address: 20 bytes. +using Address = h160; + +/// The log bloom's size (2048-bit). +using LogBloom = h2048; + +using Nonce = h64; + +using BlockNumber = unsigned; + enum IncludeProof { WithoutProof = 0, diff --git a/libethcore/Common.h b/libethcore/Common.h deleted file mode 100644 index 87ffa8465..000000000 --- a/libethcore/Common.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file Common.h - * @author Gav Wood - * @date 2014 - * - * Ethereum-specific data structures & algorithms. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace dev -{ -namespace eth -{ - -/// An Ethereum address: 20 bytes. -/// @NOTE This is not endian-specific; it's just a bunch of bytes. -using Address = h160; - -DEV_SIMPLE_EXCEPTION(InvalidAddress); - -/// The log bloom's size (2048-bit). -using LogBloom = h2048; - -/// Many log blooms. -using LogBlooms = std::vector; - -using Nonce = h64; - -using BlockNumber = unsigned; - -// TODO: move back into a mining subsystem and have it be accessible from Sealant only via a dynamic_cast. -/** - * @brief Describes the progress of a mining operation. - */ -struct WorkingProgress -{ -// MiningProgress& operator+=(MiningProgress const& _mp) { hashes += _mp.hashes; ms = std::max(ms, _mp.ms); return *this; } - uint64_t hashes = 0; ///< Total number of hashes computed. - uint64_t ms = 0; ///< Total number of milliseconds of mining thus far. - uint64_t rate() const { return ms == 0 ? 0 : hashes * 1000 / ms; } -}; - -} -} diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index 68992286c..956b6f76e 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -22,7 +22,6 @@ #pragma once #include -#include "Common.h" namespace dev { diff --git a/libethcore/Farm.h b/libethcore/Farm.h index 5c94a5f6a..e201f0077 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/libethcore/Miner.h b/libethcore/Miner.h index d709cdc6e..689649cab 100644 --- a/libethcore/Miner.h +++ b/libethcore/Miner.h @@ -29,7 +29,6 @@ #include #include #include -#include #include "EthashAux.h" #define MINER_WAIT_STATE_UNKNOWN 0 @@ -68,6 +67,14 @@ enum class MinerType Mixed }; +/// Describes the progress of a mining operation. +struct WorkingProgress +{ + uint64_t hashes = 0; ///< Total number of hashes computed. + uint64_t ms = 0; ///< Total number of milliseconds of mining thus far. + uint64_t rate() const { return ms == 0 ? 0 : hashes * 1000 / ms; } +}; + inline std::ostream& operator<<(std::ostream& _out, WorkingProgress _p) { float mh = _p.rate() / 1000000.0f;