Skip to content

Commit

Permalink
Merge pull request #15 from RavenCommunity/nonce_version
Browse files Browse the repository at this point in the history
Update version to 1.2.1, more nonce checks
  • Loading branch information
blondfrogs authored May 1, 2020
2 parents d08fdb1 + 78a8497 commit 55abbfc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.0
current_version =1.2.1
commit = True
message = kawpowminer {new_version}

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HunterGate(
)

project(kawpowminer)
set(PROJECT_VERSION 1.2.0)
set(PROJECT_VERSION 1.2.1)

cable_set_build_type(DEFAULT Release CONFIGURATION_TYPES Release RelWithDebInfo)

Expand Down
35 changes: 21 additions & 14 deletions libpoolprotocols/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,6 @@ std::string EthStratumClient::processError(Json::Value& responseObject)

bool EthStratumClient::processExtranonce(std::string& enonce)
{
// Nothing to do with an empty enonce
if (enonce.empty()) {
cwarn << "Error while setting Extranonce : empty string";
return false;
}

/*
Should not happen but I've seen so many errors :(
Extranonce should be always represented by pairs
Expand All @@ -724,6 +718,9 @@ bool EthStratumClient::processExtranonce(std::string& enonce)

try
{
// Nothing to do with an empty enonce
if (enonce.empty()) throw std::invalid_argument("Empty hex value");

// Check is a proper hex format
if (!std::regex_search(enonce, matches, rgxHex, std::regex_constants::match_default))
throw std::invalid_argument("Invalid hex value " + enonce);
Expand Down Expand Up @@ -754,8 +751,10 @@ bool EthStratumClient::processExtranonce(std::string& enonce)
catch (const std::exception& _ex)
{
cwarn << "Error while setting Extranonce : " << _ex.what();
return false;
}

return false;

}

void EthStratumClient::processResponse(Json::Value& responseObject)
Expand Down Expand Up @@ -1019,16 +1018,16 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
jReq["params"].append(m_conn->Pass());
enqueue_response_plea();

// Set the extranonce nonce to the value given in the second index in the array
// All pools must provide this or this miner will disconnect from the pools
// If pool provides it then set Extranonce now
if (
responseObject.isMember("result") // Is member present ?
&& responseObject["result"].isArray() // Is it an array ?
&& responseObject["result"].size() > 1 // Does it have 2 elements ?
)
{
std::string strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString();
if (!processExtranonce(strNonce)) {
if (strNonce.size() && !processExtranonce(strNonce))
{
cwarn << "Disconnecting from stratum because of invalid extranonce";
// Disconnect from stratum if it fails to set the extra nonce
m_io_service.post(m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect, this)));
Expand Down Expand Up @@ -1513,8 +1512,12 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
if (jPrm.isArray())
{
std::string enonce = jPrm.get(Json::Value::ArrayIndex(0), "").asString();
if (!enonce.empty())
processExtranonce(enonce);
if (!processExtranonce(enonce))
{
cwarn << "Disconnecting ...";
m_io_service.post(
m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect, this)));
}
}
}
else if (_method == "mining.set" && m_conn->StratumMode() == ETHEREUMSTRATUM2)
Expand Down Expand Up @@ -1556,8 +1559,12 @@ void EthStratumClient::processResponse(Json::Value& responseObject)

m_session->algo = jPrm.get("algo", "ethash").asString();
string enonce = jPrm.get("extranonce", "").asString();
if (!enonce.empty())
processExtranonce(enonce);
if (!processExtranonce(enonce))
{
cwarn << "Disconnecting ...";
m_io_service.post(
m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect, this)));
}
}
else if (_method == "mining.set_target") {
jPrm = responseObject.get("params", Json::Value::null);
Expand Down

0 comments on commit 55abbfc

Please sign in to comment.