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

Error provider.getBlock in ethers v5, working in v4 #711

Closed
zemse opened this issue Jan 21, 2020 · 7 comments
Closed

Error provider.getBlock in ethers v5, working in v4 #711

zemse opened this issue Jan 21, 2020 · 7 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@zemse
Copy link
Collaborator

zemse commented Jan 21, 2020

Getting error in ethers 5.0 while it works in 4.0,

ethers.version
"ethers/5.0.0-beta.169"

provider = ethers.getDefaultProvider('kovan')
FallbackProvider {_isProvider: true, formatter: Formatter, _network: {…}, ready: Promise, _maxInternalBlockNumber: -1024, …}

await provider.getBlock(16265864);
ethers.umd.js:4555 Uncaught (in promise) TypeError: Cannot read property '_hex' of null TypeError: Cannot read property '_hex' of null
    at Function.BigNumber.from (ethers.umd.js:4554)
    at Formatter.difficulty (ethers.umd.js:20091)
    at Function.Formatter.check (ethers.umd.js:20270)
    at Formatter._block (ethers.umd.js:20113)
    at Formatter.block (ethers.umd.js:20117)
    at FallbackProvider.<anonymous> (ethers.umd.js:21716)
    at step (ethers.umd.js:20481)
    at Object.next (ethers.umd.js:20412)
    at fulfilled (ethers.umd.js:20366)
BigNumber.from @ ethers.umd.js:4554
Formatter.difficulty @ ethers.umd.js:20091
Formatter.check @ ethers.umd.js:20270
Formatter._block @ ethers.umd.js:20113
Formatter.block @ ethers.umd.js:20117
(anonymous) @ ethers.umd.js:21716
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
load (async)
(anonymous) @ ethers.umd.js:18879
fileReaderReady @ ethers.umd.js:18878
readBlobAsText @ ethers.umd.js:18898
Body.text @ ethers.umd.js:18997
(anonymous) @ ethers.umd.js:19661
step @ ethers.umd.js:19456
(anonymous) @ ethers.umd.js:19387
fulfilled @ ethers.umd.js:19341
Promise.then (async)
step @ ethers.umd.js:19356
(anonymous) @ ethers.umd.js:19359
__awaiter @ ethers.umd.js:19338
(anonymous) @ ethers.umd.js:19623
fetchJson @ ethers.umd.js:19740
JsonRpcProvider.send @ ethers.umd.js:22963
JsonRpcProvider.perform @ ethers.umd.js:23019
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
getRunner @ ethers.umd.js:24625
_loop_2 @ ethers.umd.js:24790
(anonymous) @ ethers.umd.js:24842
step @ ethers.umd.js:24336
(anonymous) @ ethers.umd.js:24267
step @ ethers.umd.js:24275
(anonymous) @ ethers.umd.js:24267
(anonymous) @ ethers.umd.js:24239
__awaiter @ ethers.umd.js:24218
FallbackProvider.perform @ ethers.umd.js:24728
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
(anonymous) @ VM13701:1
(anonymous) @ VM13701:2
ethers.umd.js:4554 Uncaught (in promise) TypeError: Cannot read property '_hex' of null
    at Function.BigNumber.from (ethers.umd.js:4554)
    at Formatter.difficulty (ethers.umd.js:20091)
    at Function.Formatter.check (ethers.umd.js:20270)
    at Formatter._block (ethers.umd.js:20113)
    at Formatter.block (ethers.umd.js:20117)
    at FallbackProvider.<anonymous> (ethers.umd.js:21716)
    at step (ethers.umd.js:20481)
    at Object.next (ethers.umd.js:20412)
    at fulfilled (ethers.umd.js:20366)
BigNumber.from @ ethers.umd.js:4554
Formatter.difficulty @ ethers.umd.js:20091
Formatter.check @ ethers.umd.js:20270
Formatter._block @ ethers.umd.js:20113
Formatter.block @ ethers.umd.js:20117
(anonymous) @ ethers.umd.js:21716
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
load (async)
(anonymous) @ ethers.umd.js:18879
fileReaderReady @ ethers.umd.js:18878
readBlobAsText @ ethers.umd.js:18898
Body.text @ ethers.umd.js:18997
(anonymous) @ ethers.umd.js:19661
step @ ethers.umd.js:19456
(anonymous) @ ethers.umd.js:19387
fulfilled @ ethers.umd.js:19341
Promise.then (async)
step @ ethers.umd.js:19356
(anonymous) @ ethers.umd.js:19359
__awaiter @ ethers.umd.js:19338
(anonymous) @ ethers.umd.js:19623
fetchJson @ ethers.umd.js:19740
JsonRpcProvider.send @ ethers.umd.js:22963
JsonRpcProvider.perform @ ethers.umd.js:23019
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
getRunner @ ethers.umd.js:24625
_loop_2 @ ethers.umd.js:24790
(anonymous) @ ethers.umd.js:24842
step @ ethers.umd.js:24336
(anonymous) @ ethers.umd.js:24267
step @ ethers.umd.js:24275
(anonymous) @ ethers.umd.js:24267
(anonymous) @ ethers.umd.js:24239
__awaiter @ ethers.umd.js:24218
FallbackProvider.perform @ ethers.umd.js:24728
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
(anonymous) @ VM13701:1
(anonymous) @ VM13701:2

Tried it for homestead seems to be working for that.

@zemse zemse changed the title Error provider.getBlock in ethers 5.0, working in 4.0 Error provider.getBlock in ethers v5, working in v4 Jan 21, 2020
@ricmoo ricmoo added the investigate Under investigation and may be a bug. label Jan 21, 2020
@ricmoo
Copy link
Member

ricmoo commented Jan 21, 2020

I’ll investigate this immediately once I get to Starbucks for the day. It may be relate to some of the refactoring of the FallbackProvider I’ve been working on... :s

@zemse
Copy link
Collaborator Author

zemse commented Jan 21, 2020

Okay, this was pretty quick response :P

@ricmoo
Copy link
Member

ricmoo commented Jan 21, 2020

Looks like it is probably PoA related (difficulty is null), I need to figure out why the Kovan tests didn’t detect this...

@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels Jan 21, 2020
@ricmoo
Copy link
Member

ricmoo commented Jan 21, 2020

Sorry for the delay, I forgot I had prior engagements today, but I'm looking at this now and have reproduced it...

@ricmoo
Copy link
Member

ricmoo commented Jan 21, 2020

Ok...Found the problem; it had nothing to do with the other changes... Just that time moved forward. :)

The test cases I have from Kovan are from early on when the difficulty was quite low and fit in a 53-bit number. Not that it is over 53-bits, it is no longer fits. The ethers API specifies that difficulty over 53-bits gets converted to null (this is only relevant for PoA networks, where the difficulty does not have any significant meaning anyways).

So, I've made the parser check for null difficulty before trying to parse it and added your block as a test case to the test suite, so this should be caught before being published next time.

I have 2 or 3 other small things I'm going to look into first, but I should be publishing this to npm within a hour or so and will keep this issue updated.

Thanks for your patience! :)

@ricmoo
Copy link
Member

ricmoo commented Jan 22, 2020

This should be fixed now in the npm version, 5.0.0-beta.170. Please give it a go and let me know if you still have issues. :)

@zemse
Copy link
Collaborator Author

zemse commented Jan 22, 2020

Thank you, it's now working :)

@zemse zemse closed this as completed Jan 22, 2020
@ricmoo ricmoo added the fixed/complete This Bug is fixed or Enhancement is complete and published. label Feb 10, 2020
michaeltout pushed a commit to michaeltout/ethers.js that referenced this issue Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants