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

Conversation

jean-m-cyr
Copy link
Contributor

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.

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;
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.

Copy link
Collaborator

@AndreaLanfranchi AndreaLanfranchi left a 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");
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.

@jean-m-cyr jean-m-cyr merged commit 0c36782 into master May 26, 2018
@jean-m-cyr jean-m-cyr deleted the stratum2 branch May 26, 2018 18:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants