Browse Source

eth-proxy compatibility

cl-refactor
Genoil 8 years ago
parent
commit
c2245a954e
  1. 2
      CMakeLists.txt
  2. 82
      ethminer/MinerAux.h
  3. 3
      libethcore/Miner.h
  4. 126
      libstratum/EthStratumClient.cpp
  5. 8
      libstratum/EthStratumClient.h
  6. 120
      libstratum/EthStratumClientV2.cpp
  7. 7
      libstratum/EthStratumClientV2.h
  8. BIN
      releases/ethminer-0.9.41-genoil-1.1.7.zip

2
CMakeLists.txt

@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 2.8.12)
set(PROJECT_VERSION "0.9.41")
set(GENOIL_VERSION "1.1.6")
set(GENOIL_VERSION "1.1.7")
if (${CMAKE_VERSION} VERSION_GREATER 3.0)
cmake_policy(SET CMP0042 OLD) # fix MACOSX_RPATH
cmake_policy(SET CMP0048 NEW) # allow VERSION argument in project()

82
ethminer/MinerAux.h

@ -188,7 +188,7 @@ public:
if (p + 1 <= userpass.length())
m_pass = userpass.substr(p+1);
}
else if ((arg == "-SV" || arg == "--stratum-version") && i + 1 < argc)
else if ((arg == "-SC" || arg == "--stratum-client") && i + 1 < argc)
{
try {
m_stratumClientVersion = atoi(argv[++i]);
@ -201,9 +201,27 @@ public:
BOOST_THROW_EXCEPTION(BadArgument());
}
}
else if (arg == "-ES" || arg == "--ethereum-stratum")
else if ((arg == "-SP" || arg == "--stratum-protocol") && i + 1 < argc)
{
m_ethereumStratum = true;
try {
m_stratumProtocol = atoi(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
}
else if ((arg == "-SE" || arg == "--stratum-email") && i + 1 < argc)
{
try {
m_email = string(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
}
else if ((arg == "-FO" || arg == "--failover-userpass") && i + 1 < argc)
{
@ -400,47 +418,6 @@ public:
{
m_minerType = MinerType::Mixed;
}
/*
else if (arg == "--current-block" && i + 1 < argc)
m_currentBlock = stol(argv[++i]);
else if ((arg == "-w" || arg == "--check-pow") && i + 4 < argc)
{
string m;
try
{
Ethash::BlockHeader bi;
m = boost::to_lower_copy(string(argv[++i]));
h256 powHash(m);
m = boost::to_lower_copy(string(argv[++i]));
h256 seedHash;
if (m.size() == 64 || m.size() == 66)
seedHash = h256(m);
else
seedHash = EthashAux::seedHash(stol(m));
m = boost::to_lower_copy(string(argv[++i]));
bi.setDifficulty(u256(m));
auto boundary = bi.boundary();
m = boost::to_lower_copy(string(argv[++i]));
bi.setNonce(h64(m));
auto r = EthashAux::eval(seedHash, powHash, bi.nonce());
bool valid = r.value < boundary;
cout << (valid ? "VALID :-)" : "INVALID :-(") << endl;
cout << r.value << (valid ? " < " : " >= ") << boundary << endl;
cout << " where " << boundary << " = 2^256 / " << bi.difficulty() << endl;
cout << " and " << r.value << " = ethash(" << powHash << ", " << bi.nonce() << ")" << endl;
cout << " with seed as " << seedHash << endl;
if (valid)
cout << "(mixHash = " << r.mixHash << ")" << endl;
cout << "SHA3( light(seed) ) = " << sha3(EthashAux::light(bi.seedHash())->data()) << endl;
exit(0);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << m << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
}
*/
else if (arg == "-M" || arg == "--benchmark")
{
mode = OperationMode::Benchmark;
@ -603,8 +580,12 @@ public:
<< " -O, --userpass <username.workername:password> Stratum login credentials" << endl
<< " -FO, --failover-userpass <username.workername:password> Failover stratum login credentials (optional, will use normal credentials when omitted)" << endl
<< " --work-timeout <n> reconnect/failover after n seconds of working on the same (stratum) job. Defaults to 180. Don't set lower than max. avg. block time" << endl
<< " -SV, --stratum-version <n> Stratum client version. Defaults to 1 (async client). Use 2 to test new synchronous client." << endl
<< " -ES, --ethereum-stratum Use EthereumStratum/1.0.0 mode." << endl
<< " -SC, --stratum-client <n> Stratum client version. Defaults to 1 (async client). Use 2 to use the new synchronous client." << endl
<< " -SP, --stratum-protocol <n> Choose which stratum protocol to use:" << endl
<< " 0: official stratum spec: ethpool, ethermine, coinotron, mph, nanopool (default)" << endl
<< " 1: eth-proxy compatible: dwarfpool, f2pool, nanopool" << endl
<< " 2: EthereumStratum/1.0.0: nicehash" << endl
<< " -SE, --stratum-email <s> Email address used in eth-proxy (optional)" << endl
#endif
#if ETH_JSONRPC || ETH_STRATUM || !ETH_TRUE
<< " --farm-recheck <n> Leave n ms between checks for changed work (default: 500). When using stratum, use a high value (i.e. 2000) to get more stable hashrate output" << endl
@ -930,6 +911,7 @@ private:
cwarn << ":-( Not accepted.";
f.rejectedSolution(false);
}
//exit(0);
}
else if (EthashAux::eval(previous.seedHash, previous.headerHash, solution.nonce).value < previous.boundary)
{
@ -942,6 +924,7 @@ private:
cwarn << ":-( Not accepted.";
f.rejectedSolution(true);
}
//exit(0);
}
else {
f.failedSolution();
@ -1005,7 +988,7 @@ private:
// this is very ugly, but if Stratum Client V2 tunrs out to be a success, V1 will be completely removed anyway
if (m_stratumClientVersion == 1) {
EthStratumClient client(&f, m_minerType, m_farmURL, m_port, m_user, m_pass, m_maxFarmRetries, m_worktimeout, m_ethereumStratum);
EthStratumClient client(&f, m_minerType, m_farmURL, m_port, m_user, m_pass, m_maxFarmRetries, m_worktimeout, m_stratumProtocol, m_email);
if (m_farmFailOverURL != "")
{
if (m_fuser != "")
@ -1045,7 +1028,7 @@ private:
}
}
else if (m_stratumClientVersion == 2) {
EthStratumClientV2 client(&f, m_minerType, m_farmURL, m_port, m_user, m_pass, m_maxFarmRetries, m_worktimeout, m_ethereumStratum);
EthStratumClientV2 client(&f, m_minerType, m_farmURL, m_port, m_user, m_pass, m_maxFarmRetries, m_worktimeout, m_stratumProtocol, m_email);
if (m_farmFailOverURL != "")
{
if (m_fuser != "")
@ -1135,12 +1118,13 @@ private:
#if ETH_STRATUM || !ETH_TRUE
int m_stratumClientVersion = 1;
bool m_ethereumStratum = false;
int m_stratumProtocol = STRATUM_PROTOCOL_STRATUM;
string m_user;
string m_pass;
string m_port;
string m_fuser = "";
string m_fpass = "";
string m_email = "";
#endif
string m_fport = "";
};

3
libethcore/Miner.h

@ -40,6 +40,9 @@
#define DAG_LOAD_MODE_SEQUENTIAL 1
#define DAG_LOAD_MODE_SINGLE 2
#define STRATUM_PROTOCOL_STRATUM 0
#define STRATUM_PROTOCOL_ETHPROXY 1
#define STRATUM_PROTOCOL_ETHEREUMSTRATUM 2
using namespace std;

126
libstratum/EthStratumClient.cpp

@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff)
}
EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, bool ethstratum)
EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email)
: m_socket(m_io_service)
{
m_minerType = m;
@ -44,7 +44,8 @@ EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType
m_maxRetries = retries;
m_worktimeout = worktimeout;
m_ethereumStratum = ethstratum;
m_protocol = protocol;
m_email = email;
p_farm = f;
p_worktimer = nullptr;
@ -179,11 +180,35 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp:
}
}
std::ostream os(&m_requestBuffer);
if (m_ethereumStratum)
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"ethminer/" << ETH_PROJECT_VERSION << "\",\"EthereumStratum/1.0.0\"]}\n";
else
string user;
size_t p;
switch (m_protocol) {
case STRATUM_PROTOCOL_STRATUM:
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}\n";
break;
case STRATUM_PROTOCOL_ETHPROXY:
p = p_active->user.find_first_of(".");
user = p_active->user.substr(0, p);
if (p + 1 <= p_active->user.length())
m_worker = p_active->user.substr(p + 1);
else
m_worker = "";
if (m_email.empty())
{
os << "{\"id\": 1, \"worker\":\"" << m_worker << "\", \"method\": \"eth_submitLogin\", \"params\": [\"" << user << "\"]}\n";
}
else
{
os << "{\"id\": 1, \"worker\":\"" << m_worker << "\", \"method\": \"eth_submitLogin\", \"params\": [\"" << user << "\", \"" << m_email << "\"]}\n";
}
break;
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"ethminer/" << ETH_PROJECT_VERSION << "\",\"EthereumStratum/1.0.0\"]}\n";
break;
}
async_write(m_socket, m_requestBuffer,
boost::bind(&EthStratumClient::handleResponse, this,
@ -235,7 +260,7 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si
std::string response;
getline(is, response);
if (response.front() == '{' && response.back() == '}')
if (!response.empty() && response.front() == '{' && response.back() == '}')
{
Json::Value responseObject;
Json::Reader reader;
@ -249,7 +274,7 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si
cwarn << "Parse response failed: " << reader.getFormattedErrorMessages();
}
}
else
else if (m_protocol != STRATUM_PROTOCOL_ETHPROXY)
{
cwarn << "Discarding incomplete response";
}
@ -288,9 +313,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
switch (id)
{
case 1:
cnote << "Subscribed to stratum server";
if (m_ethereumStratum)
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
m_nextWorkDifficulty = 1;
params = responseObject.get("result", Json::Value::null);
@ -302,9 +325,16 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
os << "{\"id\": 2, \"method\": \"mining.extranonce.subscribe\", \"params\": []}\n";
}
if (m_protocol != STRATUM_PROTOCOL_ETHPROXY)
{
cnote << "Subscribed to stratum server";
os << "{\"id\": 3, \"method\": \"mining.authorize\", \"params\": [\"" << p_active->user << "\",\"" << p_active->pass << "\"]}\n";
}
else
{
m_authorized = true;
os << "{\"id\": 5, \"method\": \"eth_getWork\", \"params\": []}\n"; // not strictly required but it does speed up initialization
}
async_write(m_socket, m_requestBuffer,
boost::bind(&EthStratumClient::handleResponse, this,
boost::asio::placeholders::error));
@ -333,15 +363,29 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
}
break;
default:
string method = responseObject.get("method", "").asString();
string method, workattr;
unsigned index;
if (m_protocol != STRATUM_PROTOCOL_ETHPROXY)
{
method = responseObject.get("method", "").asString();
workattr = "params";
index = 1;
}
else
{
method = "mining.notify";
workattr = "result";
index = 0;
}
if (method == "mining.notify")
{
params = responseObject.get("params", Json::Value::null);
params = responseObject.get(workattr.c_str(), Json::Value::null);
if (params.isArray())
{
string job = params.get((Json::Value::ArrayIndex)0, "").asString();
if (m_ethereumStratum)
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
string sSeedHash = params.get((Json::Value::ArrayIndex)1, "").asString();
string sHeaderHash = params.get((Json::Value::ArrayIndex)2, "").asString();
@ -349,9 +393,6 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
if (sHeaderHash != "" && sSeedHash != "")
{
cnote << "Received new job #" + job;
//cnote << "Header hash: " + sHeaderHash;
//cnote << "Seed hash: " + sSeedHash;
//cnote << "Share target: " + sShareTarget;
h256 seedHash = h256(sSeedHash);
h256 headerHash = h256(sHeaderHash);
@ -376,10 +417,9 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
}
else
{
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();
string sHeaderHash = params.get((Json::Value::ArrayIndex)index++, "").asString();
string sSeedHash = params.get((Json::Value::ArrayIndex)index++, "").asString();
string sShareTarget = params.get((Json::Value::ArrayIndex)index++, "").asString();
// coinmine.pl fix
int l = sShareTarget.length();
@ -390,9 +430,6 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
if (sHeaderHash != "" && sSeedHash != "" && sShareTarget != "")
{
cnote << "Received new job #" + job.substr(0, 8);
//cnote << "Header hash: " + sHeaderHash;
//cnote << "Seed hash: " + sSeedHash;
//cnote << "Share target: " + sShareTarget;
h256 seedHash = h256(sSeedHash);
h256 headerHash = h256(sHeaderHash);
@ -410,7 +447,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
m_current.headerHash = h256(sHeaderHash);
m_current.seedHash = seedHash;
m_current.boundary = h256(sShareTarget);// , h256::AlignRight);
m_current.boundary = h256(sShareTarget);
m_job = job;
p_farm->setWork(m_current);
@ -423,7 +460,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
}
}
}
else if (method == "mining.set_difficulty" && m_ethereumStratum)
else if (method == "mining.set_difficulty" && m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
params = responseObject.get("params", Json::Value::null);
if (params.isArray())
@ -433,7 +470,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
cnote << "Difficulty set to " << m_nextWorkDifficulty;
}
}
else if (method == "mining.set_extranonce" && m_ethereumStratum)
else if (method == "mining.set_extranonce" && m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
params = responseObject.get("params", Json::Value::null);
if (params.isArray())
@ -472,18 +509,28 @@ bool EthStratumClient::submit(EthashProofOfWork::Solution solution) {
cnote << "Solution found; Submitting to" << p_active->host << "...";
string minernonce;
if (!m_ethereumStratum)
if (m_protocol != STRATUM_PROTOCOL_ETHEREUMSTRATUM)
cnote << " Nonce:" << "0x" + solution.nonce.hex();
else
minernonce = solution.nonce.hex().substr(m_extraNonceHexSize, 16 - m_extraNonceHexSize);
if (EthashAux::eval(tempWork.seedHash, tempWork.headerHash, solution.nonce).value < tempWork.boundary)
{
string json;
if (m_ethereumStratum)
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_job + "\",\"" + minernonce + "\"]}\n";
else
switch (m_protocol) {
case STRATUM_PROTOCOL_STRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_job + "\",\"0x" + solution.nonce.hex() + "\",\"0x" + tempWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHPROXY:
json = "{\"id\": 4, \"worker\":\"" + m_worker + "\", \"method\": \"eth_submitWork\", \"params\": [\"0x" + solution.nonce.hex() + "\",\"0x" + tempWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_job + "\",\"" + minernonce + "\"]}\n";
break;
}
std::ostream os(&m_requestBuffer);
os << json;
m_stale = false;
@ -495,10 +542,19 @@ bool EthStratumClient::submit(EthashProofOfWork::Solution solution) {
else if (EthashAux::eval(tempPreviousWork.seedHash, tempPreviousWork.headerHash, solution.nonce).value < tempPreviousWork.boundary)
{
string json;
if (m_ethereumStratum)
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_previous_job + "\",\"" + minernonce + "\"]}\n";
else
switch (m_protocol) {
case STRATUM_PROTOCOL_STRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_previous_job + "\",\"0x" + solution.nonce.hex() + "\",\"0x" + tempPreviousWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHPROXY:
json = "{\"id\": 4, \"worker\":\"" + m_worker + "\", \"method\": \"eth_submitWork\", \"params\": [\"0x" + solution.nonce.hex() + "\",\"0x" + tempPreviousWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_previous_job + "\",\"" + minernonce + "\"]}\n";
break;
}
std::ostream os(&m_requestBuffer);
os << json;
m_stale = true;

8
libstratum/EthStratumClient.h

@ -21,7 +21,7 @@ using namespace dev::eth;
class EthStratumClient
{
public:
EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, bool ethstratum);
EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email);
~EthStratumClient();
void setFailover(string const & host, string const & port);
@ -53,9 +53,10 @@ private:
cred_t m_primary;
cred_t m_failover;
string m_worker; // eth-proxy only;
bool m_authorized;
bool m_connected;
bool m_precompute;
bool m_running = true;
int m_retries = 0;
@ -87,7 +88,8 @@ private:
boost::asio::deadline_timer * p_worktimer;
bool m_ethereumStratum;
int m_protocol;
string m_email;
double m_nextWorkDifficulty;

120
libstratum/EthStratumClientV2.cpp

@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff)
}
EthStratumClientV2::EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, bool ethstratum)
EthStratumClientV2::EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email)
: Worker("stratum"),
m_socket(m_io_service)
{
@ -44,7 +44,8 @@ EthStratumClientV2::EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, Miner
m_maxRetries = retries;
m_worktimeout = worktimeout;
m_ethereumStratum = ethstratum;
m_protocol = protocol;
m_email = email;
p_farm = f;
p_worktimer = nullptr;
@ -86,7 +87,7 @@ void EthStratumClientV2::workLoop()
std::string response;
getline(is, response);
if (response.front() == '{' && response.back() == '}')
if (!response.empty() && response.front() == '{' && response.back() == '}')
{
Json::Value responseObject;
Json::Reader reader;
@ -100,7 +101,7 @@ void EthStratumClientV2::workLoop()
cwarn << "Parse response failed: " << reader.getFormattedErrorMessages();
}
}
else
else if (m_protocol != STRATUM_PROTOCOL_ETHPROXY)
{
cwarn << "Discarding incomplete response";
}
@ -152,10 +153,37 @@ void EthStratumClientV2::connect()
}
}
std::ostream os(&m_requestBuffer);
if (m_ethereumStratum)
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"ethminer/" << ETH_PROJECT_VERSION << "\",\"EthereumStratum/1.0.0\"]}\n";
else
string user;
size_t p;
switch (m_protocol) {
case STRATUM_PROTOCOL_STRATUM:
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}\n";
break;
case STRATUM_PROTOCOL_ETHPROXY:
p = p_active->user.find_first_of(".");
user = p_active->user.substr(0, p);
if (p + 1 <= p_active->user.length())
m_worker = p_active->user.substr(p + 1);
else
m_worker = "";
if (m_email.empty())
{
os << "{\"id\": 1, \"worker\":\"" << m_worker << "\", \"method\": \"eth_submitLogin\", \"params\": [\"" << user << "\"]}\n";
}
else
{
os << "{\"id\": 1, \"worker\":\"" << m_worker << "\", \"method\": \"eth_submitLogin\", \"params\": [\"" << user << "\", \"" << m_email << "\"]}\n";
}
break;
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
os << "{\"id\": 1, \"method\": \"mining.subscribe\", \"params\": [\"ethminer/" << ETH_PROJECT_VERSION << "\",\"EthereumStratum/1.0.0\"]}\n";
break;
}
write(m_socket, m_requestBuffer);
}
}
@ -236,9 +264,8 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
switch (id)
{
case 1:
cnote << "Subscribed to stratum server";
if (m_ethereumStratum)
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
m_nextWorkDifficulty = 1;
params = responseObject.get("result", Json::Value::null);
@ -250,10 +277,18 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
os << "{\"id\": 2, \"method\": \"mining.extranonce.subscribe\", \"params\": []}\n";
}
if (m_protocol != STRATUM_PROTOCOL_ETHPROXY)
{
cnote << "Subscribed to stratum server";
os << "{\"id\": 3, \"method\": \"mining.authorize\", \"params\": [\"" << p_active->user << "\",\"" << p_active->pass << "\"]}\n";
write(m_socket, m_requestBuffer);
}
else
{
m_authorized = true;
os << "{\"id\": 5, \"method\": \"eth_getWork\", \"params\": []}\n"; // not strictly required but it does speed up initialization
write(m_socket, m_requestBuffer);
}
break;
case 2:
// nothing to do...
@ -279,15 +314,29 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
}
break;
default:
string method = responseObject.get("method", "").asString();
string method, workattr;
unsigned index;
if (m_protocol != STRATUM_PROTOCOL_ETHPROXY)
{
method = responseObject.get("method", "").asString();
workattr = "params";
index = 1;
}
else
{
method = "mining.notify";
workattr = "result";
index = 0;
}
if (method == "mining.notify")
{
params = responseObject.get("params", Json::Value::null);
params = responseObject.get(workattr, Json::Value::null);
if (params.isArray())
{
string job = params.get((Json::Value::ArrayIndex)0, "").asString();
if (m_ethereumStratum)
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
string job = params.get((Json::Value::ArrayIndex)0, "").asString();
string sSeedHash = params.get((Json::Value::ArrayIndex)1, "").asString();
@ -296,9 +345,6 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
if (sHeaderHash != "" && sSeedHash != "")
{
cnote << "Received new job #" + job;
//cnote << "Header hash: " + sHeaderHash;
//cnote << "Seed hash: " + sSeedHash;
//cnote << "Share target: " + sShareTarget;
h256 seedHash = h256(sSeedHash);
h256 headerHash = h256(sHeaderHash);
@ -323,10 +369,9 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
}
else
{
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();
string sHeaderHash = params.get((Json::Value::ArrayIndex)index++, "").asString();
string sSeedHash = params.get((Json::Value::ArrayIndex)index++, "").asString();
string sShareTarget = params.get((Json::Value::ArrayIndex)index++, "").asString();
// coinmine.pl fix
int l = sShareTarget.length();
@ -366,7 +411,7 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
}
}
}
else if (method == "mining.set_difficulty" && m_ethereumStratum)
else if (method == "mining.set_difficulty" && m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
params = responseObject.get("params", Json::Value::null);
if (params.isArray())
@ -376,7 +421,7 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
cnote << "Difficulty set to " << m_nextWorkDifficulty;
}
}
else if (method == "mining.set_extranonce" && m_ethereumStratum)
else if (method == "mining.set_extranonce" && m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
{
params = responseObject.get("params", Json::Value::null);
if (params.isArray())
@ -413,7 +458,7 @@ bool EthStratumClientV2::submit(EthashProofOfWork::Solution solution) {
cnote << "Solution found; Submitting to" << p_active->host << "...";
string minernonce;
if (!m_ethereumStratum)
if (m_protocol != STRATUM_PROTOCOL_ETHEREUMSTRATUM)
cnote << " Nonce:" << "0x" + solution.nonce.hex();
else
minernonce = solution.nonce.hex().substr(m_extraNonceHexSize, 16 - m_extraNonceHexSize);
@ -422,10 +467,17 @@ bool EthStratumClientV2::submit(EthashProofOfWork::Solution solution) {
if (EthashAux::eval(tempWork.seedHash, tempWork.headerHash, solution.nonce).value < tempWork.boundary)
{
string json;
if (m_ethereumStratum)
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_job + "\",\"" + minernonce + "\"]}\n";
else
switch (m_protocol) {
case STRATUM_PROTOCOL_STRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_job + "\",\"0x" + solution.nonce.hex() + "\",\"0x" + tempWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHPROXY:
json = "{\"id\": 4, \"worker\":\"" + m_worker + "\", \"method\": \"eth_submitWork\", \"params\": [\"0x" + solution.nonce.hex() + "\",\"0x" + tempWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_job + "\",\"" + minernonce + "\"]}\n";
break;
}
std::ostream os(&m_requestBuffer);
os << json;
m_stale = false;
@ -435,11 +487,17 @@ bool EthStratumClientV2::submit(EthashProofOfWork::Solution solution) {
else if (EthashAux::eval(tempPreviousWork.seedHash, tempPreviousWork.headerHash, solution.nonce).value < tempPreviousWork.boundary)
{
string json;
if (m_ethereumStratum)
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_previous_job + "\",\"" + minernonce + "\"]}\n";
else
switch (m_protocol) {
case STRATUM_PROTOCOL_STRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_previous_job + "\",\"0x" + solution.nonce.hex() + "\",\"0x" + tempPreviousWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
std::ostream os(&m_requestBuffer);
break;
case STRATUM_PROTOCOL_ETHPROXY:
json = "{\"id\": 4, \"worker\":\"" + m_worker + "\", \"method\": \"eth_submitWork\", \"params\": [\"0x" + solution.nonce.hex() + "\",\"0x" + tempPreviousWork.headerHash.hex() + "\",\"0x" + solution.mixHash.hex() + "\"]}\n";
break;
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" + p_active->user + "\",\"" + temp_previous_job + "\",\"" + minernonce + "\"]}\n";
break;
} std::ostream os(&m_requestBuffer);
os << json;
m_stale = true;
cwarn << "Submitting stale solution.";

7
libstratum/EthStratumClientV2.h

@ -22,7 +22,7 @@ using namespace dev::eth;
class EthStratumClientV2 : public Worker
{
public:
EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, bool ethstratum);
EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email);
~EthStratumClientV2();
void setFailover(string const & host, string const & port);
@ -50,6 +50,8 @@ private:
cred_t m_primary;
cred_t m_failover;
string m_worker; // eth-proxy only;
bool m_authorized;
bool m_connected;
bool m_running = true;
@ -81,7 +83,8 @@ private:
boost::asio::deadline_timer * p_worktimer;
bool m_ethereumStratum;
int m_protocol;
string m_email;
double m_nextWorkDifficulty;

BIN
releases/ethminer-0.9.41-genoil-1.1.7.zip

Binary file not shown.
Loading…
Cancel
Save