Browse Source

Don't prep mining if no need.

cl-refactor
Gav Wood 10 years ago
parent
commit
66a4752cf2
  1. 12
      libethereum/Client.cpp
  2. 4
      libethereum/Client.h

12
libethereum/Client.cpp

@ -408,6 +408,7 @@ ProofOfWork::WorkPackage Client::getWork()
{ {
// lock the work so a later submission isn't invalidated by processing a transaction elsewhere. // lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
// this will be reset as soon as a new block arrives, allowing more transactions to be processed. // this will be reset as soon as a new block arrives, allowing more transactions to be processed.
m_lastGetWork = chrono::system_clock::now();
m_remoteWorking = true; m_remoteWorking = true;
return ProofOfWork::package(m_miningInfo); return ProofOfWork::package(m_miningInfo);
} }
@ -527,18 +528,23 @@ void Client::onChainChanged(ImportRoute const& _ir)
noteChanged(changeds); noteChanged(changeds);
} }
bool Client::remoteActive() const
{
return chrono::system_clock::now() - m_lastGetWork < chrono::seconds(30);
}
void Client::onPostStateChanged() void Client::onPostStateChanged()
{ {
cnote << "Post state changed: Restarting mining..."; cnote << "Post state changed: Restarting mining...";
// if (isMining()) if (isMining() || remoteActive())
// { {
{ {
WriteGuard l(x_postMine); WriteGuard l(x_postMine);
m_postMine.commitToMine(m_bc); m_postMine.commitToMine(m_bc);
m_miningInfo = m_postMine.info(); m_miningInfo = m_postMine.info();
} }
m_farm.setWork(m_miningInfo); m_farm.setWork(m_miningInfo);
// } }
m_remoteWorking = false; m_remoteWorking = false;
} }

4
libethereum/Client.h

@ -287,7 +287,9 @@ private:
mutable SharedMutex x_postMine; ///< Lock on the OverlayDB and other attributes of m_postMine. mutable SharedMutex x_postMine; ///< Lock on the OverlayDB and other attributes of m_postMine.
State m_postMine; ///< The state of the client which we're mining (i.e. it'll have all the rewards added). State m_postMine; ///< The state of the client which we're mining (i.e. it'll have all the rewards added).
BlockInfo m_miningInfo; ///< The header we're attempting to mine on (derived from m_postMine). BlockInfo m_miningInfo; ///< The header we're attempting to mine on (derived from m_postMine).
bool m_remoteWorking = false; ///< Is there an acive and valid remote worker? bool remoteActive() const; ///< Is there an active and valid remote worker?
bool m_remoteWorking = false; ///< Has the remote worker recently been reset?
std::chrono::system_clock::time_point m_lastGetWork = std::chrono::system_clock::time_point::min(); ///< Is there an active and valid remote worker?
std::weak_ptr<EthereumHost> m_host; ///< Our Ethereum Host. Don't do anything if we can't lock. std::weak_ptr<EthereumHost> m_host; ///< Our Ethereum Host. Don't do anything if we can't lock.

Loading…
Cancel
Save