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

v5 getBlock send ill-formed rpc querry #629

Closed
pldespaigne opened this issue Oct 16, 2019 · 3 comments
Closed

v5 getBlock send ill-formed rpc querry #629

pldespaigne opened this issue Oct 16, 2019 · 3 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@pldespaigne
Copy link

Hi Richard !
I hope you are not too tired by the devcon jet lag ^^

Anyway I found an interesting bug in ethers v5's base-provider :
when you call myProvider.getBlock(myBlockHash) with a block hash that start with 0, it will strip that 0 causing the block hash to be shorter than expected and thus causing the call of rpc method eth_getBlockByNumber instead of eth_getBlockByHash. This will in return cause the rpc node to return an error because obviously a block hash is an invalid block number.

After some investigation it seems that this bug is caused by the following stack
base-provider -> getBlock() -> _getBlock() -> _getBlockTag() -> formatter -> blockTag() -> bytes -> hexValue()

this bug appeared in the browser and in node, and here are the minimal steps to reproduce (in node) :

const provider = require('@ethersproject/base-provider');
const infura = new provider.InfuraProvider('goerli');
infura.getBlock('0x0f305466552efa183a0de26b6fda26d55a872dbc02aca8b5852cc2a361ce9ee4')
    .then(block => console.log(block))
    .catch(err => console.error(err));

As always thanks for your work and your time !

@ricmoo
Copy link
Member

ricmoo commented Oct 16, 2019

Eek! I’ll look into this right away.

(Im still in Ōsaka, so jet lag is t so much a problem, but reliable and non-slow internet is ;))

@ricmoo ricmoo added investigate Under investigation and may be a bug. bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. and removed investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Oct 16, 2019
@ricmoo
Copy link
Member

ricmoo commented Oct 16, 2019

This should now be fixed in @ethersproject/providers@5.0.0-beta.144.

If you are using the umbrella package, you may need to remove your package-lock.json and node_modules before doing npm install.

Please let me know if you have any more problems. :)

@ricmoo ricmoo added the fixed/complete This Bug is fixed or Enhancement is complete and published. label Oct 16, 2019
@pldespaigne
Copy link
Author

Thanks a lot it works perfectly now !

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