Skip to content

Hardhat is replaying all blocks when forking mainnet #4358

Closed

Description

@antoinedc

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

Activity

  1. antoinedc commented on Sep 2, 2023

    @antoinedc
    ContributorAuthor

    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.

  2. fvictorio commented on Sep 11, 2023

    @fvictorio
    Contributor

    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.

  3. antoinedc commented on Sep 11, 2023

    @antoinedc
    ContributorAuthor

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

  4. fvictorio commented on Sep 11, 2023

    @fvictorio
    Contributor
  5. antoinedc commented on Sep 11, 2023

    @antoinedc
    ContributorAuthor

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

  6. fvictorio commented on Sep 11, 2023

    @fvictorio
    Contributor

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

  7. antoinedc commented on Sep 11, 2023

    @antoinedc
    ContributorAuthor

    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!

  8. moved this from Ready to Done in Hardhaton Sep 11, 2023
  9. locked as resolved and limited conversation to collaborators on Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions