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

Rise in ethereum difficulty will break block.difficulty #2001

Closed
sz-piotr opened this issue Sep 3, 2021 · 4 comments
Closed

Rise in ethereum difficulty will break block.difficulty #2001

sz-piotr opened this issue Sep 3, 2021 · 4 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. minor-bump Planned for the next minor version bump.

Comments

@sz-piotr
Copy link

sz-piotr commented Sep 3, 2021

The following code tries to fit block.difficulty into a number.

// Returns the difficulty as a number, or if too large (i.e. PoA network) null
difficulty(value: any): number {
if (value == null) { return null; }
const v = BigNumber.from(value);
try {
return v.toNumber();
} catch (error) { }
return null;
}

The difficulty in the recent Ethereum blocks is fast approaching Number.MAX_SAFE_INTEGER. Comparing:

https://etherscan.io/block/13153551  8,648,512,341,350,155
Number.MAX_SAFE_INTEGER              9,007,199,254,740,991

In order to properly handle this the type of block.difficulty would need to change to BigNumber. Since this is a breaking change I am not sure what the process for it should be.

@ricmoo
Copy link
Member

ricmoo commented Sep 3, 2021

I completely agree. I will schedule this change for the next major-version.

Thanks! :)

@ricmoo ricmoo added major-bump Planned for the next major version bump on-deck This Enhancement or Bug is currently being worked on. labels Sep 3, 2021
@ricmoo ricmoo added enhancement New feature or improvement. minor-bump Planned for the next minor version bump. and removed major-bump Planned for the next major version bump labels Sep 13, 2021
@ricmoo
Copy link
Member

ricmoo commented Sep 13, 2021

I'll add this as the next minor bump as discussed in #2036, for v5 and in v6 this will be a BigNumber and the new _difficulty field will be removed.

@ricmoo
Copy link
Member

ricmoo commented Oct 20, 2021

I've dded the _difficulty property for those that need it as a BigNumber. Available as of 5.5.0.

Thanks! :)

@ricmoo ricmoo closed this as completed Oct 20, 2021
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Oct 20, 2021
@wmitsuda
Copy link

Thanks! I'll upgrade and try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. minor-bump Planned for the next minor version bump.
Projects
None yet
Development

No branches or pull requests

3 participants