Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit 733ae22

Browse files
committedMay 25, 2018
Stratum nicehash. Avoid recalculating target with every job.
nicehash will periodically adjust difficulty, sending it as a float value to be converted to 32 byte target. There is no need to do the conversion with every job.
1 parent 3e1aedd commit 733ae22

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66
## Unreleased
77
### Fixed
88
- Reconnecting with mining pool improved [[#1135](https://github.com/ethereum-mining/ethminer/pull/1135)].
9+
- Stratum nicehash. Avoid recalculating target with every job [[#1156](https://github.com/ethereum-mining/ethminer/pull/1156)].
910
### Removed
1011
- Disabled Debug configuration for Visual Studio [[#69](https://github.com/ethereum-mining/ethminer/issues/69)] [[#1131](https://github.com/ethereum-mining/ethminer/pull/1131)].

‎libpoolprotocols/stratum/EthStratumClient.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
792792

793793
cnote << "Subscribed to stratum server";
794794

795-
m_nextWorkDifficulty = 1;
796-
795+
m_nextWorkBoundary = h256("0xffff000000000000000000000000000000000000000000000000000000000000");
796+
797797
if (!jResult.empty() && jResult.isArray()) {
798798
std::string enonce = jResult.get((Json::Value::ArrayIndex)1, "").asString();
799799
processExtranonce(enonce);
@@ -982,8 +982,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
982982
m_current.epoch = ethash::find_epoch_number(
983983
ethash::hash256_from_bytes(h256{sSeedHash}.data()));
984984
m_current.header = h256(sHeaderHash);
985-
m_current.boundary = h256();
986-
diffToTarget((uint32_t*)m_current.boundary.data(), m_nextWorkDifficulty);
985+
m_current.boundary = m_nextWorkBoundary;
987986
m_current.startNonce = bswap(*((uint64_t*)m_extraNonce.data()));
988987
m_current.exSizeBits = m_extraNonceHexSize * 4;
989988
m_current.job_len = job.size();
@@ -1035,9 +1034,10 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
10351034
jPrm = responseObject.get("params", Json::Value::null);
10361035
if (jPrm.isArray())
10371036
{
1038-
m_nextWorkDifficulty = jPrm.get((Json::Value::ArrayIndex)0, 1).asDouble();
1039-
if (m_nextWorkDifficulty <= 0.0001) m_nextWorkDifficulty = 0.0001;
1040-
cnote << "Difficulty set to" << m_nextWorkDifficulty;
1037+
double nextWorkDifficulty = jPrm.get((Json::Value::ArrayIndex)0, 1).asDouble();
1038+
if (nextWorkDifficulty <= 0.0001) nextWorkDifficulty = 0.0001;
1039+
diffToTarget((uint32_t*)m_nextWorkBoundary.data(), nextWorkDifficulty);
1040+
cnote << "Difficulty set to" << nextWorkDifficulty;
10411041
}
10421042
}
10431043
else if (_method == "mining.set_extranonce" && m_conn.Version() == EthStratumClient::ETHEREUMSTRATUM)
@@ -1307,4 +1307,5 @@ void EthStratumClient::onSSLShutdownCompleted(const boost::system::error_code& e
13071307
// cnote << "onSSLShutdownCompleted Error code is : " << ec.message();
13081308
m_io_service.post(m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect_finalize, this)));
13091309

1310-
}
1310+
}
1311+

‎libpoolprotocols/stratum/EthStratumClient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class EthStratumClient : public PoolClient
108108
string m_email;
109109
string m_rate;
110110

111-
double m_nextWorkDifficulty;
111+
h256 m_nextWorkBoundary = h256("0xffff000000000000000000000000000000000000000000000000000000000000");
112112

113113
h64 m_extraNonce;
114114
int m_extraNonceHexSize;

0 commit comments

Comments
 (0)
This repository has been archived.