Browse Source

Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop

cl-refactor
Gav Wood 9 years ago
parent
commit
c0c64ada03
  1. 2
      cmake/EthDependencies.cmake
  2. 2
      cmake/EthExecutableHelper.cmake
  3. 2
      ethminer/FarmClient.h
  4. 3
      ethminer/MinerAux.h
  5. 2
      ethminer/farm.json
  6. 1
      libdevcore/CommonData.cpp
  7. 4
      libdevcore/CommonJS.h
  8. 12
      libdevcore/FixedHash.h
  9. 17
      libdevcore/vector_ref.h
  10. 3
      libethcore/EthashCPUMiner.cpp
  11. 4
      libethereum/Client.cpp
  12. 2
      libethereum/Client.h
  13. 6
      libethereum/ClientBase.cpp
  14. 8
      libethereum/ClientBase.h
  15. 4
      libethereum/Interface.h
  16. 5
      libethereum/TransactionQueue.cpp
  17. 4
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  18. 2
      libweb3jsonrpc/WebThreeStubServerBase.h
  19. 6
      libweb3jsonrpc/abstractwebthreestubserver.h
  20. 2
      libweb3jsonrpc/spec.json
  21. 2
      mix/MixClient.cpp
  22. 2
      mix/MixClient.h
  23. 25
      test/libdevcrypto/SecretStore.cpp
  24. 39
      test/libethereum/StateTestsFiller/stSpecialTestFiller.json
  25. 2
      test/libweb3jsonrpc/webthreestubclient.h

2
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)

2
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

2
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);

3
ethminer/MinerAux.h

@ -37,6 +37,7 @@
#include <libdevcore/StructuredLogger.h>
#include <libethcore/Exceptions.h>
#include <libdevcore/SHA3.h>
#include <libdevcore/CommonJS.h>
#include <libethcore/EthashAux.h>
#include <libethcore/EthashGPUMiner.h>
#include <libethcore/EthashCPUMiner.h>
@ -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)
{

2
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}
]

1
libdevcore/CommonData.cpp

@ -20,6 +20,7 @@
*/
#include "CommonData.h"
#include <random>
#include <boost/random/uniform_int_distribution.hpp>
#include "Exceptions.h"
#include "Log.h"

4
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)

12
libdevcore/FixedHash.h

@ -149,18 +149,16 @@ public:
/// @returns a constant reference to the object's data as an STL array.
std::array<byte, N> const& asArray() const { return m_data; }
/// @returns a randomly-valued hash
/// Populate with random data.
template <class Engine>
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<uint16_t>(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<T>::ref(); }
byte const* data() const { return FixedHash<T>::data(); }
static SecureFixedHash<T> random() { SecureFixedHash<T> ret; ret.FixedHash<T>::ref().randomize(); return ret; }
static SecureFixedHash<T> random() { SecureFixedHash<T> ret; ret.randomize(s_fixedHashEngine); return ret; }
using FixedHash<T>::firstBitSet;
void clear() { ref().cleanse(); }

17
libdevcore/vector_ref.h

@ -5,16 +5,10 @@
#include <type_traits>
#include <vector>
#include <string>
#include <random>
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
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<typename std::remove_const<_T>::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<typename std::remove_const<_T>::type> _t) const { copyTo(_t); memset(_t.data() + m_count, 0, std::max(_t.size(), m_count) - m_count); }
/// Populate with random data.
template <class Engine>
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<uint16_t>(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;

3
libethcore/EthashCPUMiner.cpp

@ -25,6 +25,7 @@
#include <thread>
#include <chrono>
#include <boost/algorithm/string.hpp>
#include <random>
#if ETH_CPUID || !ETH_TRUE
#define HAVE_STDINT_H
#include <libcpuid/libcpuid.h>
@ -78,7 +79,7 @@ void EthashCPUMiner::workLoop()
auto tid = std::this_thread::get_id();
static std::mt19937_64 s_eng((time(0) + std::hash<decltype(tid)>()(tid)));
uint64_t tryNonce = (uint64_t)(u64)Nonce::random(s_eng);
uint64_t tryNonce = s_eng();
ethash_return_value ethashReturn;
WorkPackage w = work();

4
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;

2
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.

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

8
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<unsigned, ClientWatch> m_watches; ///< Each and every watch - these reference a filter.
// external hashrate
mutable std::unordered_map<h256, std::pair<uint64_t, std::chrono::steady_clock::time_point>> m_externalRates;
mutable std::unordered_map<h256, std::pair<u256, std::chrono::steady_clock::time_point>> m_externalRates;
};
}}

4
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<h256, h256, h256> 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;

5
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)

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

2
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);

6
libweb3jsonrpc/abstractwebthreestubserver.h

@ -60,7 +60,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(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::AbstractServer<AbstractWebThr
}
inline virtual void eth_submitHashrateI(const Json::Value &request, Json::Value &response)
{
response = this->eth_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<AbstractWebThr
virtual Json::Value eth_getLogsEx(const Json::Value& param1) = 0;
virtual Json::Value eth_getWork() = 0;
virtual bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) = 0;
virtual bool eth_submitHashrate(int param1, const std::string& param2) = 0;
virtual bool eth_submitHashrate(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_register(const std::string& param1) = 0;
virtual bool eth_unregister(const std::string& param1) = 0;
virtual Json::Value eth_fetchQueuedTransactions(const std::string& param1) = 0;

2
libweb3jsonrpc/spec.json

@ -49,7 +49,7 @@
{ "name": "eth_getLogsEx", "params": [{}], "order": [], "returns": []},
{ "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_register", "params": [""], "order": [], "returns": ""},
{ "name": "eth_unregister", "params": [""], "order": [], "returns": true},
{ "name": "eth_fetchQueuedTransactions", "params": [""], "order": [], "returns": []},

2
mix/MixClient.cpp

@ -370,7 +370,7 @@ bool MixClient::isMining() const
return false;
}
uint64_t MixClient::hashrate() const
u256 MixClient::hashrate() const
{
return 0;
}

2
mix/MixClient.h

@ -95,7 +95,7 @@ public:
void startMining() override;
void stopMining() override;
bool isMining() const override;
uint64_t hashrate() const override;
u256 hashrate() const override;
eth::WorkingProgress miningProgress() const override;
virtual void flushTransactions() override {}

25
test/libdevcrypto/SecretStore.cpp

@ -131,6 +131,31 @@ BOOST_AUTO_TEST_CASE(import_secret)
}
}
BOOST_AUTO_TEST_CASE(import_secret_bytesConstRef)
{
for (string const& password: {"foobar", ""})
{
TransientDirectory storeDir;
string priv = "0202020202020202020202020202020202020202020202020202020202020202";
h128 uuid;
{
SecretStore store(storeDir.path());
BOOST_CHECK_EQUAL(store.keys().size(), 0);
bytes privateBytes = fromHex(priv);
uuid = store.importSecret(&privateBytes, password);
BOOST_CHECK(!!uuid);
BOOST_CHECK_EQUAL(priv, toHex(store.secret(uuid, [&](){ return password; }).makeInsecure()));
BOOST_CHECK_EQUAL(store.keys().size(), 1);
}
{
SecretStore store(storeDir.path());
BOOST_CHECK_EQUAL(store.keys().size(), 1);
BOOST_CHECK_EQUAL(priv, toHex(store.secret(uuid, [&](){ return password; }).makeInsecure()));
}
}
}
BOOST_AUTO_TEST_CASE(wrong_password)
{
TransientDirectory storeDir;

39
test/libethereum/StateTestsFiller/stSpecialTestFiller.json

@ -531,5 +531,44 @@
"to" : "1baf27b88c48dd02b744999cf3522766929d2b2a",
"value" : "0"
}
},
"StackDepthLimitSEC" : {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : 1,
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"expect" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000"
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "771500"
},
"aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000000000000000000"
}
},
"pre" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "100000000",
"nonce" : "0",
"code" : "",
"storage": {}
}
},
"transaction" : {
"nonce" : "0",
"gasPrice" : "1",
"gasLimit" : "1000000",
"to" : "",
"value" : "10",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"data" : "305032503350600460006000396000515060046000600037600051506f600060006000600060003060405a03f160005260106010f3"
}
}
}

2
test/libweb3jsonrpc/webthreestubclient.h

@ -506,7 +506,7 @@ class WebThreeStubClient : 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);

Loading…
Cancel
Save