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(cli): adds --dump-state cli cmd #496

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

dutterbutter
Copy link
Collaborator

@dutterbutter dutterbutter commented Dec 16, 2024

What 💻

Why ✋

  • anvil parity

Evidence 📷

Include screenshots, screen recordings, or console output here demonstrating that your changes work as intended

Usage

Run the following command, wait ~60 secs and view state.json file:

./target/release/anvil-zksync --dump-state state.json run

Forking:

./target/release/anvil-zksync --dump-state state.json fork --fork-url sepolia-testnet

@dutterbutter dutterbutter requested a review from a team as a code owner December 16, 2024 18:57
_ = &mut state_dumper => {}
}

state_dumper.dump().await;
Copy link
Collaborator Author

@dutterbutter dutterbutter Dec 16, 2024

Choose a reason for hiding this comment

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

@itegulov inspecting the state dump we always get:

"l1BatchNumber": null,

This is problematic when you attempt to load that same dumped state:

thread 'main' panicked at crates/core/src/node/in_memory.rs:925:13:
encountered a block with no batch; this is not supposed to happen
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Updating the value to not be null resolves the issue but shouldn't l1BatchNumber never be null?

Copy link
Contributor

Choose a reason for hiding this comment

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

Very strange, this shouldn't happen indeed. Do you have an example of how I can reproduce this behaviour?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, to reproduce ./target/release/anvil-zksync --state-interval 1 --dump-state state.json fork --fork-url mainnet

Seems specific to forking?

@dutterbutter dutterbutter added the needs review 👓 PR requires a review label Dec 16, 2024
@@ -33,3 +33,5 @@ serde_json.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
flate2.workspace = true
tempfile = "3"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the version to root workspace, this way we can ensure all our crates depend on the same version to avoid dependency bloat

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added it as dev-dependency as its only used in the unit test.

crates/core/src/node/mod.rs Outdated Show resolved Hide resolved
crates/cli/src/utils.rs Outdated Show resolved Hide resolved
.state_interval
.map(Duration::from_secs)
.unwrap_or(Duration::from_secs(60)); // Default to 60 seconds
let preserve_historical_states = config.preserve_historical_states;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move inside the if below so it's clear these are only relevant when dump_state is present

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, looking at the code it seems like PeriodicStateDumper is designed to work even if dump_path is not present. So I would remove the whole if here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, nice catch. Done ✅


state_dumper.dump().await;

std::process::exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is going to be our "exit point" then could you move BlockProducer here as well? So it's a part of select! and is not spawned on its own.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done ✅

@itegulov
Copy link
Contributor

Also, would love to see an e2e test for this

@dutterbutter
Copy link
Collaborator Author

dutterbutter commented Dec 17, 2024

@itegulov added e2e tests for run and fork modes using --dump_state. I had to update the alloy-zksync dep, hence the extra changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review 👓 PR requires a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants