Browse Source

Merge pull request #304 from giact/develop

Fixed non-force mining with the new Miner class
cl-refactor
Gav Wood 10 years ago
parent
commit
364efd6495
  1. 11
      libethereum/Client.cpp
  2. 2
      libethereum/Client.h
  3. 46
      libethereum/Miner.cpp
  4. 5
      libethereum/Miner.h

11
libethereum/Client.cpp

@ -312,6 +312,17 @@ void Client::restorePeers(bytesConstRef _saved)
return m_net->restorePeers(_saved);
}
void Client::setForceMining(bool _enable)
{
m_forceMining = _enable;
if (!m_extHost.lock())
{
ReadGuard l(x_miners);
for (auto& m: m_miners)
m.noteStateChange();
}
}
void Client::connect(std::string const& _seedHost, unsigned short _port)
{
ReadGuard l(x_net);

2
libethereum/Client.h

@ -227,7 +227,7 @@ public:
/// Should we force mining to happen, even without transactions?
bool forceMining() const { return m_forceMining; }
/// Enable/disable forcing of mining to happen, even without transactions.
void setForceMining(bool _enable) { m_forceMining = _enable; }
void setForceMining(bool _enable);
/// Are we mining as fast as we can?
bool turboMining() const { return m_turboMining; }
/// Enable/disable fast mining.

46
libethereum/Miner.cpp

@ -65,14 +65,15 @@ void Miner::stop()
void Miner::work()
{
// Do some mining.
if ((m_pendingCount || m_host->force()) && m_miningStatus != Mined)
if (m_miningStatus != Waiting && m_miningStatus != Mined)
{
if (m_miningStatus == Preparing)
{
m_miningStatus = Mining;
m_host->setupState(m_mineState);
m_pendingCount = m_mineState.pending().size();
if (m_host->force() || m_mineState.pending().size())
m_miningStatus = Mining;
else
m_miningStatus = Waiting;
{
Guard l(x_mineInfo);
@ -82,26 +83,29 @@ void Miner::work()
}
}
if (m_miningStatus == Mining)
{
// Mine for a while.
MineInfo mineInfo = m_mineState.mine(100, m_host->turbo());
MineInfo mineInfo = m_mineState.mine(100, m_host->turbo());
{
Guard l(x_mineInfo);
m_mineProgress.best = min(m_mineProgress.best, mineInfo.best);
m_mineProgress.current = mineInfo.best;
m_mineProgress.requirement = mineInfo.requirement;
m_mineProgress.ms += 100;
m_mineProgress.hashes += mineInfo.hashes;
m_mineHistory.push_back(mineInfo);
}
if (mineInfo.completed)
{
m_mineState.completeMine();
m_host->onComplete();
m_miningStatus = Mined;
{
Guard l(x_mineInfo);
m_mineProgress.best = min(m_mineProgress.best, mineInfo.best);
m_mineProgress.current = mineInfo.best;
m_mineProgress.requirement = mineInfo.requirement;
m_mineProgress.ms += 100;
m_mineProgress.hashes += mineInfo.hashes;
m_mineHistory.push_back(mineInfo);
}
if (mineInfo.completed)
{
m_mineState.completeMine();
m_host->onComplete();
m_miningStatus = Mined;
}
else
m_host->onProgressed();
}
else
m_host->onProgressed();
}
else
{

5
libethereum/Miner.h

@ -130,10 +130,9 @@ private:
std::unique_ptr<std::thread> m_work; ///< The work thread.
bool m_stop = false; ///< Stop working?
enum MiningStatus { Preparing, Mining, Mined, Stopping, Stopped };
MiningStatus m_miningStatus = Preparing;///< TODO: consider mutex/atomic variable.
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.
mutable unsigned m_pendingCount = 0; ///< How many pending transactions are there in m_mineState?
mutable std::mutex x_mineInfo; ///< Lock for the mining progress & history.
MineProgress m_mineProgress; ///< What's our progress?

Loading…
Cancel
Save