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

Stratum nicehash. Avoid recalculating target with every job. #1156

Merged
merged 1 commit into from
May 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not all f?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the max target value used in all ethereum code. Not sure why it's not all F's.


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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not know if this is the right place where to put it.
PoolManager does the same on p_client->onWorkReceived(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two different things.

  • Here we've received a stratum2 (nicehash) difficulty indication message from the protocol. We display it as a float. and it is multiplied by the maximum target value to get the target value.

  • In PoolManager, we look for target value changes and when they occur we do the reverse calculation to get the difficulty, which is displayed in units on 1 million (since that's the way pools specify difficulty). This applies to all stratum versions since for non stratum2 versions the target value is part of the job notification.

It's all very confusing... there are many ways to express difficulty.

1 - as a fraction of the maximum target value.
2 - As a 256 bit target value.
3 - Max. target / current target (inverse of 1st form).
4 - (Max. target / current target) / 1000000.

All are equivalent. This code displays in format 1. The pool manager uses format 4.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm ... think we should find a standard way to express diff.
I guess (but it's only a guess) that the most understandable by users is the 4th way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should point out that this update changes nothing in this respect. No log messages were changed or added by this modification.

}
}
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