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

feat(anvil): reset to non fork #7500

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yash-atreya
Copy link
Collaborator

Motivation

Ref: #7472

Solution

Implement a new function to reset to a non-fork from a fork.

@yash-atreya
Copy link
Collaborator Author

I think we should add the logic for this into backend.reset_fork() instead of creating a new method

@bauti-defi
Copy link

will this enabled avil_reset to roll back a fork to starting block?

@mattsse
Copy link
Member

mattsse commented Mar 27, 2024

will this enabled avil_reset to roll back a fork to starting block?

this should already be possible if the input is set correctly:

https://hardhat.org/hardhat-network/docs/reference#hardhat_reset

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conceptually this is correct, but it's a bit more complex than this.

we also want some sanity tests for this
that reset and ensure the block number is reset to genesis for example

Comment on lines 476 to 486
// Clear env
{
let mut env = self.env.write();
env.clear();

// Set default anvil chain_id
env.cfg.chain_id = DEV_CHAIN_ID;

// Reset time
self.time.reset(env.block.timestamp.to::<u64>());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't entirely accurate, what we need to consider here is that the node can be in two modes here, forked or mem only.

if mem only we need to reset to the genesis block

if in forked, we need to entirely reinitialize the node block env like this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse So if the node is in mem mode, we just clear the env like env.clear()?

@yash-atreya yash-atreya marked this pull request as draft March 29, 2024 17:49
@yash-atreya yash-atreya marked this pull request as ready for review April 2, 2024 14:26
@yash-atreya yash-atreya requested a review from Evalir as a code owner April 2, 2024 14:26
@DaniPopes DaniPopes requested review from mattsse and removed request for mattsse April 5, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants