From 0217353e53ff09abe12a30c8250ea897c9d91a4f Mon Sep 17 00:00:00 2001 From: AndreaLanfranchi Date: Fri, 1 May 2020 18:10:54 +0200 Subject: [PATCH 1/8] Save one 'if' branch and let function flow beyond try block --- libpoolprotocols/stratum/EthStratumClient.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index 0119fb729..e5c185b24 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -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 @@ -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); @@ -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) From 5d3d07aec2270c503630a4f2d8ce1359fef16917 Mon Sep 17 00:00:00 2001 From: AndreaLanfranchi Date: Fri, 1 May 2020 18:15:15 +0200 Subject: [PATCH 2/8] If *all* pools must honor the ExtraNonce then move ProcessExtraNonce outside the check for member presence in Json payload --- libpoolprotocols/stratum/EthStratumClient.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index e5c185b24..6a86a95c9 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1020,19 +1020,20 @@ void EthStratumClient::processResponse(Json::Value& responseObject) // 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 + std::string strNonce = {}; 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)) { - 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))); - return; - } + strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString(); + } + if (!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))); + return; } } else From c5a0891443ff23d1048275478ac7863c9127c05a Mon Sep 17 00:00:00 2001 From: blondfrogs Date: Fri, 1 May 2020 10:19:03 -0600 Subject: [PATCH 3/8] Bump version to 1.2.1 --- .bumpversion.cfg | 2 +- CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 0fa57e8b9..bfbabadaa 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.2.0 +current_version =1.2.1 commit = True message = kawpowminer {new_version} diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c450b8cd..1f301a008 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) From b5798d37e0eea53f4dcea9fa5ade98457f5543a6 Mon Sep 17 00:00:00 2001 From: AndreaLanfranchi Date: Fri, 1 May 2020 19:29:48 +0200 Subject: [PATCH 4/8] Process Extranonce only if pool provides it --- libpoolprotocols/stratum/EthStratumClient.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index 6a86a95c9..aacba9ca3 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1018,8 +1018,7 @@ 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 std::string strNonce = {}; if ( responseObject.isMember("result") // Is member present ? @@ -1028,12 +1027,12 @@ void EthStratumClient::processResponse(Json::Value& responseObject) ) { strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString(); - } - if (!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))); - return; + if (!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))); + return; + } } } else From de64a2bc0854d3592b48941eef1404c9b9f7648a Mon Sep 17 00:00:00 2001 From: AndreaLanfranchi Date: Fri, 1 May 2020 19:34:26 +0200 Subject: [PATCH 5/8] Check extranonce is not empty before application. --- libpoolprotocols/stratum/EthStratumClient.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index aacba9ca3..847d78a0d 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1027,11 +1027,14 @@ void EthStratumClient::processResponse(Json::Value& responseObject) ) { strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString(); - if (!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))); - return; + if (strNonce.size()) + { + if (!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))); + return; + } } } } From d14a306e0b7478185050a3704539a231dd62ecfb Mon Sep 17 00:00:00 2001 From: AndreaLanfranchi Date: Fri, 1 May 2020 19:38:24 +0200 Subject: [PATCH 6/8] Better styling and initialization only when needed. --- libpoolprotocols/stratum/EthStratumClient.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index 847d78a0d..774d9f20d 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1019,15 +1019,14 @@ void EthStratumClient::processResponse(Json::Value& responseObject) enqueue_response_plea(); // If pool provides it then set Extranonce now - std::string strNonce = {}; if ( responseObject.isMember("result") // Is member present ? && responseObject["result"].isArray() // Is it an array ? && responseObject["result"].size() > 1 // Does it have 2 elements ? ) { - strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString(); - if (strNonce.size()) + std::string strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString(); + if (strNonce.size() && !processExtranonce(strNonce)) { if (!processExtranonce(strNonce)) { cwarn << "Disconnecting from stratum because of invalid extranonce"; From 188935185394615e01aa0b591dcb1bc59730457f Mon Sep 17 00:00:00 2001 From: AndreaLanfranchi Date: Fri, 1 May 2020 19:01:59 +0200 Subject: [PATCH 7/8] Be consistent with usage of ProcessExtranonce amongst all stratum flavors --- libpoolprotocols/stratum/EthStratumClient.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index 774d9f20d..f3ccce79c 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1514,8 +1514,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) @@ -1557,8 +1561,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); From 78a84976204f3f2c0b9603db64a148ebe653c5c5 Mon Sep 17 00:00:00 2001 From: blondfrogs Date: Fri, 1 May 2020 11:45:38 -0600 Subject: [PATCH 8/8] Fix duplicate function call --- libpoolprotocols/stratum/EthStratumClient.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libpoolprotocols/stratum/EthStratumClient.cpp b/libpoolprotocols/stratum/EthStratumClient.cpp index f3ccce79c..32fe99fb1 100644 --- a/libpoolprotocols/stratum/EthStratumClient.cpp +++ b/libpoolprotocols/stratum/EthStratumClient.cpp @@ -1028,12 +1028,10 @@ void EthStratumClient::processResponse(Json::Value& responseObject) std::string strNonce = responseObject["result"].get(Json::Value::ArrayIndex(1), "").asString(); if (strNonce.size() && !processExtranonce(strNonce)) { - if (!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))); - return; - } + 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))); + return; } } }