Browse Source

borked responses..

cl-refactor
Jan Willem Penterman 9 years ago
parent
commit
b758820080
  1. 9
      ethminer/MinerAux.h
  2. 192
      libstratum/EthStratumClient.cpp
  3. 5
      libstratum/EthStratumClient.h

9
ethminer/MinerAux.h

@ -886,22 +886,25 @@ private:
EthStratumClient client(&f, host, port, user, pass); EthStratumClient client(&f, host, port, user, pass);
f.setSealers(sealers); f.setSealers(sealers);
/*
if (_m == MinerType::CPU) if (_m == MinerType::CPU)
f.start("cpu"); f.start("cpu");
else if (_m == MinerType::CL) else if (_m == MinerType::CL)
f.start("opencl"); f.start("opencl");
else if (_m == MinerType::CUDA) else if (_m == MinerType::CUDA)
f.start("cuda"); f.start("cuda");
*/
bool completed = false; bool completed = false;
EthashProofOfWork::Solution solution; EthashProofOfWork::Solution solution;
/*
f.onSolutionFound([&](EthashProofOfWork::Solution sol) f.onSolutionFound([&](EthashProofOfWork::Solution sol)
{ {
solution = sol; solution = sol;
minelog << "Solution!"; minelog << "Solution!";
return client.submit(solution); client.submit(solution);
return false;
}); });
*/
while (client.isRunning()) while (client.isRunning())
{ {
auto mp = f.miningProgress(); auto mp = f.miningProgress();

192
libstratum/EthStratumClient.cpp

@ -103,101 +103,21 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si
std::istream is(&m_responseBuffer); std::istream is(&m_responseBuffer);
std::string response; std::string response;
getline(is, response); getline(is, response);
//cnote << response; cnote << response;
if (response.back() != '}') {
m_response = response;
}
if (response.front() != '{') {
response = m_response + response;
}
Json::Value responseObject; Json::Value responseObject;
Json::Reader reader; Json::Reader reader;
if (reader.parse(response.c_str(), responseObject)) if (reader.parse(response.c_str(), responseObject))
{ {
if (responseObject.isMember("id")) { processReponse(responseObject);
Json::Value error = responseObject.get("error", NULL); m_response = response;
if (error.isArray())
{
string msg = error.get(1, "Unknown error").asString();
cnote << msg;
}
std::ostream os(&m_requestBuffer);
Json::Value params;
int id = responseObject.get("id", NULL).asInt();
switch (id)
{
case 1:
cnote << "Subscribed to stratum server";
os << "{\"id\": 2, \"method\": \"mining.authorize\", \"params\": [\"" << m_user << "\",\"" << m_pass << "\"]}\n";
async_write(m_socket, m_requestBuffer,
boost::bind(&EthStratumClient::handleResponse, this,
boost::asio::placeholders::error));
break;
case 2:
m_authorized = responseObject.get("result", NULL).asBool();
if (!m_authorized)
{
disconnect();
return;
}
cnote << "Authorized worker " << m_user;
break;
case 4:
cnote << response;
default:
string method = responseObject.get("method", "").asString();
if (method == "mining.notify")
{
params = responseObject.get("params", NULL);
if (params.isArray())
{
m_job = params.get((Json::Value::ArrayIndex)0, "").asString();
string sHeaderHash = params.get((Json::Value::ArrayIndex)1, "").asString();
string sSeedHash = params.get((Json::Value::ArrayIndex)2, "").asString();
string sShareTarget = params.get((Json::Value::ArrayIndex)3, "").asString();
bool cleanJobs = params.get((Json::Value::ArrayIndex)4, "").asBool();
if (sHeaderHash != "" && sSeedHash != "" && sShareTarget != "")
{
cnote << "Received new job #" + m_job;
cnote << "Header hash: 0x" + sHeaderHash;
cnote << "Seed hash: 0x" + sSeedHash;
cnote << "Share target: 0x" + sShareTarget;
h256 seedHash = h256(sSeedHash);
h256 headerHash = h256(sHeaderHash);
EthashAux::FullType dag;
if (seedHash != m_current.seedHash)
cnote << "Grabbing DAG for" << seedHash;
if (!(dag = EthashAux::full(seedHash, true, [&](unsigned _pc){ cout << "\rCreating DAG. " << _pc << "% done..." << flush; return 0; })))
BOOST_THROW_EXCEPTION(DAGCreationFailure());
if (m_precompute)
EthashAux::computeFull(sha3(seedHash), true);
if (headerHash != m_current.headerHash)
{
m_current.headerHash = h256(sHeaderHash);
m_current.seedHash = seedHash;
m_current.boundary = h256(sShareTarget, h256::AlignRight);
p_farm->setWork(m_current);
}
}
}
}
else if (method == "mining.set_difficulty")
{
}
else if (method == "client.get_version")
{
os << "{\"error\": null, \"id\" : " << id << ", \"result\" : \"" << ETH_PROJECT_VERSION << "\"}";
async_write(m_socket, m_requestBuffer,
boost::bind(&EthStratumClient::handleResponse, this,
boost::asio::placeholders::error));
}
break;
}
}
async_read_until(m_socket, m_responseBuffer, "\n",
boost::bind(&EthStratumClient::readResponse, this,
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
} }
else else
{ {
@ -208,6 +128,98 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si
{ {
cwarn << "Read response failed: " << ec.message(); cwarn << "Read response failed: " << ec.message();
} }
async_read_until(m_socket, m_responseBuffer, "\n",
boost::bind(&EthStratumClient::readResponse, this,
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
void EthStratumClient::processReponse(Json::Value& responseObject)
{
Json::Value error = responseObject.get("error", NULL);
if (error.isArray())
{
string msg = error.get(1, "Unknown error").asString();
cnote << msg;
}
std::ostream os(&m_requestBuffer);
Json::Value params;
int id = responseObject.get("id", NULL).asInt();
switch (id)
{
case 1:
cnote << "Subscribed to stratum server";
os << "{\"id\": 2, \"method\": \"mining.authorize\", \"params\": [\"" << m_user << "\",\"" << m_pass << "\"]}\n";
async_write(m_socket, m_requestBuffer,
boost::bind(&EthStratumClient::handleResponse, this,
boost::asio::placeholders::error));
break;
case 2:
m_authorized = responseObject.get("result", NULL).asBool();
if (!m_authorized)
{
disconnect();
return;
}
cnote << "Authorized worker " << m_user;
break;
case 4:
cnote << m_response;
default:
string method = responseObject.get("method", "").asString();
if (method == "mining.notify")
{
params = responseObject.get("params", NULL);
if (params.isArray())
{
m_job = params.get((Json::Value::ArrayIndex)0, "").asString();
string sHeaderHash = params.get((Json::Value::ArrayIndex)1, "").asString();
string sSeedHash = params.get((Json::Value::ArrayIndex)2, "").asString();
string sShareTarget = params.get((Json::Value::ArrayIndex)3, "").asString();
bool cleanJobs = params.get((Json::Value::ArrayIndex)4, "").asBool();
if (sHeaderHash != "" && sSeedHash != "" && sShareTarget != "")
{
cnote << "Received new job #" + m_job;
cnote << "Header hash: 0x" + sHeaderHash;
cnote << "Seed hash: 0x" + sSeedHash;
cnote << "Share target: 0x" + sShareTarget;
h256 seedHash = h256(sSeedHash);
h256 headerHash = h256(sHeaderHash);
EthashAux::FullType dag;
if (seedHash != m_current.seedHash)
cnote << "Grabbing DAG for" << seedHash;
if (!(dag = EthashAux::full(seedHash, true, [&](unsigned _pc){ cout << "\rCreating DAG. " << _pc << "% done..." << flush; return 0; })))
BOOST_THROW_EXCEPTION(DAGCreationFailure());
if (m_precompute)
EthashAux::computeFull(sha3(seedHash), true);
if (headerHash != m_current.headerHash)
{
m_current.headerHash = h256(sHeaderHash);
m_current.seedHash = seedHash;
m_current.boundary = h256(sShareTarget, h256::AlignRight);
p_farm->setWork(m_current);
}
}
}
}
else if (method == "mining.set_difficulty")
{
}
else if (method == "client.get_version")
{
os << "{\"error\": null, \"id\" : " << id << ", \"result\" : \"" << ETH_PROJECT_VERSION << "\"}";
async_write(m_socket, m_requestBuffer,
boost::bind(&EthStratumClient::handleResponse, this,
boost::asio::placeholders::error));
}
break;
}
} }
bool EthStratumClient::submit(EthashProofOfWork::Solution solution) { bool EthStratumClient::submit(EthashProofOfWork::Solution solution) {

5
libstratum/EthStratumClient.h

@ -34,8 +34,7 @@ private:
void handleResponse(const boost::system::error_code& ec); void handleResponse(const boost::system::error_code& ec);
void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred); void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred);
void processReponse(Json::Value& responseObject);
string m_host; string m_host;
string m_port; string m_port;
@ -45,6 +44,8 @@ private:
bool m_running; bool m_running;
bool m_precompute; bool m_precompute;
string m_response;
GenericFarm<EthashProofOfWork> * p_farm; GenericFarm<EthashProofOfWork> * p_farm;
EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_current;
string m_job; string m_job;

Loading…
Cancel
Save