Browse Source

Mining improvements.

cl-refactor
Gav Wood 11 years ago
parent
commit
4807d43be6
  1. 1
      LICENSE
  2. 9
      alethzero/Main.ui
  3. 5
      alethzero/MainWin.cpp
  4. 1
      alethzero/MainWin.h
  5. 2
      libethcore/BlockInfo.cpp
  6. 8
      libethcore/Dagger.cpp
  7. 2
      libethcore/Dagger.h
  8. 2
      libethereum/Client.cpp
  9. 4
      libethereum/Client.h
  10. 4
      libethereum/State.cpp
  11. 2
      libethereum/State.h

1
LICENSE

@ -1,4 +1,3 @@
/bin/bash: wq: command not found
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>

9
alethzero/Main.ui

@ -185,6 +185,7 @@
<addaction name="killBlockchain"/>
<addaction name="inject"/>
<addaction name="forceMining"/>
<addaction name="turboMining"/>
<addaction name="enableOptimizer"/>
<addaction name="separator"/>
<addaction name="usePrivate"/>
@ -1686,6 +1687,14 @@ font-size: 14pt</string>
<string>&amp;Enable LLL &amp;Optimizer</string>
</property>
</action>
<action name="turboMining">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Reserved Debug 1</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

5
alethzero/MainWin.cpp

@ -835,6 +835,11 @@ static bool transactionMatch(string const& _f, Transaction const& _t)
return false;
}
void Main::on_turboMining_triggered()
{
m_client->setTurboMining(ui->turboMining->isChecked());
}
void Main::refreshBlockChain()
{
cwatch << "refreshBlockChain()";

1
alethzero/MainWin.h

@ -140,6 +140,7 @@ private slots:
void on_refresh_triggered();
void on_usePrivate_triggered();
void on_enableOptimizer_triggered();
void on_turboMining_triggered();
signals:
void poll();

2
libethcore/BlockInfo.cpp

@ -30,7 +30,7 @@
using namespace std;
using namespace eth;
u256 eth::c_genesisDifficulty = (u256)1 << 12;
u256 eth::c_genesisDifficulty = (u256)1 << 17;
BlockInfo::BlockInfo(): timestamp(Invalid256)
{

8
libethcore/Dagger.cpp

@ -25,6 +25,7 @@
#include <chrono>
#include <array>
#include <random>
#include <thread>
#include <libethcore/CryptoHeaders.h>
#include <libethential/Common.h>
#include "Dagger.h"
@ -36,7 +37,7 @@ namespace eth
#if FAKE_DAGGER
MineInfo Dagger::mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout, bool const& _continue)
MineInfo Dagger::mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout, bool _continue, bool _turbo)
{
MineInfo ret{0.f, 1e99, 0, false};
static std::mt19937_64 s_eng((time(0) + (unsigned)m_last));
@ -49,7 +50,10 @@ MineInfo Dagger::mine(h256& o_solution, h256 const& _root, u256 const& _difficul
// [--------*-------------------------]
//
// evaluate until we run out of time
for (auto startTime = steady_clock::now(); (steady_clock::now() - startTime) < milliseconds(_msTimeout) && _continue; s++, ret.hashes++)
auto startTime = steady_clock::now();
if (!_turbo)
this_thread::sleep_for(chrono::milliseconds(_msTimeout * 90 / 100));
for (; (steady_clock::now() - startTime) < milliseconds(_msTimeout) && _continue; s++, ret.hashes++)
{
o_solution = (h256)s;
auto e = (bigint)(u256)eval(_root, o_solution);

2
libethcore/Dagger.h

@ -52,7 +52,7 @@ public:
static h256 eval(h256 const& _root, h256 const& _nonce) { h256 b[2] = { _root, _nonce }; return sha3(bytesConstRef((byte const*)&b[0], 64)); }
static bool verify(h256 const& _root, h256 const& _nonce, u256 const& _difficulty) { return (bigint)(u256)eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; }
MineInfo mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout = 100, bool const& _continue = bool(true));
MineInfo mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout = 100, bool _continue = true, bool _turbo = false);
h256 m_last;
};

2
libethereum/Client.cpp

@ -446,7 +446,7 @@ void Client::work(bool _justQueue)
m_restartMining = false;
// Mine for a while.
MineInfo mineInfo = m_postMine.mine(100);
MineInfo mineInfo = m_postMine.mine(100, m_turboMining);
m_mineProgress.best = min(m_mineProgress.best, mineInfo.best);
m_mineProgress.current = mineInfo.best;

4
libethereum/Client.h

@ -304,6 +304,9 @@ public:
/// Clears pending transactions. Just for debug use.
void clearPending();
void setTurboMining(bool _enable = true) { m_turboMining = _enable; }
bool turboMining() const { return m_turboMining; }
private:
/// Ensure the worker thread is running. Needed for blockchain maintenance & mining.
void ensureWorking();
@ -353,6 +356,7 @@ private:
bool m_paranoia = false;
bool m_doMine = false; ///< Are we supposed to be mining?
bool m_turboMining = false; ///< Don't squander all of our time mining actually just sleeping.
bool m_forceMining = false; ///< Mine even when there are no transactions pending?
MineProgress m_mineProgress;
std::list<MineInfo> m_mineHistory;

4
libethereum/State.cpp

@ -748,13 +748,13 @@ void State::commitToMine(BlockChain const& _bc)
m_currentBlock.parentHash = m_previousBlock.hash;
}
MineInfo State::mine(uint _msTimeout)
MineInfo State::mine(uint _msTimeout, bool _turbo)
{
// Update difficulty according to timestamp.
m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock);
// TODO: Miner class that keeps dagger between mine calls (or just non-polling mining).
auto ret = m_dagger.mine(/*out*/m_currentBlock.nonce, m_currentBlock.headerHashWithoutNonce(), m_currentBlock.difficulty, _msTimeout);
auto ret = m_dagger.mine(/*out*/m_currentBlock.nonce, m_currentBlock.headerHashWithoutNonce(), m_currentBlock.difficulty, _msTimeout, true, _turbo);
if (!ret.completed)
m_currentBytes.clear();

2
libethereum/State.h

@ -157,7 +157,7 @@ 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(uint _msTimeout = 1000);
MineInfo mine(uint _msTimeout = 1000, bool _turbo = false);
/** Commit to DB and build the final block if the previous call to mine()'s result is completion.
* Typically looks like:

Loading…
Cancel
Save