-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Stratum nicehash. Avoid recalculating target with every job. #1156
Conversation
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.
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; |
There was a problem hiding this comment.
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(...)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me.
@@ -792,8 +792,8 @@ void EthStratumClient::processReponse(Json::Value& responseObject) | |||
|
|||
cnote << "Subscribed to stratum server"; | |||
|
|||
m_nextWorkDifficulty = 1; | |||
|
|||
m_nextWorkBoundary = h256("0xffff000000000000000000000000000000000000000000000000000000000000"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not all f
?
There was a problem hiding this comment.
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.
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.