From 0547a6c1d59432b6220e34bf5430448094b75dd9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Apr 2015 21:02:00 +0200 Subject: [PATCH] Fix build. --- exp/main.cpp | 5 ++++- libethcore/BlockInfo.cpp | 7 +++++++ libethcore/BlockInfo.h | 4 +++- libethcore/ProofOfWork.cpp | 22 ++++++++++++++++------ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/exp/main.cpp b/exp/main.cpp index 6887e6c49..48562f80e 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -19,10 +19,11 @@ * @date 2014 * Ethereum client. */ +#if ETH_ETHASHCL #define __CL_ENABLE_EXCEPTIONS #define CL_USE_DEPRECATED_OPENCL_2_0_APIS #include "libethash-cl/cl.hpp" - +#endif #include #include #include @@ -108,6 +109,7 @@ int main() #else int main() { +#if ETH_ETHASHCL EthashCL ecl; BlockInfo genesis = CanonBlockChain::genesis(); genesis.difficulty = 1 << 18; @@ -118,6 +120,7 @@ int main() cdebug << r.second.mixHash << r.second.nonce; EthashCL::assignResult(r.second, genesis); assert(EthashCPU::verify(genesis)); +#endif return 0; } #endif diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 0be8cd765..6cd431931 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -75,6 +75,13 @@ h256 const& BlockInfo::hash() const return m_hash; } +h256 const& BlockInfo::boundary() const +{ + if (!m_boundary) + m_boundary = (h256)(u256)((bigint(1) << 256) / difficulty); + return m_boundary; +} + BlockInfo BlockInfo::fromHeader(bytesConstRef _header, Strictness _s, h256 const& _h) { BlockInfo ret; diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index 302db5f17..dffff73f4 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -118,7 +118,7 @@ public: void clear(); - void noteDirty() const { m_hash = m_seedHash = h256(); } + void noteDirty() const { m_hash = m_seedHash = m_boundary = h256(); } void populateFromHeader(RLP const& _header, Strictness _s = IgnoreNonce, h256 const& _h = h256()); void populate(bytesConstRef _block, Strictness _s = IgnoreNonce, h256 const& _h = h256()); @@ -131,6 +131,7 @@ public: u256 selectGasLimit(BlockInfo const& _parent) const; h256 const& seedHash() const; h256 const& hash() const; + h256 const& boundary() const; /// sha3 of the header only. h256 headerHash(IncludeNonce _n) const; @@ -139,6 +140,7 @@ public: private: mutable h256 m_seedHash; mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised. + mutable h256 m_boundary; ///< 2^256 / difficulty }; inline std::ostream& operator<<(std::ostream& _out, BlockInfo const& _bi) diff --git a/libethcore/ProofOfWork.cpp b/libethcore/ProofOfWork.cpp index f85205484..e24b2087c 100644 --- a/libethcore/ProofOfWork.cpp +++ b/libethcore/ProofOfWork.cpp @@ -128,9 +128,9 @@ struct EthashCLHook: public ethash_cl_miner::search_hook { void abort() { - cdebug << "Attempting to abort"; if (m_aborted) return; + cdebug << "Attempting to abort"; m_abort = true; for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout) std::this_thread::sleep_for(chrono::milliseconds(30)); @@ -198,14 +198,19 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi if (m_miner) m_hook->abort(); m_miner.reset(new ethash_cl_miner); - m_miner->init(Ethasher::params(_header), [&](void* d){ Ethasher::get()->readFull(_header, d); }); + auto cb = [&](void* d) { + Ethasher::get()->readFull(_header, d); + }; + m_miner->init(Ethasher::params(_header), cb); } if (m_lastHeader != _header) { m_hook->abort(); static std::random_device s_eng; uint64_t tryNonce = (uint64_t)(u64)(m_last = Nonce::random(s_eng)); - m_miner->search(_header.headerHash(WithoutNonce).data(), tryNonce, *m_hook); + auto hh = _header.headerHash(WithoutNonce); + cdebug << "Mining with headerhash" << hh << "from nonce" << m_last << "with boundary" << _header.boundary(); + m_miner->search(hh.data(), tryNonce, *m_hook); } m_lastHeader = _header; @@ -213,9 +218,14 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi auto found = m_hook->fetchFound(); if (!found.empty()) { - Nonce n = (Nonce)(u64)found[0]; - auto result = Ethasher::eval(_header, n); - return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash}); + for (auto const& n: found) + { + auto result = Ethasher::eval(_header, n); + cdebug << "Got nonce " << n << "gives result" << result.value; + if (result.value < _header.boundary()) + return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash}); + } + assert(false); } return std::make_pair(MineInfo(false), EthashCL::Proof()); }