Browse Source

stop farm while disconnected

cl-refactor
Jan Willem Penterman 9 years ago
parent
commit
ce273972b2
  1. 34
      ethminer/MinerAux.h
  2. 7
      libethcore/Miner.h
  3. 31
      libstratum/EthStratumClient.cpp
  4. 8
      libstratum/EthStratumClient.h

34
ethminer/MinerAux.h

@ -560,13 +560,6 @@ public:
;
}
enum class MinerType
{
CPU,
CL,
CUDA
};
MinerType minerType() const { return m_minerType; }
bool shouldPrecompute() const { return m_precompute; }
@ -883,34 +876,27 @@ private:
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
#endif
GenericFarm<EthashProofOfWork> f;
EthStratumClient client(&f, host, port, user, pass);
EthStratumClient client(&f, _m, host, port, user, pass);
f.setSealers(sealers);
if (_m == MinerType::CPU)
f.start("cpu");
else if (_m == MinerType::CL)
f.start("opencl");
else if (_m == MinerType::CUDA)
f.start("cuda");
bool completed = false;
f.onSolutionFound([&](EthashProofOfWork::Solution sol)
{
client.submit(sol);
return false;
});
while (client.isRunning())
while (true)
{
auto mp = f.miningProgress();
f.resetMiningProgress();
if (client.current())
minelog << "Mining on PoWhash" << client.currentHeaderHash() << ": " << mp;
else
minelog << "Waiting for work package...";
if (client.isConnected())
{
if (client.current())
minelog << "Mining on PoWhash" << client.currentHeaderHash() << ": " << mp;
else
minelog << "Waiting for work package...";
}
this_thread::sleep_for(chrono::milliseconds(_recheckPeriod));
}
}

7
libethcore/Miner.h

@ -36,6 +36,13 @@ namespace dev
namespace eth
{
enum class MinerType
{
CPU,
CL,
CUDA
};
struct MineInfo: public WorkingProgress {};
inline std::ostream& operator<<(std::ostream& _out, WorkingProgress _p)

31
libstratum/EthStratumClient.cpp

@ -4,17 +4,20 @@
using boost::asio::ip::tcp;
EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, string const & host, string const & port, string const & user, string const & pass)
EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass)
: m_socket(m_io_service)
{
m_minerType = m;
m_host = host;
m_port = port;
m_user = user;
m_pass = pass;
m_authorized = false;
m_running = true;
m_connected = false;
m_precompute = true;
m_pending = 0;
p_farm = f;
connect();
}
@ -42,9 +45,15 @@ void EthStratumClient::connect()
void EthStratumClient::reconnect()
{
if (p_farm->isMining())
{
cnote << "Stopping farm";
p_farm->stop();
}
m_socket.close();
m_io_service.reset();
m_authorized = false;
m_connected = false;
cnote << "Reconnecting in 3 seconds...";
boost::asio::deadline_timer timer(m_io_service, boost::posix_time::seconds(3));
timer.wait();
@ -54,8 +63,12 @@ void EthStratumClient::reconnect()
void EthStratumClient::disconnect()
{
cnote << "Disconnecting";
m_running = false;
m_connected = false;
if (p_farm->isMining())
{
cnote << "Stopping farm";
p_farm->stop();
}
m_socket.close();
m_io_service.stop();
}
@ -71,7 +84,7 @@ void EthStratumClient::resolve_handler(const boost::system::error_code& ec, tcp:
else
{
cerr << "Could not resolve host" << m_host + ":" + m_port + ", " << ec.message();
disconnect();
reconnect();
}
}
@ -79,7 +92,15 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp:
{
if (!ec)
{
m_connected = true;
cnote << "Connected to stratum server " << m_host << ":" << m_port;
cnote << "Starting farm";
if (m_minerType == MinerType::CPU)
p_farm->start("cpu");
else if (m_minerType == MinerType::CL)
p_farm->start("opencl");
else if (m_minerType == MinerType::CUDA)
p_farm->start("cuda");
std::ostream os(&m_requestBuffer);
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}\n";

8
libstratum/EthStratumClient.h

@ -7,6 +7,7 @@
#include <libdevcore/FixedHash.h>
#include <libethcore/Farm.h>
#include <libethcore/EthashAux.h>
#include <libethcore/Miner.h>
#include "BuildInfo.h"
@ -19,10 +20,10 @@ using namespace dev::eth;
class EthStratumClient
{
public:
EthStratumClient(GenericFarm<EthashProofOfWork> * f, string const & host, string const & port, string const & user, string const & pass);
EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass);
~EthStratumClient();
bool isRunning() { return m_running; }
bool isConnected() { return m_connected; }
h256 currentHeaderHash() { return m_current.headerHash; }
bool current() { return m_current; }
bool submit(EthashProofOfWork::Solution solution);
@ -38,12 +39,13 @@ private:
void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred);
void processReponse(Json::Value& responseObject);
MinerType m_minerType;
string m_host;
string m_port;
string m_user;
string m_pass;
bool m_authorized;
bool m_running;
bool m_connected;
bool m_precompute;
int m_pending;

Loading…
Cancel
Save