Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of returning the first Nonce below difficulty, return the absolute lowest #90

Closed
Tracked by #209
fasmat opened this issue Dec 6, 2022 · 2 comments
Closed
Tracked by #209
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@fasmat
Copy link
Member

fasmat commented Dec 6, 2022

Summary:

The work oracle is implemented to return the index of the first hash that is below the given difficulty threshold for Pow when calculating labels.

Instead it should return the index of the hash with the lowest value between StartPosition and EndPosition. Additionally when calculating leaves in batches the Initializer should continue to look for indices where the resulting hash is lower than the one already found.

The reason for this is that instead of finding the first Nonce that satisfies the given difficulty, this finds the "best" (lowest) nonce. If a smesher decides to increase their PoST storage in the future this gives them a higher chance of being able to re-use the nonce instead of being required to search for a new one. Additionally if the lowest found nonce doesn't satisfy the difficulty for the larger PoST they can be sure no index in the PoST already calculated does.

Acceptance criteria:

  • add a benchmark to compare the speed of looking for a nonce vs. not using pow during leaf calculation to estimate the impact of the change
    • if looking for a nonce is costly (i.e. speed of initialization drops by more than 10%) we should not implement this change
  • when looking for a nonce don't return the first one below the difficulty threshold, but rather the lowest one
  • if a nonce was found in a batch during the initialization procedure use the value of the found nonce for the next batch to look for "better" nonces
    • alternatively if it simplifies the implementation gpu-post can also just return all nonces that satisfy the difficulty threshold and post can use the CPU to find the lowest one among those found, since we are only expecting ~ 8 nonces during initialization the impact of this should be negligible.

Implementation hints:

  • in gpu-post the comparison from the calculated hash to D (the difficulty threshold) is here. This needs to be changed such that D is updated to the value found and the loop isn't aborted.
  • in gpu-post additionally to the index of the found nonce it's value should be returned as well so it can be used as new difficulty threshold
  • in post a found nonce should not stop the oracle from looking for one, but instead here the difficulty should be updated with the found value and the Initializer should look for better Nonces in successive batches
@fasmat fasmat added enhancement New feature or request good first issue Good for newcomers labels Dec 6, 2022
@fasmat fasmat self-assigned this Dec 6, 2022
@noamnelke
Copy link
Member

if a nonce was found in a batch during the initialization procedure use the value of the found nonce for the next batch to look for "better" nonces

If easier to implement, can also return all nonces below threshold and use CPU to find the lowest one among those found. Should have negligible impact on performance, if at all.

@fasmat
Copy link
Member Author

fasmat commented May 24, 2023

With the recent move of the initialization to OpenCL the code was updated to look for and store the absolute lowest nonce instead of the first below threshold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

2 participants