diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 0d4a7a4bc..389664c99 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -17,7 +17,7 @@ set(ETH_GENERATED_DIR "${PROJECT_BINARY_DIR}/gen") include_directories(${ETH_GENERATED_DIR}) # custom cmake scripts -set(ETH_SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/cmake/scripts) +set(ETH_SCRIPTS_DIR ${CMAKE_CURRENT_LIST_DIR}/scripts) # Qt5 requires opengl # TODO use proper version of windows SDK (32 vs 64) diff --git a/cmake/EthExecutableHelper.cmake b/cmake/EthExecutableHelper.cmake index 40d4ae86a..dd4dafddb 100644 --- a/cmake/EthExecutableHelper.cmake +++ b/cmake/EthExecutableHelper.cmake @@ -95,7 +95,7 @@ macro(eth_install_executable EXECUTABLE) add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${MACDEPLOYQT_APP} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app -executable=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app/Contents/MacOS/${EXECUTABLE} ${eth_qml_dir} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/scripts/macdeployfix.sh ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app/Contents + COMMAND sh ${ETH_SCRIPTS_DIR}/macdeployfix.sh ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app/Contents ) # This tool and next will inspect linked libraries in order to determine which dependencies are required diff --git a/ethminer/FarmClient.h b/ethminer/FarmClient.h index 7f5f29182..3a8dded2d 100644 --- a/ethminer/FarmClient.h +++ b/ethminer/FarmClient.h @@ -34,7 +34,7 @@ class FarmClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_submitHashrate(int param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + bool eth_submitHashrate(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index d862729de..84cd69c2c 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -515,7 +516,7 @@ private: auto rate = mp.rate(); try { - rpc.eth_submitHashrate((int)rate, "0x" + id.hex()); + rpc.eth_submitHashrate(toJS((u256)rate), "0x" + id.hex()); } catch (jsonrpc::JsonRpcException const& _e) { diff --git a/ethminer/farm.json b/ethminer/farm.json index 4d4981510..8e40fd85b 100644 --- a/ethminer/farm.json +++ b/ethminer/farm.json @@ -1,7 +1,7 @@ [ { "name": "eth_getWork", "params": [], "order": [], "returns": []}, { "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true}, - { "name": "eth_submitHashrate", "params": [0, ""], "order": [], "returns": true}, + { "name": "eth_submitHashrate", "params": ["", ""], "order": [], "returns": true}, { "name": "eth_awaitNewWork", "params": [], "order": [], "returns": []}, { "name": "eth_progress", "params": [], "order": [], "returns": true} ] diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 7a6e7ff55..3e5231b6e 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -20,6 +20,7 @@ */ #include "CommonData.h" +#include #include #include "Exceptions.h" #include "Log.h" diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index ee77b1431..fc928f47a 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -113,9 +113,7 @@ inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } inline int jsToInt(std::string const& _s) { - if (_s.size() > 2 && _s.substr(0, 2).compare("0x") == 0) - return std::stoi(_s, nullptr, 16); - return std::stoi(_s, nullptr, 10); + return std::stoi(_s, nullptr, 0); } inline std::string jsToDecimal(std::string const& _s) diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 973bc174e..8beb3bec7 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -149,18 +149,16 @@ public: /// @returns a constant reference to the object's data as an STL array. std::array const& asArray() const { return m_data; } - /// @returns a randomly-valued hash + /// Populate with random data. template - static FixedHash random(Engine& _eng) + void randomize(Engine& _eng) { - FixedHash ret; - for (auto& i: ret.m_data) + for (auto& i: m_data) i = (uint8_t)boost::random::uniform_int_distribution(0, 255)(_eng); - return ret; } /// @returns a random valued object. - static FixedHash random() { return random(s_fixedHashEngine); } + static FixedHash random() { FixedHash ret; ret.randomize(s_fixedHashEngine); return ret; } struct hash { @@ -293,7 +291,7 @@ public: bytesConstRef ref() const { return FixedHash::ref(); } byte const* data() const { return FixedHash::data(); } - static SecureFixedHash random() { SecureFixedHash ret; ret.FixedHash::ref().randomize(); return ret; } + static SecureFixedHash random() { SecureFixedHash ret; ret.randomize(s_fixedHashEngine); return ret; } using FixedHash::firstBitSet; void clear() { ref().cleanse(); } diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index b5d0453a6..6fb9ad3b5 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -5,16 +5,10 @@ #include #include #include -#include -#include -#include namespace dev { -static unsigned char s_cleanseCounter = 0; -static boost::random_device s_vectorRefEngine; - /** * A modifiable reference to an existing object or vector in memory. */ @@ -71,20 +65,11 @@ public: void copyTo(vector_ref::type> _t) const { if (overlapsWith(_t)) memmove(_t.data(), m_data, std::min(_t.size(), m_count) * sizeof(_T)); else memcpy(_t.data(), m_data, std::min(_t.size(), m_count) * sizeof(_T)); } /// Copies the contents of this vector_ref to the contents of @a _t, and zeros further trailing elements in @a _t. void populate(vector_ref::type> _t) const { copyTo(_t); memset(_t.data() + m_count, 0, std::max(_t.size(), m_count) - m_count); } - /// Populate with random data. - template - void randomize(Engine& _eng) - { - uint8_t* e = (uint8_t*)end(); - for (uint8_t* i = (uint8_t*)begin(); i != e; ++i) - *i = (uint8_t)boost::random::uniform_int_distribution(0, 255)(_eng); - } - /// @returns a random valued object. - void randomize() { randomize(s_vectorRefEngine); } /// Securely overwrite the memory. /// @note adapted from OpenSSL's implementation. void cleanse() { + static unsigned char s_cleanseCounter = 0; uint8_t* p = (uint8_t*)begin(); size_t const len = (uint8_t*)end() - p; size_t loop = len; diff --git a/libethcore/EthashCPUMiner.cpp b/libethcore/EthashCPUMiner.cpp index 0c645c831..6c7097605 100644 --- a/libethcore/EthashCPUMiner.cpp +++ b/libethcore/EthashCPUMiner.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #if ETH_CPUID || !ETH_TRUE #define HAVE_STDINT_H #include @@ -78,7 +79,7 @@ void EthashCPUMiner::workLoop() auto tid = std::this_thread::get_id(); static std::mt19937_64 s_eng((time(0) + std::hash()(tid))); - uint64_t tryNonce = (uint64_t)(u64)Nonce::random(s_eng); + uint64_t tryNonce = s_eng(); ethash_return_value ethashReturn; WorkPackage w = work(); diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 3a6087ea5..031af59e8 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -507,9 +507,9 @@ WorkingProgress Client::miningProgress() const return WorkingProgress(); } -uint64_t Client::hashrate() const +u256 Client::hashrate() const { - uint64_t r = externalHashrate(); + u256 r = externalHashrate(); if (Ethash::isWorking(m_sealEngine.get())) r += Ethash::workingProgress(m_sealEngine.get()).rate(); return r; diff --git a/libethereum/Client.h b/libethereum/Client.h index a7d184d76..f7b5eefad 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -171,7 +171,7 @@ public: /// Are we mining now? bool wouldMine() const override { return m_wouldMine; } /// The hashrate... - uint64_t hashrate() const override; + u256 hashrate() const override; /// Check the progress of the mining. WorkingProgress miningProgress() const override; /// Get and clear the mining history. diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index f11d533a6..1d230a9b3 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -524,14 +524,14 @@ bool ClientBase::isKnownTransaction(h256 const& _blockHash, unsigned _i) const return isKnown(_blockHash) && bc().transactions().size() > _i; } -void ClientBase::submitExternalHashrate(int _rate, h256 const& _id) +void ClientBase::submitExternalHashrate(u256 const& _rate, h256 const& _id) { m_externalRates[_id] = make_pair(_rate, chrono::steady_clock::now()); } -uint64_t ClientBase::externalHashrate() const +u256 ClientBase::externalHashrate() const { - uint64_t ret = 0; + u256 ret = 0; for (auto i = m_externalRates.begin(); i != m_externalRates.end();) if (chrono::steady_clock::now() - i->second.second > chrono::seconds(5)) i = m_externalRates.erase(i); diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 504fb2dbd..c942c459d 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -164,10 +164,10 @@ public: virtual void stopMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::stopMining")); } virtual bool isMining() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::isMining")); } virtual bool wouldMine() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::wouldMine")); } - virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::hashrate")); } + virtual u256 hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::hashrate")); } virtual WorkingProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::miningProgress")); } - virtual void submitExternalHashrate(int _rate, h256 const& _id) override; + virtual void submitExternalHashrate(u256 const& _rate, h256 const& _id) override; Block asOf(BlockNumber _h) const; @@ -182,7 +182,7 @@ protected: virtual void prepareForTransaction() = 0; /// } - uint64_t externalHashrate() const; + u256 externalHashrate() const; TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain. @@ -194,7 +194,7 @@ protected: std::map m_watches; ///< Each and every watch - these reference a filter. // external hashrate - mutable std::unordered_map> m_externalRates; + mutable std::unordered_map> m_externalRates; }; }} diff --git a/libethereum/Interface.h b/libethereum/Interface.h index ed9659f3b..e7bbb5e4f 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -211,14 +211,14 @@ public: /// Would we like to mine now? virtual bool wouldMine() const = 0; /// Current hash rate. - virtual uint64_t hashrate() const = 0; + virtual u256 hashrate() const = 0; /// Get hash of the current block to be mined minus the nonce (the 'work hash'). virtual std::tuple getEthashWork() { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::getEthashWork")); } /// Submit the nonce for the proof-of-work. virtual bool submitEthashWork(h256 const&, h64 const&) { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::submitEthashWork")); } /// Submit the ongoing hashrate of a particular external miner. - virtual void submitExternalHashrate(int, h256 const&) { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::submitExternalHashrate")); } + virtual void submitExternalHashrate(u256 const&, h256 const&) { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::submitExternalHashrate")); } /// Check the progress of the mining. virtual WorkingProgress miningProgress() const = 0; diff --git a/libethereum/TransactionQueue.cpp b/libethereum/TransactionQueue.cpp index bf8e14a27..74a49d841 100644 --- a/libethereum/TransactionQueue.cpp +++ b/libethereum/TransactionQueue.cpp @@ -294,6 +294,7 @@ void TransactionQueue::setFuture(h256 const& _txHash) void TransactionQueue::makeCurrent_WITH_LOCK(Transaction const& _t) { + bool newCurrent = false; auto fs = m_future.find(_t.from()); if (fs != m_future.end()) { @@ -311,6 +312,7 @@ void TransactionQueue::makeCurrent_WITH_LOCK(Transaction const& _t) --m_futureSize; ++ft; ++nonce; + newCurrent = true; } fs->second.erase(fb, ft); if (fs->second.empty()) @@ -328,6 +330,9 @@ void TransactionQueue::makeCurrent_WITH_LOCK(Transaction const& _t) if (m_future.begin()->second.empty()) m_future.erase(m_future.begin()); } + + if (newCurrent) + m_onReady(); } void TransactionQueue::drop(h256 const& _txHash) diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 03b2be8d8..11dae47cc 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -780,9 +780,9 @@ bool WebThreeStubServerBase::eth_submitWork(string const& _nonce, string const&, } } -bool WebThreeStubServerBase::eth_submitHashrate(int _hashes, string const& _id) +bool WebThreeStubServerBase::eth_submitHashrate(string const& _hashes, string const& _id) { - client()->submitExternalHashrate(_hashes, jsToFixed<32>(_id)); + client()->submitExternalHashrate(jsToInt<32>(_hashes), jsToFixed<32>(_id)); return true; } diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index f4ca99d83..9db4e7854 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -139,7 +139,7 @@ public: virtual Json::Value eth_getLogsEx(Json::Value const& _json); virtual Json::Value eth_getWork(); virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash); - virtual bool eth_submitHashrate(int _hashes, std::string const& _id); + virtual bool eth_submitHashrate(std::string const& _hashes, std::string const& _id); virtual std::string eth_register(std::string const& _address); virtual bool eth_unregister(std::string const& _accountId); virtual Json::Value eth_fetchQueuedTransactions(std::string const& _accountId); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index 0009fdcc2..9dba0bd1a 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -60,7 +60,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("eth_getLogsEx", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_getLogsExI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_getWorkI); this->bindAndAddMethod(jsonrpc::Procedure("eth_submitWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitWorkI); - this->bindAndAddMethod(jsonrpc::Procedure("eth_submitHashrate", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitHashrateI); + this->bindAndAddMethod(jsonrpc::Procedure("eth_submitHashrate", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitHashrateI); this->bindAndAddMethod(jsonrpc::Procedure("eth_register", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_registerI); this->bindAndAddMethod(jsonrpc::Procedure("eth_unregister", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_unregisterI); this->bindAndAddMethod(jsonrpc::Procedure("eth_fetchQueuedTransactions", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_fetchQueuedTransactionsI); @@ -315,7 +315,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_submitHashrate(request[0u].asInt(), request[1u].asString()); + response = this->eth_submitHashrate(request[0u].asString(), request[1u].asString()); } inline virtual void eth_registerI(const Json::Value &request, Json::Value &response) { @@ -534,7 +534,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer