From 256eea1b0bb3048e5195f33a9e937adc8aeafd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 16:09:33 +0200 Subject: [PATCH 01/11] CMake: Refactor mvcc flags --- libethash-cuda/CMakeLists.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libethash-cuda/CMakeLists.txt b/libethash-cuda/CMakeLists.txt index 47233d696..e1be8c9d0 100644 --- a/libethash-cuda/CMakeLists.txt +++ b/libethash-cuda/CMakeLists.txt @@ -6,10 +6,19 @@ list(APPEND CUDA_NVCC_FLAGS_RELEASE -O3) list(APPEND CUDA_NVCC_FLAGS_DEBUG -G) if(COMPUTE AND (COMPUTE GREATER 0)) - list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_${COMPUTE},code=sm_${COMPUTE}) -else(COMPUTE AND (COMPUTE GREATER 0)) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_20,code=sm_20;-gencode arch=compute_30,code=sm_30;-gencode arch=compute_35,code=sm_35;-gencode arch=compute_50,code=sm_50;-gencode arch=compute_52,code=sm_52;-gencode arch=compute_61,code=sm_61) -endif(COMPUTE AND (COMPUTE GREATER 0)) + list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_${COMPUTE},code=sm_${COMPUTE}") +else() + set( + CUDA_NVCC_FLAGS + ${CUDA_NVCC_FLAGS} + "-gencode arch=compute_20,code=sm_20" + "-gencode arch=compute_30,code=sm_30" + "-gencode arch=compute_35,code=sm_35" + "-gencode arch=compute_50,code=sm_50" + "-gencode arch=compute_52,code=sm_52" + "-gencode arch=compute_61,code=sm_61" + ) +endif() file(GLOB sources "*.cpp" "*.cu") file(GLOB headers "*.h" "*.cuh") From 1de8f50a640f636e4e14b859d3820b63ad8fe065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 16:27:31 +0200 Subject: [PATCH 02/11] CUDA: Drop Compute 2.0 architecture --- libethash-cuda/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/libethash-cuda/CMakeLists.txt b/libethash-cuda/CMakeLists.txt index e1be8c9d0..fac71a6b2 100644 --- a/libethash-cuda/CMakeLists.txt +++ b/libethash-cuda/CMakeLists.txt @@ -11,7 +11,6 @@ else() set( CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} - "-gencode arch=compute_20,code=sm_20" "-gencode arch=compute_30,code=sm_30" "-gencode arch=compute_35,code=sm_35" "-gencode arch=compute_50,code=sm_50" From 8258dcc8c1f3f884ba6b06af2d4b19f9479b41e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 16:48:43 +0200 Subject: [PATCH 03/11] Remove Assertions.h header --- libdevcore/Assertions.h | 110 ---------------------------------------- 1 file changed, 110 deletions(-) delete mode 100644 libdevcore/Assertions.h diff --git a/libdevcore/Assertions.h b/libdevcore/Assertions.h deleted file mode 100644 index 00c4c3b75..000000000 --- a/libdevcore/Assertions.h +++ /dev/null @@ -1,110 +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 Assertions.h - * @author Christian - * @date 2015 - * - * Assertion handling. - */ - -#pragma once - -#include "Exceptions.h" - -namespace dev -{ - -#if defined(_MSC_VER) -#define ETH_FUNC __FUNCSIG__ -#elif defined(__GNUC__) -#define ETH_FUNC __PRETTY_FUNCTION__ -#else -#define ETH_FUNC __func__ -#endif - -#define asserts(A) ::dev::assertAux(A, #A, __LINE__, __FILE__, ETH_FUNC) -#define assertsEqual(A, B) ::dev::assertEqualAux(A, B, #A, #B, __LINE__, __FILE__, ETH_FUNC) - -inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func) -{ - bool ret = _a; - if (!ret) - { - std::cerr << "Assertion failed:" << _aStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl; -#if ETH_DEBUG - debug_break(); -#endif - } - return !ret; -} - -template -inline bool assertEqualAux(A const& _a, B const& _b, char const* _aStr, char const* _bStr, unsigned _line, char const* _file, char const* _func) -{ - bool ret = _a == _b; - if (!ret) - { - std::cerr << "Assertion failed: " << _aStr << " == " << _bStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl; - std::cerr << " Fail equality: " << _a << "==" << _b << std::endl; -#if ETH_DEBUG - debug_break(); -#endif - } - return !ret; -} - -/// Assertion that throws an exception containing the given description if it is not met. -/// Use it as assertThrow(1 == 1, ExceptionType, "Mathematics is wrong."); -/// Do NOT supply an exception object as the second parameter. -#define assertThrow(_condition, _ExceptionType, _description) \ - ::dev::assertThrowAux<_ExceptionType>(_condition, _description, __LINE__, __FILE__, ETH_FUNC) - -using errinfo_comment = boost::error_info; - -template -inline void assertThrowAux( - bool _condition, - ::std::string const& _errorDescription, - unsigned _line, - char const* _file, - char const* _function -) -{ - if (!_condition) - ::boost::throw_exception( - _ExceptionType() << - ::dev::errinfo_comment(_errorDescription) << - ::boost::throw_function(_function) << - ::boost::throw_file(_file) << - ::boost::throw_line(_line) - ); -} - -template -inline void assertThrowAux( - void const* _pointer, - ::std::string const& _errorDescription, - unsigned _line, - char const* _file, - char const* _function -) -{ - assertThrowAux<_ExceptionType>(_pointer != nullptr, _errorDescription, _line, _file, _function); -} - -} From 6830f46b018fa8c745f461c88dda68b5aab8bdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 16:54:01 +0200 Subject: [PATCH 04/11] Remove unused exception types --- libdevcore/Exceptions.h | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index 48ece799c..71f8a5df6 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -53,31 +53,14 @@ DEV_SIMPLE_EXCEPTION_RLP(OversizeRLP); DEV_SIMPLE_EXCEPTION_RLP(UndersizeRLP); DEV_SIMPLE_EXCEPTION(BadHexCharacter); -DEV_SIMPLE_EXCEPTION(NoNetworking); -DEV_SIMPLE_EXCEPTION(NoUPnPDevice); -DEV_SIMPLE_EXCEPTION(RootNotFound); -struct BadRoot: virtual Exception { public: BadRoot(h256 const& _root): Exception("BadRoot " + _root.hex()), root(_root) {} h256 root; }; -DEV_SIMPLE_EXCEPTION(FileError); -DEV_SIMPLE_EXCEPTION(Overflow); -DEV_SIMPLE_EXCEPTION(FailedInvariant); -DEV_SIMPLE_EXCEPTION(ValueTooLarge); -struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} }; struct ExternalFunctionFailure: virtual Exception { public: ExternalFunctionFailure(std::string _f): Exception("Function " + _f + "() failed.") {} }; // error information to be added to exceptions using errinfo_invalidSymbol = boost::error_info; -using errinfo_wrongAddress = boost::error_info; using errinfo_comment = boost::error_info; using errinfo_required = boost::error_info; using errinfo_got = boost::error_info; -using errinfo_min = boost::error_info; -using errinfo_max = boost::error_info; using RequirementError = boost::tuple; -using errinfo_hash256 = boost::error_info; -using errinfo_required_h256 = boost::error_info; -using errinfo_got_h256 = boost::error_info; -using Hash256RequirementError = boost::tuple; -using errinfo_extraData = boost::error_info; } From 4fe77c4458c4ab0bc99794219c4426ae45595fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 17:02:39 +0200 Subject: [PATCH 05/11] Drop SecureFixedHash class --- libdevcore/FixedHash.h | 171 ----------------------------------------- 1 file changed, 171 deletions(-) diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index c09d54759..9c8cd8b66 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -32,10 +32,6 @@ namespace dev { -/// Compile-time calculation of Log2 of constant values. -template struct StaticLog2 { enum { result = 1 + StaticLog2::result }; }; -template <> struct StaticLog2<1> { enum { result = 0 }; }; - extern std::random_device s_fixedHashEngine; /// Fixed-size raw-byte array container type, with an API optimised for storing hashes. @@ -110,9 +106,6 @@ public: // Big-endian increment. FixedHash& operator++() { for (unsigned i = size; i > 0 && !++m_data[--i]; ) {} return *this; } - /// @returns true if all one-bits in @a _c are set in this object. - bool contains(FixedHash const& _c) const { return (*this & _c) == _c; } - /// @returns a particular byte from the hash. byte& operator[](unsigned _i) { return m_data[_i]; } /// @returns a particular byte from the hash. @@ -121,9 +114,6 @@ public: /// @returns an abridged version of the hash as a user-readable hex string. std::string abridged() const { return toHex(ref().cropped(0, 4)) + "\342\200\246"; } - /// @returns a version of the hash as a user-readable hex string that leaves out the middle part. - std::string abridgedMiddle() const { return toHex(ref().cropped(0, 4)) + "\342\200\246" + toHex(ref().cropped(N - 4)); } - /// @returns the hash as a user-readable hex string. std::string hex() const { return toHex(ref()); } @@ -139,15 +129,6 @@ public: /// @returns a constant byte pointer to the object's data. byte const* data() const { return m_data.data(); } - /// @returns a copy of the object's data as a byte vector. - bytes asBytes() const { return bytes(data(), data() + N); } - - /// @returns a mutable reference to the object's data as an STL array. - std::array& asArray() { return m_data; } - - /// @returns a constant reference to the object's data as an STL array. - std::array const& asArray() const { return m_data; } - /// Populate with random data. template void randomize(Engine& _eng) @@ -165,136 +146,12 @@ public: size_t operator()(FixedHash const& _value) const { return boost::hash_range(_value.m_data.cbegin(), _value.m_data.cend()); } }; - template inline FixedHash& shiftBloom(FixedHash const& _h) - { - return (*this |= _h.template bloomPart()); - } - - template inline bool containsBloom(FixedHash const& _h) - { - return contains(_h.template bloomPart()); - } - - template inline FixedHash bloomPart() const - { - unsigned const c_bloomBits = M * 8; - unsigned const c_mask = c_bloomBits - 1; - unsigned const c_bloomBytes = (StaticLog2::result + 7) / 8; - - static_assert((M & (M - 1)) == 0, "M must be power-of-two"); - static_assert(P * c_bloomBytes <= N, "out of range"); - - FixedHash ret; - byte const* p = data(); - for (unsigned i = 0; i < P; ++i) - { - unsigned index = 0; - for (unsigned j = 0; j < c_bloomBytes; ++j, ++p) - index = (index << 8) | *p; - index &= c_mask; - ret[M - 1 - index / 8] |= (1 << (index % 8)); - } - return ret; - } - - /// Returns the index of the first bit set to one, or size() * 8 if no bits are set. - inline unsigned firstBitSet() const - { - unsigned ret = 0; - for (auto d: m_data) - if (d) - for (;; ++ret, d <<= 1) - if (d & 0x80) - return ret; - else {} - else - ret += 8; - return ret; - } - void clear() { m_data.fill(0); } private: std::array m_data; ///< The binary data. }; -template -class SecureFixedHash: private FixedHash -{ -public: - using ConstructFromHashType = typename FixedHash::ConstructFromHashType; - using ConstructFromStringType = typename FixedHash::ConstructFromStringType; - using ConstructFromPointerType = typename FixedHash::ConstructFromPointerType; - SecureFixedHash() = default; - explicit SecureFixedHash(bytes const& _b, ConstructFromHashType _t = FixedHash::FailIfDifferent): FixedHash(_b, _t) {} - explicit SecureFixedHash(bytesConstRef _b, ConstructFromHashType _t = FixedHash::FailIfDifferent): FixedHash(_b, _t) {} - explicit SecureFixedHash(bytesSec const& _b, ConstructFromHashType _t = FixedHash::FailIfDifferent): FixedHash(_b.ref(), _t) {} - template explicit SecureFixedHash(FixedHash const& _h, ConstructFromHashType _t = FixedHash::AlignLeft): FixedHash(_h, _t) {} - template explicit SecureFixedHash(SecureFixedHash const& _h, ConstructFromHashType _t = FixedHash::AlignLeft): FixedHash(_h.makeInsecure(), _t) {} - explicit SecureFixedHash(std::string const& _s, ConstructFromStringType _t = FixedHash::FromHex, ConstructFromHashType _ht = FixedHash::FailIfDifferent): FixedHash(_s, _t, _ht) {} - explicit SecureFixedHash(bytes const* _d, ConstructFromPointerType _t): FixedHash(_d, _t) {} - ~SecureFixedHash() { ref().cleanse(); } - - SecureFixedHash& operator=(SecureFixedHash const& _c) - { - if (&_c == this) - return *this; - ref().cleanse(); - FixedHash::operator=(static_cast const&>(_c)); - return *this; - } - - using FixedHash::size; - - bytesSec asBytesSec() const { return bytesSec(ref()); } - - FixedHash const& makeInsecure() const { return static_cast const&>(*this); } - FixedHash& writable() { clear(); return static_cast&>(*this); } - - using FixedHash::operator bool; - - // The obvious comparison operators. - bool operator==(SecureFixedHash const& _c) const { return static_cast const&>(*this).operator==(static_cast const&>(_c)); } - bool operator!=(SecureFixedHash const& _c) const { return static_cast const&>(*this).operator!=(static_cast const&>(_c)); } - bool operator<(SecureFixedHash const& _c) const { return static_cast const&>(*this).operator<(static_cast const&>(_c)); } - bool operator>=(SecureFixedHash const& _c) const { return static_cast const&>(*this).operator>=(static_cast const&>(_c)); } - bool operator<=(SecureFixedHash const& _c) const { return static_cast const&>(*this).operator<=(static_cast const&>(_c)); } - bool operator>(SecureFixedHash const& _c) const { return static_cast const&>(*this).operator>(static_cast const&>(_c)); } - - using FixedHash::operator==; - using FixedHash::operator!=; - using FixedHash::operator<; - using FixedHash::operator>=; - using FixedHash::operator<=; - using FixedHash::operator>; - - // The obvious binary operators. - SecureFixedHash& operator^=(FixedHash const& _c) { static_cast&>(*this).operator^=(_c); return *this; } - SecureFixedHash operator^(FixedHash const& _c) const { return SecureFixedHash(*this) ^= _c; } - SecureFixedHash& operator|=(FixedHash const& _c) { static_cast&>(*this).operator^=(_c); return *this; } - SecureFixedHash operator|(FixedHash const& _c) const { return SecureFixedHash(*this) |= _c; } - SecureFixedHash& operator&=(FixedHash const& _c) { static_cast&>(*this).operator^=(_c); return *this; } - SecureFixedHash operator&(FixedHash const& _c) const { return SecureFixedHash(*this) &= _c; } - - SecureFixedHash& operator^=(SecureFixedHash const& _c) { static_cast&>(*this).operator^=(static_cast const&>(_c)); return *this; } - SecureFixedHash operator^(SecureFixedHash const& _c) const { return SecureFixedHash(*this) ^= _c; } - SecureFixedHash& operator|=(SecureFixedHash const& _c) { static_cast&>(*this).operator^=(static_cast const&>(_c)); return *this; } - SecureFixedHash operator|(SecureFixedHash const& _c) const { return SecureFixedHash(*this) |= _c; } - SecureFixedHash& operator&=(SecureFixedHash const& _c) { static_cast&>(*this).operator^=(static_cast const&>(_c)); return *this; } - SecureFixedHash operator&(SecureFixedHash const& _c) const { return SecureFixedHash(*this) &= _c; } - SecureFixedHash operator~() const { auto r = ~static_cast const&>(*this); return static_cast(r); } - - using FixedHash::abridged; - using FixedHash::abridgedMiddle; - - bytesConstRef ref() const { return FixedHash::ref(); } - byte const* data() const { return FixedHash::data(); } - - using FixedHash::firstBitSet; - - void clear() { ref().cleanse(); } -}; - /// Fast equality operator for h256. template<> inline bool FixedHash<32>::operator==(FixedHash<32> const& _other) const { @@ -321,14 +178,6 @@ inline std::ostream& operator<<(std::ostream& _out, FixedHash const& _h) return _out; } -/// Stream I/O for the SecureFixedHash class. -template -inline std::ostream& operator<<(std::ostream& _out, SecureFixedHash const& _h) -{ - _out << "SecureFixedHash#" << std::hex << typename FixedHash::hash()(_h.makeInsecure()) << std::dec; - return _out; -} - // Common types of FixedHash. using h2048 = FixedHash<256>; using h1024 = FixedHash<128>; @@ -346,26 +195,6 @@ using h160Set = std::set; using h256Hash = std::unordered_set; using h160Hash = std::unordered_set; -/// Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes. -inline h160 right160(h256 const& _t) -{ - h160 ret; - memcpy(ret.data(), _t.data() + 12, 20); - return ret; -} - -/// Convert the given value into h160 (160-bit unsigned integer) using the left 20 bytes. -inline h160 left160(h256 const& _t) -{ - h160 ret; - memcpy(&ret[0], _t.data(), 20); - return ret; -} - -h128 fromUUID(std::string const& _uuid); - -std::string toUUID(h128 const& _uuid); - inline std::string toString(h256s const& _bs) { std::ostringstream out; From 99b778e180f31ef1898a9caffa5eb96f0850976f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 17:13:45 +0200 Subject: [PATCH 06/11] Simplify FixedHash --- libdevcore/FixedHash.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 9c8cd8b66..20755ef3e 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -50,9 +50,6 @@ public: /// A dummy flag to avoid accidental construction from pointer. enum ConstructFromPointerType { ConstructFromPointer }; - /// Method to convert from a string. - enum ConstructFromStringType { FromHex, FromBinary }; - /// Method to convert from a string. enum ConstructFromHashType { AlignLeft, AlignRight, FailIfDifferent }; @@ -78,7 +75,7 @@ public: explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); } /// Explicitly construct, copying from a string. - explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : dev::asBytes(_s), _ht) {} + explicit FixedHash(std::string const& _s): FixedHash(fromHex(_s, WhenError::Throw), FailIfDifferent) {} /// Convert to arithmetic type. operator Arith() const { return fromBigEndian(m_data); } From eb4377939fccb70cca60fdc80ad135b659d41a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 17:34:52 +0200 Subject: [PATCH 07/11] Simplify log output --- libdevcore/Log.cpp | 22 ++-------------------- libdevcore/Log.h | 7 ++----- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/libdevcore/Log.cpp b/libdevcore/Log.cpp index cad77cb3f..f64f682c3 100644 --- a/libdevcore/Log.cpp +++ b/libdevcore/Log.cpp @@ -130,11 +130,6 @@ string dev::ThreadContext::join(string const& _prior) return g_logThreadContext.join(_prior); } -// foward declare without all of Windows.h -#ifdef _WIN32 -extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString); -#endif - string dev::getThreadName() { #if defined(__linux__) || defined(__APPLE__) @@ -158,20 +153,7 @@ void dev::setThreadName(char const* _n) #endif } -void dev::simpleDebugOut(std::string const& _s, char const*) +void dev::simpleDebugOut(std::string const& _s) { - static SpinLock s_lock; - SpinGuard l(s_lock); - - cerr << _s << endl << flush; - - // helpful to use OutputDebugString on windows - #ifdef _WIN32 - { - OutputDebugStringA(_s.data()); - OutputDebugStringA("\n"); - } - #endif + std::cerr << _s << '\n'; } - -std::function dev::g_logPost = simpleDebugOut; diff --git a/libdevcore/Log.h b/libdevcore/Log.h index d6e2ef44d..8d8c2b3bc 100644 --- a/libdevcore/Log.h +++ b/libdevcore/Log.h @@ -44,14 +44,11 @@ public: }; /// A simple log-output function that prints log messages to stdout. -void simpleDebugOut(std::string const&, char const*); +void simpleDebugOut(std::string const&); /// The logging system's current verbosity. extern int g_logVerbosity; -/// The current method that the logging system uses to output the log messages. Defaults to simpleDebugOut(). -extern std::function g_logPost; - class ThreadContext { public: @@ -208,7 +205,7 @@ public: LogOutputStream(): LogOutputStreamBase(Id::name(), &typeid(Id), Id::verbosity, _AutoSpacing) {} /// Destructor. Posts the accrued log entry to the g_logPost function. - ~LogOutputStream() { if (Id::verbosity <= g_logVerbosity) g_logPost(m_sstr.str(), Id::name()); } + ~LogOutputStream() { if (Id::verbosity <= g_logVerbosity) simpleDebugOut(m_sstr.str()); } LogOutputStream& operator<<(std::string const& _t) { if (Id::verbosity <= g_logVerbosity) { if (_AutoSpacing && m_sstr.str().size() && m_sstr.str().back() != ' ') m_sstr << " "; comment(_t); } return *this; } From 7294edf711173c8a75cb39204377eac0ef4e4e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 18:00:32 +0200 Subject: [PATCH 08/11] Simplify RLP --- libdevcore/RLP.cpp | 13 +---------- libdevcore/RLP.h | 54 --------------------------------------------- libdevcore/SHA3.cpp | 4 +--- libdevcore/SHA3.h | 2 -- 4 files changed, 2 insertions(+), 71 deletions(-) diff --git a/libdevcore/RLP.cpp b/libdevcore/RLP.cpp index 94e4ee579..1a934c03f 100644 --- a/libdevcore/RLP.cpp +++ b/libdevcore/RLP.cpp @@ -23,9 +23,6 @@ using namespace std; using namespace dev; -bytes dev::RLPNull = rlp(""); -bytes dev::RLPEmptyList = rlpList(); - RLP::RLP(bytesConstRef _d, Strictness _s): m_data(_d) { @@ -131,7 +128,7 @@ bool RLP::isInt() const requireGood(); byte n = m_data[0]; if (n < c_rlpDataImmLenStart) - return !!n; + return n != 0; else if (n == c_rlpDataImmLenStart) return true; else if (n <= c_rlpDataIndLenZero) @@ -146,8 +143,6 @@ bool RLP::isInt() const BOOST_THROW_EXCEPTION(BadRLP()); return m_data[1 + n - c_rlpDataIndLenZero] != 0; } - else - return false; return false; } @@ -365,9 +360,3 @@ static void streamOut(std::ostream& _out, dev::RLP const& _d, unsigned _depth = _out << " ]"; } } - -std::ostream& dev::operator<<(std::ostream& _out, RLP const& _d) -{ - streamOut(_out, _d); - return _out; -} diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index 701f4b8e8..23a1a347b 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -100,9 +100,6 @@ public: /// No value. bool isNull() const { return m_data.size() == 0; } - /// Contains a zero-length string or zero-length list. - bool isEmpty() const { return !isNull() && (m_data[0] == c_rlpDataImmLenStart || m_data[0] == c_rlpListStart); } - /// String value. bool isData() const { return !isNull() && m_data[0] < c_rlpListStart; } @@ -118,7 +115,6 @@ public: /// @returns the number of bytes in the data, or zero if it isn't data. size_t size() const { return isData() ? length() : 0; } - size_t sizeStrict() const { if (!isData()) BOOST_THROW_EXCEPTION(BadCast()); return length(); } /// Equality operators; does best-effort conversion and checks for equality. bool operator==(char const* _s) const { return isData() && toString() == _s; } @@ -189,12 +185,8 @@ public: /// Converts to bytearray. @returns the empty byte array if not a string. bytes toBytes() const { if (!isData()) return bytes(); return bytes(payload().data(), payload().data() + length()); } - /// Converts to bytearray. @returns the empty byte array if not a string. - bytesConstRef toBytesConstRef() const { if (!isData()) return bytesConstRef(); return payload().cropped(0, length()); } /// Converts to string. @returns the empty string if not a string. std::string toString() const { if (!isData()) return std::string(); return payload().cropped(0, length()).toString(); } - /// Converts to string. @throws BadCast if not a string. - std::string toStringStrict() const { if (!isData()) BOOST_THROW_EXCEPTION(BadCast()); return payload().cropped(0, length()).toString(); } template std::vector toVector() const @@ -219,16 +211,6 @@ public: return ret; } - template - std::unordered_set toUnorderedSet() const - { - std::unordered_set ret; - if (isList()) - for (auto const& i: *this) - ret.insert((T)i); - return ret; - } - template std::pair toPair() const { @@ -369,20 +351,14 @@ public: /// Appends a sequence of data to the stream as a list. template RLPStream& append(std::vector<_T> const& _s) { return appendVector(_s); } template RLPStream& appendVector(std::vector<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } - template RLPStream& append(std::array<_T, S> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } - template RLPStream& append(std::set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } - template RLPStream& append(std::unordered_set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } - template RLPStream& append(std::pair const& _s) { appendList(2); append(_s.first); append(_s.second); return *this; } /// Appends a list. RLPStream& appendList(size_t _items); RLPStream& appendList(bytesConstRef _rlp); RLPStream& appendList(bytes const& _rlp) { return appendList(&_rlp); } - RLPStream& appendList(RLPStream const& _s) { return appendList(&_s.out()); } /// Appends raw (pre-serialised) RLP data. Use with caution. RLPStream& appendRaw(bytesConstRef _rlp, size_t _itemCount = 1); - RLPStream& appendRaw(bytes const& _rlp, size_t _itemCount = 1) { return appendRaw(&_rlp, _itemCount); } /// Shift operators for appending data items. template RLPStream& operator<<(T _data) { return append(_data); } @@ -393,12 +369,6 @@ public: /// Read the byte stream. bytes const& out() const { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); return m_out; } - /// Invalidate the object and steal the output byte stream. - bytes&& invalidate() { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); return std::move(m_out); } - - /// Swap the contents of the output stream out for some other byte array. - void swapOut(bytes& _dest) { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); swap(m_out, _dest); } - private: void noteAppended(size_t _itemCount = 1); @@ -421,28 +391,4 @@ private: std::vector> m_listStack; }; -template void rlpListAux(RLPStream& _out, _T _t) { _out << _t; } -template void rlpListAux(RLPStream& _out, _T _t, _Ts ... _ts) { rlpListAux(_out << _t, _ts...); } - -/// Export a single item in RLP format, returning a byte array. -template bytes rlp(_T _t) { return (RLPStream() << _t).out(); } - -/// Export a list of items in RLP format, returning a byte array. -inline bytes rlpList() { return RLPStream(0).out(); } -template bytes rlpList(_Ts ... _ts) -{ - RLPStream out(sizeof ...(_Ts)); - rlpListAux(out, _ts...); - return out.out(); -} - -/// The empty string in RLP format. -extern bytes RLPNull; - -/// The empty list in RLP format. -extern bytes RLPEmptyList; - -/// Human readable version of RLP. -std::ostream& operator<<(std::ostream& _out, dev::RLP const& _d); - } diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index 3f4fd2c96..89e072ede 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -20,15 +20,13 @@ */ #include "SHA3.h" -#include "RLP.h" + using namespace std; using namespace dev; namespace dev { -h256 EmptyListSHA3 = sha3(rlpList()); - namespace keccak { diff --git a/libdevcore/SHA3.h b/libdevcore/SHA3.h index 00c61b721..db2bda45e 100644 --- a/libdevcore/SHA3.h +++ b/libdevcore/SHA3.h @@ -45,6 +45,4 @@ inline h256 sha3(bytes const& _input) { return sha3(bytesConstRef(&_input)); } /// Calculate SHA3-256 hash of the given input (presented as a FixedHash), returns a 256-bit hash. template inline h256 sha3(FixedHash const& _input) { return sha3(_input.ref()); } -extern h256 EmptyListSHA3; - } From fa4c7fbb4779d09fbb081def68bfc89de82dd240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 23:14:21 +0200 Subject: [PATCH 09/11] Remove CPU miner leftovers --- ethminer/MinerAux.h | 32 +++++++------------------------ libethcore/Miner.h | 5 ++--- libstratum/EthStratumClient.cpp | 4 +--- libstratum/EthStratumClientV2.cpp | 4 +--- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 857ca9812..284149d1a 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -81,7 +81,6 @@ public: enum class OperationMode { None, - DAGInit, Benchmark, Simulation, Farm, @@ -380,8 +379,6 @@ public: cerr << "Bad " << arg << " option: " << argv[i] << endl; BOOST_THROW_EXCEPTION(BadArgument()); } - else if (arg == "-C" || arg == "--cpu") - m_minerType = MinerType::CPU; else if (arg == "-G" || arg == "--opencl") m_minerType = MinerType::CL; else if (arg == "-U" || arg == "--cuda") @@ -464,17 +461,10 @@ public: if (m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed) EthashCUDAMiner::listDevices(); #endif - if (m_minerType == MinerType::CPU) - cout << "--list-devices should be combined with GPU mining flag (-G for OpenCL or -U for CUDA)" << endl; exit(0); } - if (m_minerType == MinerType::CPU) - { - cout << "CPU mining is no longer supported in this miner. Use -G (opencl) or -U (cuda) flag to select GPU platform." << endl; - exit(0); - } - else if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed) + if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed) { #if ETH_ETHASHCL if (m_openclDeviceCount > 0) @@ -605,8 +595,6 @@ public: ; } - MinerType minerType() const { return m_minerType; } - private: void doBenchmark(MinerType _m, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5) @@ -627,7 +615,7 @@ private: f.setSealers(sealers); f.onSolutionFound([&](Solution) { return false; }); - string platformInfo = _m == MinerType::CPU ? "CPU" : (_m == MinerType::CL ? "CL" : "CUDA"); + string platformInfo = _m == MinerType::CL ? "CL" : "CUDA"; cout << "Benchmarking on platform: " << platformInfo << endl; cout << "Preparing DAG for block #" << m_benchmarkBlock << endl; @@ -635,9 +623,7 @@ private: genesis.setDifficulty(u256(1) << 63); f.setWork(genesis); - if (_m == MinerType::CPU) - f.start("cpu", false); - else if (_m == MinerType::CL) + if (_m == MinerType::CL) f.start("opencl", false); else if (_m == MinerType::CUDA) f.start("cuda", false); @@ -692,7 +678,7 @@ private: #endif f.setSealers(sealers); - string platformInfo = _m == MinerType::CPU ? "CPU" : (_m == MinerType::CL ? "CL" : "CUDA"); + string platformInfo = _m == MinerType::CL ? "CL" : "CUDA"; cout << "Running mining simulation on platform: " << platformInfo << endl; cout << "Preparing DAG for block #" << m_benchmarkBlock << endl; @@ -701,9 +687,7 @@ private: genesis.setDifficulty(u256(1) << difficulty); f.setWork(genesis); - if (_m == MinerType::CPU) - f.start("cpu", false); - else if (_m == MinerType::CL) + if (_m == MinerType::CL) f.start("opencl", false); else if (_m == MinerType::CUDA) f.start("cuda", false); @@ -782,9 +766,7 @@ private: h256 id = h256::random(); Farm f; f.setSealers(sealers); - if (_m == MinerType::CPU) - f.start("cpu", false); - else if (_m == MinerType::CL) + if (_m == MinerType::CL) f.start("opencl", false); else if (_m == MinerType::CUDA) f.start("cuda", false); @@ -1019,7 +1001,7 @@ private: /// Mining options bool m_running = true; - MinerType m_minerType = MinerType::CPU; + MinerType m_minerType = MinerType::Mixed; unsigned m_openclPlatform = 0; unsigned m_openclDevice = 0; unsigned m_miningThreads = UINT_MAX; diff --git a/libethcore/Miner.h b/libethcore/Miner.h index 689649cab..203fbdea6 100644 --- a/libethcore/Miner.h +++ b/libethcore/Miner.h @@ -61,10 +61,9 @@ namespace eth enum class MinerType { - CPU, + Mixed, CL, - CUDA, - Mixed + CUDA }; /// Describes the progress of a mining operation. diff --git a/libstratum/EthStratumClient.cpp b/libstratum/EthStratumClient.cpp index 89c114eef..36ce28b8d 100644 --- a/libstratum/EthStratumClient.cpp +++ b/libstratum/EthStratumClient.cpp @@ -176,9 +176,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp: if (!p_farm->isMining()) { cnote << "Starting farm"; - if (m_minerType == MinerType::CPU) - p_farm->start("cpu", false); - else if (m_minerType == MinerType::CL) + if (m_minerType == MinerType::CL) p_farm->start("opencl", false); else if (m_minerType == MinerType::CUDA) p_farm->start("cuda", false); diff --git a/libstratum/EthStratumClientV2.cpp b/libstratum/EthStratumClientV2.cpp index 5284b9395..7bc9823ed 100644 --- a/libstratum/EthStratumClientV2.cpp +++ b/libstratum/EthStratumClientV2.cpp @@ -141,9 +141,7 @@ void EthStratumClientV2::connect() if (!p_farm->isMining()) { cnote << "Starting farm"; - if (m_minerType == MinerType::CPU) - p_farm->start("cpu", false); - else if (m_minerType == MinerType::CL) + if (m_minerType == MinerType::CL) p_farm->start("opencl", false); else if (m_minerType == MinerType::CUDA) p_farm->start("cuda", false); From 784af6c79a6b3d1ebb04c90d60ab53ce5c69fb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Jul 2017 23:20:05 +0200 Subject: [PATCH 10/11] Remove SpinLock --- libdevcore/Guards.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/libdevcore/Guards.h b/libdevcore/Guards.h index a65695863..064be8ab5 100644 --- a/libdevcore/Guards.h +++ b/libdevcore/Guards.h @@ -39,18 +39,6 @@ struct GenericGuardBool: GuardType bool b = true; }; -/** @brief Simple lock that waits for release without making context switch */ -class SpinLock -{ -public: - SpinLock() { m_lock.clear(); } - void lock() { while (m_lock.test_and_set(std::memory_order_acquire)) {} } - void unlock() { m_lock.clear(std::memory_order_release); } -private: - std::atomic_flag m_lock; -}; -using SpinGuard = std::lock_guard; - template class Notified { From 93dbb73095eedc401e85601829932cb738e973ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 4 Jul 2017 10:43:35 +0200 Subject: [PATCH 11/11] CUDA: Add Compute 6.0 architecture --- libethash-cuda/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libethash-cuda/CMakeLists.txt b/libethash-cuda/CMakeLists.txt index fac71a6b2..be0239d99 100644 --- a/libethash-cuda/CMakeLists.txt +++ b/libethash-cuda/CMakeLists.txt @@ -15,6 +15,7 @@ else() "-gencode arch=compute_35,code=sm_35" "-gencode arch=compute_50,code=sm_50" "-gencode arch=compute_52,code=sm_52" + "-gencode arch=compute_60,code=sm_60" "-gencode arch=compute_61,code=sm_61" ) endif()