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

Fix "diff not match" #106

Closed
wants to merge 2 commits into from
Closed

Fix "diff not match" #106

wants to merge 2 commits into from

Conversation

syntrust
Copy link
Contributor

Addressing ethstorage/es-node#304.

The current expectedDiff() in MiningLib.sol appears to have lost accuracy compared to the implementation in es-node, leading to rare cases where the computed difficulty does not match.

The fix aligns with the algorithm described here: https://github.com/ethstorage/es-node/blob/87a1fe723871dc319e2e7761cacc38c5aaf92ee8/ethstorage/miner/algorithm.go#L43

The unit test utilizes actual input data from a previously failed case.

@@ -33,12 +33,12 @@ library MiningLib {
uint256 interval = _mineTime - _info.lastMineTime;
uint256 diff = _info.difficulty;
if (interval < _cutoff) {
diff = diff + ((1 - interval / _cutoff) * diff) / _diffAdjDivisor;
diff = diff + (diff - interval * diff / _cutoff) / _diffAdjDivisor;
Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed in the sync meeting, we may not want to change the alg in the smart contact.

@syntrust
Copy link
Contributor Author

It should be an es-node issue according to the discussion in ethstorage/pm#116

See ethstorage/es-node#315 instead.

Origin:
image

@syntrust syntrust closed this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants