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

refactor: split off Fork/ForkSource from ForkStorage #556

Merged
merged 10 commits into from
Jan 23, 2025

Conversation

itegulov
Copy link
Contributor

What 💻

Closes #535

This PR basically get rids of the remaining non-inner fork_storage usages (there are still some tests that depend on it being exposed, to be refactored) by moving fork-related logic into a different struct as IMO these should not be so tightly coupled together. Also I reused jsonrpsee mocking functionality from zksync-era for our tests thus getting rid of ExternalStorage.

I have tested forking functionality manually and it seems to be working fine.

The PR is not perfect by any means but I have already spent too much time on this so IMO an improvement is better than no improvement.

Why ✋

Forking is the place with the most amount of tech debt so having better code here is very valuable

@itegulov itegulov requested a review from popzxc January 22, 2025 08:57
@itegulov itegulov requested a review from a team as a code owner January 22, 2025 08:57
crates/cli/src/main.rs Outdated Show resolved Hide resolved
crates/core/src/node/eth.rs Show resolved Hide resolved
popzxc
popzxc previously approved these changes Jan 23, 2025
Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

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

Agree that incremental improvements are better; just don't forget to handle all the TODOs later :)

Overall, great job, lovin' it.

crates/cli/src/main.rs Outdated Show resolved Hide resolved
crates/cli/src/main.rs Outdated Show resolved Hide resolved
Comment on lines +314 to +316
// It is possible that some external nodes do not store protocol versions for versions below 9.
// That's why we assume that whenever a protocol version is not present, it is unsupported by anvil-zksync.
anyhow::bail!(
Copy link
Member

Choose a reason for hiding this comment

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

Does anvil-zksync support system contracts for all the protocol versions? I was under impression that it only supports the "current" protocol version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a fair point, I was a bit on autopilot when refactoring this part :)

This is what our "stance" used to be before the refactoring so I am just keeping it for now. I added a TODO to figure out what we want to do in reality. Supporting 20 different protocol versions does not seem feasible but likely we should support ProtocolVersion::latest() and ProtocolVersion::next()? Let's have a separate discussion.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should just do what we do in EN: if we encounter a custom protocol version, we fetch the base system contracts from RPC and use them. ABIs are all the same IIRC, so we only need the bytecode. Multivm already supports all the protocol versions and knows how to handle.

Copy link
Member

Choose a reason for hiding this comment

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

(not suggesting to do in in this PR obv)

Comment on lines +585 to +586
// TODO: This is currently cached at the `ForkStorage` level but I am unsure if this is a
// good thing. Intuitively it feels like cache should be centralized in a single place.
Copy link
Member

Choose a reason for hiding this comment

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

Agree

crates/core/src/node/inner/fork_storage.rs Outdated Show resolved Hide resolved
@itegulov itegulov merged commit 7273a59 into main Jan 23, 2025
14 checks passed
@itegulov itegulov deleted the daniyar/refactor/fork branch January 23, 2025 08:44
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.

refactor: hide mutable fork storage interface
3 participants