Skip to content

Commit

Permalink
Stratum nicehash. Avoid recalculating target with every job.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jean-m-cyr committed May 25, 2018
1 parent 3e1aedd commit 733ae22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## Unreleased
### Fixed
- Reconnecting with mining pool improved [[#1135](https://github.com/ethereum-mining/ethminer/pull/1135)].
- Stratum nicehash. Avoid recalculating target with every job [[#1156](https://github.com/ethereum-mining/ethminer/pull/1156)].
### Removed
- Disabled Debug configuration for Visual Studio [[#69](https://github.com/ethereum-mining/ethminer/issues/69)] [[#1131](https://github.com/ethereum-mining/ethminer/pull/1131)].
17 changes: 9 additions & 8 deletions libpoolprotocols/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ void EthStratumClient::processReponse(Json::Value& responseObject)

cnote << "Subscribed to stratum server";

m_nextWorkDifficulty = 1;
m_nextWorkBoundary = h256("0xffff000000000000000000000000000000000000000000000000000000000000");

if (!jResult.empty() && jResult.isArray()) {
std::string enonce = jResult.get((Json::Value::ArrayIndex)1, "").asString();
processExtranonce(enonce);
Expand Down Expand Up @@ -982,8 +982,7 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
m_current.epoch = ethash::find_epoch_number(
ethash::hash256_from_bytes(h256{sSeedHash}.data()));
m_current.header = h256(sHeaderHash);
m_current.boundary = h256();
diffToTarget((uint32_t*)m_current.boundary.data(), m_nextWorkDifficulty);
m_current.boundary = m_nextWorkBoundary;
m_current.startNonce = bswap(*((uint64_t*)m_extraNonce.data()));
m_current.exSizeBits = m_extraNonceHexSize * 4;
m_current.job_len = job.size();
Expand Down Expand Up @@ -1035,9 +1034,10 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
jPrm = responseObject.get("params", Json::Value::null);
if (jPrm.isArray())
{
m_nextWorkDifficulty = jPrm.get((Json::Value::ArrayIndex)0, 1).asDouble();
if (m_nextWorkDifficulty <= 0.0001) m_nextWorkDifficulty = 0.0001;
cnote << "Difficulty set to" << m_nextWorkDifficulty;
double nextWorkDifficulty = jPrm.get((Json::Value::ArrayIndex)0, 1).asDouble();
if (nextWorkDifficulty <= 0.0001) nextWorkDifficulty = 0.0001;
diffToTarget((uint32_t*)m_nextWorkBoundary.data(), nextWorkDifficulty);
cnote << "Difficulty set to" << nextWorkDifficulty;
}
}
else if (_method == "mining.set_extranonce" && m_conn.Version() == EthStratumClient::ETHEREUMSTRATUM)
Expand Down Expand Up @@ -1307,4 +1307,5 @@ void EthStratumClient::onSSLShutdownCompleted(const boost::system::error_code& e
// cnote << "onSSLShutdownCompleted Error code is : " << ec.message();
m_io_service.post(m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect_finalize, this)));

}
}

2 changes: 1 addition & 1 deletion libpoolprotocols/stratum/EthStratumClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class EthStratumClient : public PoolClient
string m_email;
string m_rate;

double m_nextWorkDifficulty;
h256 m_nextWorkBoundary = h256("0xffff000000000000000000000000000000000000000000000000000000000000");

h64 m_extraNonce;
int m_extraNonceHexSize;
Expand Down

0 comments on commit 733ae22

Please sign in to comment.