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

Hardhat is replaying all blocks when forking mainnet #4358

Closed
antoinedc opened this issue Sep 1, 2023 · 7 comments
Closed

Hardhat is replaying all blocks when forking mainnet #4358

antoinedc opened this issue Sep 1, 2023 · 7 comments
Assignees

Comments

@antoinedc
Copy link
Contributor

antoinedc commented Sep 1, 2023

Version of Hardhat

2.17.2

What happened?

When starting/stopping a node setup with a mainnet fork multiple times, instead of emitting the block event only for the latest, Hardhat is going to emit it for all past events since the last emitted one.
For example:

  • I start the node with a fork that is at block 1000
  • I stop it
  • 5 blocks go by
  • I start it again
  • Blocks 1001 to 1005 are going to be emitted

I don't know if this is expected, but this is annoying as the main purpose of mainnet forks is to get the state, not to synchronize blocks & transactions. For my specific use case (Ethernal), this causes issues for users, as when they reset their node, they end up with tons of mainnet blocks/transactions in their backend, instead of just theirs.

Interestingly, this doesn't happen when a block number is specified for the fork.

Minimal reproduction steps

Here is a repo that reproduces the issue, instructions are in the README: https://github.com/tryethernal/repro-hardhat-bug

Search terms

replay, blocks, fork, mainnet

@antoinedc
Copy link
Contributor Author

Also, it seems like those events are only emitted outside of the Hardhat environment.
A plugin using hre.provider is not going to catch them, only something listening from the outside.

@fvictorio
Copy link
Member

Thanks @antoinedc! I honestly have no idea how this is even possible. The second execution shouldn't "know" that there was a previous execution with a lower block number :/ I'll try to look into this as soon as I have some time.

@antoinedc
Copy link
Contributor Author

Thanks! Good to know at least that this is actually a bug and not a hidden feature ahah

@fvictorio
Copy link
Member

@antoinedc
Copy link
Contributor Author

Oh wow, great find! And here is the reason: ethers-io/ethers.js#3924 (comment)

@fvictorio
Copy link
Member

Makes sense. I don't think there's much we can do on our side though, right? Do you mind if we close this?

@antoinedc
Copy link
Contributor Author

Yes, we can definitely close this. I'm opening an issue on their end. Thanks a lot for tracking this down though, it was super helpful!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants