You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hardhat is replaying all blocks when forking mainnet #4358
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.
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.
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.
Activity
antoinedc commentedon Sep 2, 2023
Also, it seems like those events are only emitted outside of the Hardhat environment.
A plugin using
hre.provideris not going to catch them, only something listening from the outside.fvictorio commentedon Sep 11, 2023
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 commentedon Sep 11, 2023
Thanks! Good to know at least that this is actually a bug and not a hidden feature ahah
fvictorio commentedon Sep 11, 2023
Actually, I believe this might be a feature of ethers 😬
https://github.com/ethers-io/ethers.js/blob/32915634bef5b81c6d9998f4e9ad812ffe721954/src.ts/providers/subscriber-polling.ts#L71-L80
antoinedc commentedon Sep 11, 2023
Oh wow, great find! And here is the reason: ethers-io/ethers.js#3924 (comment)
fvictorio commentedon Sep 11, 2023
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 commentedon Sep 11, 2023
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!