Browse Source

Merge branch 'develop' into neighbours

cl-refactor
subtly 10 years ago
parent
commit
454795cb69
  1. 13
      CMakeLists.txt
  2. 18
      alethzero/Main.ui
  3. 3
      alethzero/MainWin.cpp
  4. 4
      eth/main.cpp
  5. 3
      exp/CMakeLists.txt
  6. 24
      libethcore/ProofOfWork.cpp
  7. 34
      libethcore/ProofOfWork.h
  8. 18
      libethereum/Client.cpp
  9. 20
      libethereum/Client.h
  10. 3
      libethereum/ClientBase.h
  11. 4
      libethereum/Interface.h
  12. 4
      libethereum/Miner.cpp
  13. 13
      libethereum/Miner.h
  14. 27
      libethereum/State.cpp
  15. 22
      libethereum/State.h
  16. 17
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  17. 1
      libweb3jsonrpc/WebThreeStubServerBase.h
  18. 7
      libweb3jsonrpc/abstractwebthreestubserver.h
  19. 5
      libweb3jsonrpc/spec.json
  20. 10
      mix/MixClient.cpp
  21. 3
      mix/MixClient.h
  22. 34
      mix/qml/Debugger.qml
  23. 122
      mix/qml/StepActionImage.qml
  24. 7
      test/blockchain.cpp
  25. 5
      test/stateOriginal.cpp
  26. 10
      test/webthreestubclient.h

13
CMakeLists.txt

@ -62,6 +62,8 @@ function(configureProject)
if (GUI)
add_definitions(-DETH_GUI)
endif()
add_definitions(-DETH_TRUE)
endfunction()
set(CPPETHEREUM 1)
@ -134,7 +136,6 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
endif ()
createDefaultCacheConfig()
configureProject()
# Force chromium.
set (ETH_HAVE_WEBENGINE 1)
@ -261,6 +262,8 @@ elseif (BUNDLE STREQUAL "user")
set(TESTS OFF)
endif ()
configureProject()
# Default CMAKE_BUILD_TYPE to "Release".
set(CMAKE_BUILD_TYPE CACHE STRING "Release")
if ("x${CMAKE_BUILD_TYPE}" STREQUAL "x")
@ -270,7 +273,11 @@ endif ()
# Default TARGET_PLATFORM to "linux".
set(TARGET_PLATFORM CACHE STRING "linux")
if ("x${TARGET_PLATFORM}" STREQUAL "x")
set(TARGET_PLATFORM "linux")
if (WIN32)
set(TARGET_PLATFORM "windows")
else ()
set(TARGET_PLATFORM "linux")
endif ()
endif ()
message("------------------------------------------------------------------------")
@ -306,7 +313,7 @@ include(EthCompilerSettings)
message("-- CXXFLAGS: ${CMAKE_CXX_FLAGS}")
# this must be an include, as a function it would messs up with variable scope!
# this must be an include, as a function it would mess up with variable scope!
include(EthDependencies)
include(EthExecutableHelper)

18
alethzero/Main.ui

@ -150,6 +150,7 @@
<string>&amp;Tools</string>
</property>
<addaction name="mine"/>
<addaction name="turboMining"/>
<addaction name="separator"/>
<addaction name="newTransaction"/>
<addaction name="newAccount"/>
@ -176,7 +177,6 @@
<addaction name="killBlockchain"/>
<addaction name="inject"/>
<addaction name="forceMining"/>
<addaction name="turboMining"/>
<addaction name="separator"/>
<addaction name="usePrivate"/>
<addaction name="jitvm"/>
@ -1608,14 +1608,6 @@ font-size: 14pt</string>
<string>&amp;Enable LLL Optimizer</string>
</property>
</action>
<action name="turboMining">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Reserved Debug 1</string>
</property>
</action>
<action name="localNetworking">
<property name="checkable">
<bool>true</bool>
@ -1679,6 +1671,14 @@ font-size: 14pt</string>
<string>&amp;NatSpec Enabled</string>
</property>
</action>
<action name="turboMining">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;GPU Mining</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

3
alethzero/MainWin.cpp

@ -707,6 +707,7 @@ void Main::writeSettings()
s.setValue("upnp", ui->upnp->isChecked());
s.setValue("forceAddress", ui->forcePublicIP->text());
s.setValue("forceMining", ui->forceMining->isChecked());
s.setValue("turboMining", ui->turboMining->isChecked());
s.setValue("paranoia", ui->paranoia->isChecked());
s.setValue("natSpec", ui->natSpec->isChecked());
s.setValue("showAll", ui->showAll->isChecked());
@ -777,6 +778,8 @@ void Main::readSettings(bool _skipGeometry)
ui->dropPeers->setChecked(false);
ui->forceMining->setChecked(s.value("forceMining", false).toBool());
on_forceMining_triggered();
ui->turboMining->setChecked(s.value("turboMining", false).toBool());
on_turboMining_triggered();
ui->paranoia->setChecked(s.value("paranoia", false).toBool());
ui->natSpec->setChecked(s.value("natSpec", true).toBool());
ui->showAll->setChecked(s.value("showAll", false).toBool());

4
eth/main.cpp

@ -273,7 +273,6 @@ int main(int argc, char** argv)
unsigned mining = ~(unsigned)0;
int miners = -1;
bool forceMining = false;
bool turboMining = false;
KeyPair us = KeyPair::create();
Address coinbase = us.address();
@ -466,8 +465,6 @@ int main(int argc, char** argv)
bootstrap = true;
else if (arg == "-f" || arg == "--force-mining")
forceMining = true;
else if (arg == "-T" || arg == "--turbo-mining")
turboMining = true;
else if (arg == "-i" || arg == "--interactive")
interactive = true;
#if ETH_JSONRPC
@ -632,7 +629,6 @@ int main(int argc, char** argv)
{
c->setGasPricer(gasPricer);
c->setForceMining(forceMining);
c->setTurboMining(turboMining);
c->setAddress(coinbase);
}

3
exp/CMakeLists.txt

@ -23,10 +23,11 @@ endif()
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} p2p)
if (ETHASHCL)
target_link_libraries(${EXECUTABLE} ethash-cl)
target_link_libraries(${EXECUTABLE} ethash)
target_link_libraries(${EXECUTABLE} OpenCL)
endif()
install( TARGETS ${EXECUTABLE} DESTINATION bin)

24
libethcore/ProofOfWork.cpp

@ -45,12 +45,12 @@ namespace dev
namespace eth
{
bool EthashCPU::verify(BlockInfo const& _header)
bool EthashPoW::verify(BlockInfo const& _header)
{
return Ethasher::verify(_header);
}
std::pair<MineInfo, EthashCPU::Proof> EthashCPU::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue, bool _turbo)
std::pair<MineInfo, EthashCPU::Proof> EthashCPU::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue)
{
Ethasher::Miner m(_header);
@ -67,8 +67,6 @@ std::pair<MineInfo, EthashCPU::Proof> EthashCPU::mine(BlockInfo const& _header,
//
// evaluate until we run out of time
auto startTime = std::chrono::steady_clock::now();
if (!_turbo)
std::this_thread::sleep_for(std::chrono::milliseconds(_msTimeout * 90 / 100));
double best = 1e99; // high enough to be effectively infinity :)
Proof result;
unsigned hashCount = 0;
@ -102,7 +100,7 @@ std::pair<MineInfo, EthashCPU::Proof> EthashCPU::mine(BlockInfo const& _header,
return ret;
}
#if ETH_ETHASHCL
#if ETH_ETHASHCL || !ETH_TRUE
/*
class ethash_cl_miner
@ -186,12 +184,7 @@ EthashCL::~EthashCL()
{
}
bool EthashCL::verify(BlockInfo const& _header)
{
return Ethasher::verify(_header);
}
std::pair<MineInfo, Ethash::Proof> EthashCL::mine(BlockInfo const& _header, unsigned _msTimeout, bool, bool)
std::pair<MineInfo, Ethash::Proof> EthashCL::mine(BlockInfo const& _header, unsigned _msTimeout, bool)
{
if (!m_lastHeader || m_lastHeader.seedHash() != _header.seedHash())
{
@ -201,16 +194,15 @@ std::pair<MineInfo, Ethash::Proof> EthashCL::mine(BlockInfo const& _header, unsi
auto cb = [&](void* d) {
Ethasher::get()->readFull(_header, d);
};
m_miner->init(Ethasher::params(_header), cb);
m_miner->init(Ethasher::params(_header), cb, 32);
}
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));
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);
uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)_header.boundary() >> 192);
m_miner->search(hh.data(), upper64OfBoundary, *m_hook);
}
m_lastHeader = _header;
@ -221,11 +213,9 @@ std::pair<MineInfo, Ethash::Proof> EthashCL::mine(BlockInfo const& _header, unsi
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());
}

34
libethcore/ProofOfWork.h

@ -51,7 +51,7 @@ struct MineInfo
bool completed = false;
};
class EthashCPU
class EthashPoW
{
public:
struct Proof
@ -61,31 +61,32 @@ public:
};
static bool verify(BlockInfo const& _header);
std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false);
static void assignResult(Proof const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; }
virtual unsigned defaultTimeout() const { return 100; }
virtual std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true) = 0;
};
class EthashCPU: public EthashPoW
{
public:
std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true) override;
protected:
Nonce m_last;
};
#if ETH_ETHASHCL
#if ETH_ETHASHCL || !ETH_TRUE
class EthashCLHook;
class EthashCL
class EthashCL: public EthashPoW
{
public:
struct Proof
{
Nonce nonce;
h256 mixHash;
};
EthashCL();
~EthashCL();
static bool verify(BlockInfo const& _header);
std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false);
static void assignResult(Proof const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; }
std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true) override;
unsigned defaultTimeout() const override { return 500; }
protected:
Nonce m_last;
@ -107,8 +108,9 @@ public:
using Proof = Nonce;
static bool verify(BlockInfo const& _header) { return (bigint)(u256)Evaluator::eval(_header.headerHash(WithoutNonce), _header.nonce) <= (bigint(1) << 256) / _header.difficulty; }
inline std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false);
inline std::pair<MineInfo, Proof> mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true);
static void assignResult(Proof const& _r, BlockInfo& _header) { _header.nonce = _r; }
unsigned defaultTimeout() const { return 100; }
protected:
Nonce m_last;
@ -125,7 +127,7 @@ using SHA3ProofOfWork = ProofOfWorkEngine<SHA3Evaluator>;
using ProofOfWork = Ethash;
template <class Evaluator>
std::pair<MineInfo, typename ProofOfWorkEngine<Evaluator>::Proof> ProofOfWorkEngine<Evaluator>::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue, bool _turbo)
std::pair<MineInfo, typename ProofOfWorkEngine<Evaluator>::Proof> ProofOfWorkEngine<Evaluator>::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue)
{
auto headerHashWithoutNonce = _header.headerHash(WithoutNonce);
auto difficulty = _header.difficulty;
@ -142,8 +144,6 @@ std::pair<MineInfo, typename ProofOfWorkEngine<Evaluator>::Proof> ProofOfWorkEng
//
// evaluate until we run out of time
auto startTime = std::chrono::steady_clock::now();
if (!_turbo)
std::this_thread::sleep_for(std::chrono::milliseconds(_msTimeout * 90 / 100));
double best = 1e99; // high enough to be effectively infinity :)
ProofOfWorkEngine<Evaluator>::Proof solution;
unsigned h = 0;

18
libethereum/Client.cpp

@ -264,7 +264,7 @@ static string filtersToString(T const& _fs)
{
stringstream ret;
ret << "{";
bool i = false;
unsigned i = 0;
for (h256 const& f: _fs)
ret << (i++ ? ", " : "") << (f == PendingChangedFilter ? "pending" : f == ChainChangedFilter ? "chain" : f.abridged());
ret << "}";
@ -345,11 +345,10 @@ void Client::setForceMining(bool _enable)
void Client::setMiningThreads(unsigned _threads)
{
stopMining();
#if ETH_ETHASHCL
(void)_threads;
unsigned t = 1;
#else
auto t = _threads ? _threads : thread::hardware_concurrency();
#if ETH_ETHASHCL || !ETH_TRUE
if (m_turboMining)
t = 1;
#endif
WriteGuard l(x_localMiners);
m_localMiners.clear();
@ -368,6 +367,15 @@ MineProgress Client::miningProgress() const
return ret;
}
uint64_t Client::hashrate() const
{
uint64_t ret = 0;
ReadGuard l(x_localMiners);
for (LocalMiner const& m: m_localMiners)
ret += m.miningProgress().hashes / m.miningProgress().ms;
return ret / 1000;
}
std::list<MineInfo> Client::miningHistory()
{
std::list<MineInfo> ret;

20
libethereum/Client.h

@ -188,25 +188,27 @@ public:
bool forceMining() const { return m_forceMining; }
/// Enable/disable forcing of mining to happen, even without transactions.
void setForceMining(bool _enable);
/// Are we mining as fast as we can?
/// Are we allowed to GPU mine?
bool turboMining() const { return m_turboMining; }
/// Enable/disable fast mining.
void setTurboMining(bool _enable = true) { m_turboMining = _enable; }
/// Enable/disable GPU mining.
void setTurboMining(bool _enable = true) { bool was = isMining(); stopMining(); m_turboMining = _enable; setMiningThreads(0); if (was) startMining(); }
/// Stops mining and sets the number of mining threads (0 for automatic).
virtual void setMiningThreads(unsigned _threads = 0);
void setMiningThreads(unsigned _threads = 0) override;
/// Get the effective number of mining threads.
virtual unsigned miningThreads() const { ReadGuard l(x_localMiners); return m_localMiners.size(); }
unsigned miningThreads() const override { ReadGuard l(x_localMiners); return m_localMiners.size(); }
/// Start mining.
/// NOT thread-safe - call it & stopMining only from a single thread
virtual void startMining() { startWorking(); { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.start(); } }
void startMining() override { startWorking(); { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.start(); } }
/// Stop mining.
/// NOT thread-safe
virtual void stopMining() { { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.stop(); } }
void stopMining() override { { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.stop(); } }
/// Are we mining now?
virtual bool isMining() { { ReadGuard l(x_localMiners); if (!m_localMiners.empty() && m_localMiners[0].isRunning()) return true; } return false; }
bool isMining() const override { { ReadGuard l(x_localMiners); if (!m_localMiners.empty() && m_localMiners[0].isRunning()) return true; } return false; }
/// Are we mining now?
uint64_t hashrate() const override;
/// Check the progress of the mining.
virtual MineProgress miningProgress() const;
MineProgress miningProgress() const override;
/// Get and clear the mining history.
std::list<MineInfo> miningHistory();

3
libethereum/ClientBase.h

@ -146,7 +146,8 @@ public:
virtual unsigned miningThreads() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::miningThreads")); }
virtual void startMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::startMining")); }
virtual void stopMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::stopMining")); }
virtual bool isMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::isMining")); }
virtual bool isMining() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::isMining")); }
virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::hashrate")); }
virtual eth::MineProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::miningProgress")); }
virtual std::pair<h256, u256> getWork() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::getWork")); }
virtual bool submitWork(eth::ProofOfWork::Proof const&) override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::submitWork")); }

4
libethereum/Interface.h

@ -183,7 +183,9 @@ public:
/// NOT thread-safe
virtual void stopMining() = 0;
/// Are we mining now?
virtual bool isMining() = 0;
virtual bool isMining() const = 0;
/// Current hash rate.
virtual uint64_t hashrate() const = 0;
/// Get hash of the current block to be mined minus the nonce (the 'work hash').
virtual std::pair<h256, u256> getWork() = 0;

4
libethereum/Miner.cpp

@ -34,12 +34,14 @@ LocalMiner::LocalMiner(MinerHost* _host, unsigned _id):
AsyncMiner(_host, _id),
Worker("miner-" + toString(_id))
{
m_pow.reset(_host->turbo() ? new Ethash : (Ethash*)new EthashCPU);
}
void LocalMiner::setup(MinerHost* _host, unsigned _id)
{
AsyncMiner::setup(_host, _id);
setName("miner-" + toString(m_id));
m_pow.reset(_host->turbo() ? new Ethash : (Ethash*)new EthashCPU);
}
void LocalMiner::doWork()
@ -66,7 +68,7 @@ void LocalMiner::doWork()
if (m_miningStatus == Mining)
{
// Mine for a while.
MineInfo mineInfo = m_mineState.mine(100, m_host->turbo());
MineInfo mineInfo = m_mineState.mine(m_pow.get());
{
Guard l(x_mineInfo);

13
libethereum/Miner.h

@ -60,8 +60,8 @@ public:
virtual void setupState(State& _s) = 0; ///< Reset the given State object to the one that should be being mined.
virtual void onProgressed() {} ///< Called once some progress has been made.
virtual void onComplete() {} ///< Called once a block is found.
virtual bool turbo() const = 0; ///< @returns true iff the Miner should mine as fast as possible.
virtual bool force() const = 0; ///< @returns true iff the Miner should mine regardless of the number of transactions.
virtual bool turbo() const = 0; ///< @returns true iff the Miner should use GPU if possible.
};
class Miner
@ -93,7 +93,7 @@ public:
virtual void stop() {}
/// @returns true iff the mining has been start()ed. It may still not be actually mining, depending on the host's turbo() & force().
virtual bool isRunning() { return false; }
virtual bool isRunning() const { return false; }
protected:
MinerHost* m_host = nullptr; ///< Our host.
@ -122,10 +122,10 @@ public:
LocalMiner(MinerHost* _host, unsigned _id = 0);
/// Move-constructor.
LocalMiner(LocalMiner&& _m): Worker((Worker&&)_m) { std::swap(m_host, _m.m_host); }
LocalMiner(LocalMiner&& _m): Worker((Worker&&)_m) { std::swap(m_host, _m.m_host); std::swap(m_pow, _m.m_pow); }
/// Move-assignment.
LocalMiner& operator=(LocalMiner&& _m) { Worker::operator=((Worker&&)_m); std::swap(m_host, _m.m_host); return *this; }
LocalMiner& operator=(LocalMiner&& _m) { Worker::operator=((Worker&&)_m); std::swap(m_host, _m.m_host); std::swap(m_pow, _m.m_pow); return *this; }
/// Destructor. Stops miner.
~LocalMiner() { stop(); }
@ -143,7 +143,7 @@ public:
virtual void noteStateChange() override { m_miningStatus = Preparing; }
/// @returns true iff the mining has been start()ed. It may still not be actually mining, depending on the host's turbo() & force().
bool isRunning() { return isWorking(); }
bool isRunning() const override { return isWorking(); }
/// @returns true if mining is complete.
virtual bool isComplete() const override { return m_miningStatus == Mined; }
@ -167,8 +167,9 @@ private:
enum MiningStatus { Waiting, Preparing, Mining, Mined, Stopping, Stopped };
MiningStatus m_miningStatus = Waiting; ///< TODO: consider mutex/atomic variable.
State m_mineState; ///< The state on which we are mining, generally equivalent to m_postMine.
std::unique_ptr<EthashPoW> m_pow; ///< Our miner.
mutable std::mutex x_mineInfo; ///< Lock for the mining progress & history.
mutable Mutex x_mineInfo; ///< Lock for the mining progress & history.
MineProgress m_mineProgress; ///< What's our progress?
std::list<MineInfo> m_mineHistory; ///< What the history of our mining?
};

27
libethereum/State.cpp

@ -451,7 +451,7 @@ bool State::cull(TransactionQueue& _tq) const
{
try
{
if (i.second.nonce() <= transactionsFrom(i.second.sender()))
if (i.second.nonce() < transactionsFrom(i.second.sender()))
{
_tq.drop(i.first);
ret = true;
@ -856,33 +856,12 @@ void State::commitToMine(BlockChain const& _bc)
m_committedToMine = true;
}
MineInfo State::mine(unsigned _msTimeout, bool _turbo)
{
// Update difficulty according to timestamp.
m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock);
MineInfo ret;
// TODO: Miner class that keeps dagger between mine calls (or just non-polling mining).
ProofOfWork::Proof r;
tie(ret, r) = m_pow.mine(m_currentBlock, _msTimeout, true, _turbo);
if (!ret.completed)
m_currentBytes.clear();
else
{
ProofOfWork::assignResult(r, m_currentBlock);
cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock);
}
return ret;
}
bool State::completeMine(ProofOfWork::Proof const& _nonce)
{
ProofOfWork::assignResult(_nonce, m_currentBlock);
if (!m_pow.verify(m_currentBlock))
return false;
// if (!m_pow.verify(m_currentBlock))
// return false;
cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock);

22
libethereum/State.h

@ -168,7 +168,25 @@ public:
/// This function is thread-safe. You can safely have other interactions with this object while it is happening.
/// @param _msTimeout Timeout before return in milliseconds.
/// @returns Information on the mining.
MineInfo mine(unsigned _msTimeout = 1000, bool _turbo = false);
template <class ProofOfWork> MineInfo mine(ProofOfWork* _pow)
{
// Update difficulty according to timestamp.
m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock);
MineInfo ret;
typename ProofOfWork::Proof r;
std::tie(ret, r) = _pow->mine(m_currentBlock, _pow->defaultTimeout(), true);
if (!ret.completed)
m_currentBytes.clear();
else
{
ProofOfWork::assignResult(r, m_currentBlock);
cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock);
}
return ret;
}
/** Commit to DB and build the final block if the previous call to mine()'s result is completion.
* Typically looks like:
@ -371,8 +389,6 @@ private:
Address m_ourAddress; ///< Our address (i.e. the address to which fees go).
ProofOfWork m_pow; ///< The PoW mining class.
u256 m_blockReward;
static std::string c_defaultPath;

17
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -26,7 +26,7 @@
#include <jsonrpccpp/common/exception.h>
#include <libdevcore/CommonData.h>
#if ETH_SOLIDITY
#if ETH_SOLIDITY || !ETH_TRUE
#include <libsolidity/CompilerStack.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/SourceReferenceFormatter.h>
@ -38,7 +38,7 @@
#include <libethcore/CommonJS.h>
#include <libwhisper/Message.h>
#include <libwhisper/WhisperHost.h>
#if ETH_SERPENT
#if ETH_SERPENT || !ETH_TRUE
#include <libserpent/funcs.h>
#endif
#include "WebThreeStubServerBase.h"
@ -296,6 +296,11 @@ string WebThreeStubServerBase::eth_coinbase()
return toJS(client()->address());
}
string WebThreeStubServerBase::eth_hashrate()
{
return toJS(client()->hashrate());
}
bool WebThreeStubServerBase::eth_mining()
{
return client()->isMining();
@ -602,10 +607,10 @@ Json::Value WebThreeStubServerBase::eth_getCompilers()
{
Json::Value ret(Json::arrayValue);
ret.append("lll");
#if SOLIDITY
#if ETH_SOLIDITY || !TRUE
ret.append("solidity");
#endif
#if SERPENT
#if ETH_SERPENT || !TRUE
ret.append("serpent");
#endif
return ret;
@ -627,7 +632,7 @@ string WebThreeStubServerBase::eth_compileSerpent(string const& _code)
// TODO throw here jsonrpc errors
string res;
(void)_code;
#if SERPENT
#if ETH_SERPENT || !ETH_TRUE
try
{
res = toJS(dev::asBytes(::compile(_code)));
@ -649,7 +654,7 @@ string WebThreeStubServerBase::eth_compileSolidity(string const& _code)
// TOOD throw here jsonrpc errors
(void)_code;
string res;
#if SOLIDITY
#if ETH_SOLIDITY || !ETH_TRUE
dev::solidity::CompilerStack compiler;
try
{

1
libweb3jsonrpc/WebThreeStubServerBase.h

@ -78,6 +78,7 @@ public:
virtual bool net_listening();
virtual std::string eth_protocolVersion();
virtual std::string eth_hashrate();
virtual std::string eth_coinbase();
virtual bool eth_mining();
virtual std::string eth_gasPrice();

7
libweb3jsonrpc/abstractwebthreestubserver.h

@ -18,6 +18,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("net_peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::net_peerCountI);
this->bindAndAddMethod(jsonrpc::Procedure("net_listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::net_listeningI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_protocolVersion", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_protocolVersionI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_hashrate", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_hashrateI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_coinbaseI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_miningI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_gasPriceI);
@ -98,6 +99,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
(void)request;
response = this->eth_protocolVersion();
}
inline virtual void eth_hashrateI(const Json::Value &request, Json::Value &response)
{
(void)request;
response = this->eth_hashrate();
}
inline virtual void eth_coinbaseI(const Json::Value &request, Json::Value &response)
{
(void)request;
@ -309,6 +315,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string net_peerCount() = 0;
virtual bool net_listening() = 0;
virtual std::string eth_protocolVersion() = 0;
virtual std::string eth_hashrate() = 0;
virtual std::string eth_coinbase() = 0;
virtual bool eth_mining() = 0;
virtual std::string eth_gasPrice() = 0;

5
libweb3jsonrpc/spec.json

@ -6,8 +6,9 @@
{ "name": "net_peerCount", "params": [], "order": [], "returns" : "" },
{ "name": "net_listening", "params": [], "order": [], "returns" : false },
{ "name": "eth_protocolVersion", "params": [], "order": [], "returns" : "" },
{ "name": "eth_coinbase", "params": [], "order": [], "returns" : "" },
{ "name": "eth_protocolVersion", "params": [], "order": [], "returns" : "" },
{ "name": "eth_hashrate", "params": [], "order": [], "returns" : "" },
{ "name": "eth_coinbase", "params": [], "order": [], "returns" : "" },
{ "name": "eth_mining", "params": [], "order": [], "returns" : false },
{ "name": "eth_gasPrice", "params": [], "order": [], "returns" : "" },
{ "name": "eth_accounts", "params": [], "order": [], "returns" : [] },

10
mix/MixClient.cpp

@ -250,7 +250,8 @@ void MixClient::mine()
{
WriteGuard l(x_state);
m_state.commitToMine(bc());
while (!m_state.mine(100, true).completed) {}
ProofOfWork pow;
while (!m_state.mine(&pow).completed) {}
m_state.completeMine();
bc().import(m_state.blockData(), m_stateDB);
m_state.sync(bc());
@ -391,11 +392,16 @@ void MixClient::stopMining()
//no-op
}
bool MixClient::isMining()
bool MixClient::isMining() const
{
return false;
}
uint64_t MixClient::hashrate() const
{
return 0;
}
eth::MineProgress MixClient::miningProgress() const
{
return eth::MineProgress();

3
mix/MixClient.h

@ -67,7 +67,8 @@ public:
unsigned miningThreads() const override;
void startMining() override;
void stopMining() override;
bool isMining() override;
bool isMining() const override;
uint64_t hashrate() const override;
eth::MineProgress miningProgress() const override;
std::pair<h256, u256> getWork() override { return std::pair<h256, u256>(); }
bool submitWork(eth::ProofOfWork::Proof const&) override { return false; }

34
mix/qml/Debugger.qml

@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0
import QtGraphicalEffects 1.0
import "js/Debugger.js" as Debugger
import "js/ErrorLocationFormater.js" as ErrorLocationFormater
import "."
@ -231,9 +232,9 @@ Rectangle {
id: playAction
enabledStateImg: "qrc:/qml/img/play_button.png"
disableStateImg: "qrc:/qml/img/play_button.png"
buttonLeft: true
onClicked: projectModel.stateListModel.runState(transactionLog.selectedStateIndex)
width: 30
height: 30
width: 23
buttonShortcut: "Ctrl+Shift+F8"
buttonTooltip: qsTr("Start Debugging")
visible: true
@ -246,8 +247,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/stop_button2x.png"
disableStateImg: "qrc:/qml/img/stop_button2x.png"
onClicked: Debugger.init(null);
width: 30
height: 30
width: 23
buttonShortcut: "Ctrl+Shift+F9"
buttonTooltip: qsTr("Stop Debugging")
visible: true
@ -259,8 +259,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoutback.png"
disableStateImg: "qrc:/qml/img/jumpoutbackdisabled.png"
onClicked: Debugger.runBack()
width: 30
height: 30
width: 23
buttonShortcut: "Ctrl+Shift+F5"
buttonTooltip: qsTr("Run Back")
visible: false
@ -272,8 +271,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoutback.png"
disableStateImg: "qrc:/qml/img/jumpoutbackdisabled.png"
onClicked: Debugger.stepOutBack()
width: 30
height: 30
width: 23
buttonShortcut: "Ctrl+Shift+F11"
buttonTooltip: qsTr("Step Out Back")
}
@ -284,8 +282,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpintoback.png"
disableStateImg: "qrc:/qml/img/jumpintobackdisabled.png"
onClicked: Debugger.stepIntoBack()
width: 30
height: 30
width: 23
buttonShortcut: "Ctrl+F11"
buttonTooltip: qsTr("Step Into Back")
}
@ -296,8 +293,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoverback.png"
disableStateImg: "qrc:/qml/img/jumpoverbackdisabled.png"
onClicked: Debugger.stepOverBack()
width: 30
height: 30
width: 23
buttonShortcut: "Ctrl+F10"
buttonTooltip: qsTr("Step Over Back")
}
@ -308,8 +304,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoverforward.png"
disableStateImg: "qrc:/qml/img/jumpoverforwarddisabled.png"
onClicked: Debugger.stepOverForward()
width: 30
height: 30
width: 23
buttonShortcut: "F10"
buttonTooltip: qsTr("Step Over Forward")
}
@ -320,8 +315,7 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpintoforward.png"
disableStateImg: "qrc:/qml/img/jumpintoforwarddisabled.png"
onClicked: Debugger.stepIntoForward()
width: 30
height: 30
width: 23
buttonShortcut: "F11"
buttonTooltip: qsTr("Step Into Forward")
}
@ -332,10 +326,10 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoutforward.png"
disableStateImg: "qrc:/qml/img/jumpoutforwarddisabled.png"
onClicked: Debugger.stepOutForward()
width: 30
height: 30
width: 45
buttonShortcut: "Shift+F11"
buttonTooltip: qsTr("Step Out Forward")
buttonRight: true
}
StepActionImage
@ -344,11 +338,11 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoutforward.png"
disableStateImg: "qrc:/qml/img/jumpoutforwarddisabled.png"
onClicked: Debugger.runForward()
width: 30
height: 30
width: 45
buttonShortcut: "Ctrl+F5"
buttonTooltip: qsTr("Run Forward")
visible: false
buttonRight: true
}
Rectangle {

122
mix/qml/StepActionImage.qml

@ -4,15 +4,22 @@ import QtQuick.Layouts 1.0
import QtQuick.Controls.Styles 1.1
Rectangle {
id: buttonActionContainer
color: "transparent"
property string disableStateImg
property string enabledStateImg
property string buttonTooltip
property string buttonShortcut
property bool buttonLeft
property bool buttonRight
signal clicked
color: "transparent"
width: 35
height: 24
function enabled(state)
{
buttonAction.enabled = state;
@ -22,29 +29,104 @@ Rectangle {
debugImage.source = disableStateImg;
}
Button
{
anchors.fill: parent
id: debugImg
/* iconSource: enabledStateImg
*/ action: buttonAction
Rectangle {
color: "#DCDADA"
width: 10
height: 24
radius: 4
x: 0
visible: buttonLeft
Rectangle {
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: parent.bottom
bottomMargin:debugImg.pressed? 0 : 1;
topMargin:debugImg.pressed? 1 : 0;
}
color: "#FCFBFC"
radius: 3
}
}
Image {
id: debugImage
source: enabledStateImg
anchors.centerIn: parent
fillMode: Image.PreserveAspectFit
width: 15
height: 15
Rectangle {
color: "#DCDADA"
width: 10
height: 24
radius: 4
x: 25
visible: buttonRight
Rectangle {
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: parent.bottom
bottomMargin:debugImg.pressed? 0 : 1;
topMargin:debugImg.pressed? 1 : 0;
}
color: "#FCFBFC"
radius: 3
}
}
Action {
tooltip: buttonTooltip
id: buttonAction
shortcut: buttonShortcut
onTriggered: {
buttonActionContainer.clicked();
Rectangle {
id: contentRectangle
width: 25
height: 24
color: "#DCDADA"
x: 5
Rectangle {
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: parent.bottom
bottomMargin:debugImg.pressed? 0 : 1;
topMargin:debugImg.pressed? 1 : 0;
}
color: "#FCFBFC"
Image {
id: debugImage
source: enabledStateImg
anchors.centerIn: parent
anchors.topMargin: debugImg.pressed? 1 : 0;
fillMode: Image.PreserveAspectFit
width: 15
height: 15
}
}
Button {
anchors.fill: parent
id: debugImg
action: buttonAction
style: Rectangle {
color: "transparent"
}
}
Action {
tooltip: buttonTooltip
id: buttonAction
shortcut: buttonShortcut
onTriggered: {
// contentRectangle.anchors.bottomMargin = 0
// contentRectangle.anchors.topMargin = 1
buttonActionContainer.clicked();
}
}
}
}

7
test/blockchain.cpp

@ -192,7 +192,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
state.sync(bc, txs, gp);
state.commitToMine(bc);
MineInfo info;
for (info.completed = false; !info.completed; info = state.mine()) {}
ProofOfWork pow;
for (info.completed = false; !info.completed; info = state.mine(&pow)) {}
state.completeMine();
}
catch (Exception const& _e)
@ -577,7 +578,7 @@ void overwriteBlockHeader(BlockInfo& _currentBlockHeader, mObject& _blObj)
std::pair<MineInfo, Ethash::Proof> ret;
while (!ProofOfWork::verify(_currentBlockHeader))
{
ret = pow.mine(_currentBlockHeader, 1000, true, true);
ret = pow.mine(_currentBlockHeader, 1000, true);
Ethash::assignResult(ret.second, _currentBlockHeader);
}
}
@ -623,7 +624,7 @@ void updatePoW(BlockInfo& _bi)
std::pair<MineInfo, Ethash::Proof> ret;
while (!ProofOfWork::verify(_bi))
{
ret = pow.mine(_bi, 10000, true, true);
ret = pow.mine(_bi, 10000, true);
Ethash::assignResult(ret.second, _bi);
}
_bi.noteDirty();

5
test/stateOriginal.cpp

@ -68,7 +68,8 @@ BOOST_AUTO_TEST_CASE(Complex)
// Mine to get some ether!
s.commitToMine(bc);
while (!s.mine(100, true).completed) {}
ProofOfWork pow;
while (!s.mine(&pow).completed) {}
s.completeMine();
bc.attemptImport(s.blockData(), stateDB);
@ -88,7 +89,7 @@ BOOST_AUTO_TEST_CASE(Complex)
// Mine to get some ether and set in stone.
s.commitToMine(bc);
s.commitToMine(bc);
while (!s.mine(100, true).completed) {}
while (!s.mine(&pow).completed) {}
s.completeMine();
bc.attemptImport(s.blockData(), stateDB);

10
test/webthreestubclient.h

@ -72,6 +72,16 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_hashrate() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->CallMethod("eth_hashrate",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_coinbase() throw (jsonrpc::JsonRpcException)
{
Json::Value p;

Loading…
Cancel
Save