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: clean zksync_error integration #583

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

Conversation

sayon
Copy link

@sayon sayon commented Feb 6, 2025

What πŸ’»

  • Add zksync_error to this project and wire CLI launcher to it.

Why βœ‹

  • Unified failure system integration.

Evidence πŸ“·

Intended to be transparent.

@sayon sayon requested a review from a team as a code owner February 6, 2025 20:16
@sayon sayon force-pushed the integrate-zksync-error branch from e5a6dcd to fb6f92f Compare February 6, 2025 21:31
Cargo.toml Outdated Show resolved Hide resolved
@sayon sayon requested review from itegulov and popzxc February 7, 2025 16:50
#########################
# Build dependencies #
#########################
zksync-error-codegen = { git = "https://github.com/matter-labs/zksync-error", branch = "main" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should reference a commit hash here instead unless we want to make an initial release of zksync-error?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe rather a tag?
There are two locations in where it is important: here and in build.rs.
Something like stable.
This is a build dependency to rebuild the zksync-error crate, which is included. It is not triggered on build unless anvil.json is changed, therefore even if repository zksync-error breaks compatibility, anvil-zksync is still built without issues.

Copy link
Member

Choose a reason for hiding this comment

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

We need to start publishing it on crates.io (thankfully we have an automation for that now), but until then I'd prefer to depend on commit hash. Everything else can be a PITA to manage due to Cargo.lock (you can update the dep in Cargo.toml, but it won't be updated in Cargo.lock until you do cargo update).

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to commit hash

@dutterbutter dutterbutter added the needs review πŸ‘“ PR requires a review label Feb 7, 2025
@sayon
Copy link
Author

sayon commented Feb 8, 2025

There is a point to discuss here -- how do we depend on zksync-error repository?
There are two Rust dependencies of interest here:

  1. The code generator: crate zksync-error-codegen. This is a build-time dependency, and it is only used to rebuild the crate zksync-error. In other words, normally it is not triggered at all.
  2. The documentation layout: crate zksync-error-description. It is a runtime dependency, but currently it is listed only in the generated file crates/zksync-error/Cargo.toml. This crate is an interface-only crate, meaning that it is supposed to be solid and it is detached from the codegen internals. If codegen changes, it is still obliged to conform to the interface in zksync-error-description.

I propose to depend on main or on some designated tag (stable?) for the codegen (can break but older builds will remain buildable) and on main for (2) (we promise that the interface remains stable).

@popzxc @itegulov @dutterbutter

#########################
# Build dependencies #
#########################
zksync-error-codegen = { git = "https://github.com/matter-labs/zksync-error", branch = "main" }
Copy link
Member

Choose a reason for hiding this comment

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

We need to start publishing it on crates.io (thankfully we have an automation for that now), but until then I'd prefer to depend on commit hash. Everything else can be a PITA to manage due to Cargo.lock (you can update the dep in Cargo.toml, but it won't be updated in Cargo.lock until you do cargo update).

@@ -0,0 +1,377 @@
# What is zksync-error?
Copy link
Member

Choose a reason for hiding this comment

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

Formatting in this file is odd. Could you please make sure that it's properly formatted, e.g.:

  • aligned to 120 line length
  • no blocks of many empty lines
  • only one H1 header

@@ -0,0 +1,377 @@
# What is zksync-error?

A generated crate describing all errors that are:
Copy link
Member

Choose a reason for hiding this comment

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

It feels like this document tries to cover two things:

  • What is zksync-error
  • How to use it in anvil-zksync specifically.

IMHO, the first part should be a part of zksync-error repository, and here we would do something like "Please read this document first (link), and below we will cover how to use it for this codebase".

Otherwise, it will be a copypasta to be added to every repo and it will be a PITA to manage.

We can do it later if you prefer, however, I don't intend to block merging over this.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, zksync-error must have a book published similarly to core/prover/compiler docs covering the architecture/usage/etc, but this can wait until we integrate it here.

Copy link
Author

Choose a reason for hiding this comment

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

@dutterbutter if I recall correctly you suggested including project-agnostic documentation for zksync-error in this repository. If that was the case, could you remind the rationale?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for the initial integration having it in this repo is fine given most of the early usage / work with it will be within anvil-zksync. I know for myself I will be referencing it and having it within the repo is certainly convenient.

That being said, definitely once we've defined some standards / best practices it should be hosted and published separately. That will be done outside of this PR.

"types": [],
"domains": [
{
"domain_name": "AnvilZKS",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be AnvilZksync / anvil_zksync? ZKS feels super odd.

Copy link
Author

Choose a reason for hiding this comment

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

Agree

@@ -61,8 +61,9 @@ jobs:

- name: Pack anvil-zksync
run: |
tar -czf anvil-zksync-${{ inputs.tag || inputs.prerelease_name }}-${{ matrix.arch }}.tar.gz \
./target/${{ matrix.arch }}/release/anvil-zksync
tar -C ./target/${{ matrix.arch }}/release -czf \
Copy link
Member

Choose a reason for hiding this comment

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

Merge artifacts?

Copy link
Author

Choose a reason for hiding this comment

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

Yea this comes from a merge commit. Would you prefer me to rebase instead? I remember weird behavior on Github when I rebased branches and then conversations tied to the old commits are impossible to resolve.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you made #584 a part of your PR by accident

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 it should be etc/errors/anvil-zksync.json.

Copy link
Author

Choose a reason for hiding this comment

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

Agree

Copy link
Contributor

@itegulov itegulov left a comment

Choose a reason for hiding this comment

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

Yet to read through the howto doc but reviewed everything else. The new approach looks a lot more idiomatic!

@@ -61,8 +61,9 @@ jobs:

- name: Pack anvil-zksync
run: |
tar -czf anvil-zksync-${{ inputs.tag || inputs.prerelease_name }}-${{ matrix.arch }}.tar.gz \
./target/${{ matrix.arch }}/release/anvil-zksync
tar -C ./target/${{ matrix.arch }}/release -czf \
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you made #584 a part of your PR by accident

@@ -70,9 +70,9 @@ dependencies = [

[[package]]
name = "alloy-core"
version = "0.8.15"
version = "0.8.20"
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to run cargo update? I'd avoid bumping deps in this PR if there is no strong reason for it

#########################
# Build dependencies #
#########################
zksync-error-codegen = { git = "https://github.com/matter-labs/zksync-error", branch = "main" }
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to commit hash

fn main() {
// If we have modified anvil errors, forces rerunning the build script and
// regenerating the crate `zksync-error`.
println!("cargo:rerun-if-changed=../../etc/resources/anvil.json");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: AFAIR cargo::KEY=VALUE is the preferred syntax now (starting from Rust 1.77):

Suggested change
println!("cargo:rerun-if-changed=../../etc/resources/anvil.json");
println!("cargo::rerun-if-changed=../../etc/resources/anvil.json");

crates/core/build.rs Show resolved Hide resolved
@@ -0,0 +1,15 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: random empty line

name = "zksync_error"
version = "0.1.0"
edition = "2021"
[lib]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary

strum = "0.26.3"
strum_macros = "0.26.4"
zksync-error-description = { git = "https://github.com/matter-labs/zksync-error", branch = "main"}
anyhow = "1.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, is this file auto-generated too? If so at the very least we need a header making this clear but I also think I would prefer if it was left for the user to write


#![allow(unused)]
pub mod documentation;
pub(crate) mod error;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub(crate) mod error;
pub mod error;

Access to types CustomErrorMessage and NamedError.

@dutterbutter dutterbutter added needs changes πŸ”§ Review requested changes on a PR and removed needs review πŸ‘“ PR requires a review labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs changes πŸ”§ Review requested changes on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants