From 3972fa76e3814d96977899b277789646a9ead560 Mon Sep 17 00:00:00 2001 From: zeapoz Date: Thu, 21 Mar 2024 15:46:51 +0100 Subject: [PATCH] ref: move `ParseError` to `lib.rs` --- .../src/blob_http_client.rs | 2 +- state-reconstruct-fetcher/src/lib.rs | 31 ++++++++++++++++++ .../src/parser/calldata_tokens.rs | 2 +- state-reconstruct-fetcher/src/parser/mod.rs | 3 +- state-reconstruct-fetcher/src/types/common.rs | 7 ++-- state-reconstruct-fetcher/src/types/mod.rs | 32 +------------------ 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/state-reconstruct-fetcher/src/blob_http_client.rs b/state-reconstruct-fetcher/src/blob_http_client.rs index 8bbbeee..3dd8fd0 100644 --- a/state-reconstruct-fetcher/src/blob_http_client.rs +++ b/state-reconstruct-fetcher/src/blob_http_client.rs @@ -1,7 +1,7 @@ use serde::Deserialize; use tokio::time::{sleep, Duration}; -use crate::types::ParseError; +use crate::ParseError; /// `MAX_RETRIES` is the maximum number of retries on failed blob retrieval. const MAX_RETRIES: u8 = 5; diff --git a/state-reconstruct-fetcher/src/lib.rs b/state-reconstruct-fetcher/src/lib.rs index 9d36ae4..45fc405 100644 --- a/state-reconstruct-fetcher/src/lib.rs +++ b/state-reconstruct-fetcher/src/lib.rs @@ -1,5 +1,7 @@ #![feature(array_chunks)] #![feature(iter_next_chunk)] +use thiserror::Error; + pub mod blob_http_client; pub mod constants; pub mod database; @@ -7,3 +9,32 @@ pub mod l1_fetcher; pub mod metrics; pub mod parser; pub mod types; + +#[allow(clippy::enum_variant_names)] +#[derive(Error, Debug)] +pub enum ParseError { + #[error("invalid Calldata: {0}")] + InvalidCalldata(String), + + #[error("invalid StoredBlockInfo: {0}")] + InvalidStoredBlockInfo(String), + + #[error("invalid CommitBlockInfo: {0}")] + InvalidCommitBlockInfo(String), + + #[allow(dead_code)] + #[error("invalid compressed bytecode: {0}")] + InvalidCompressedByteCode(String), + + #[error("invalid compressed value: {0}")] + InvalidCompressedValue(String), + + #[error("invalid pubdata source: {0}")] + InvalidPubdataSource(String), + + #[error("blob storage error: {0}")] + BlobStorageError(String), + + #[error("blob format error: {0}")] + BlobFormatError(String, String), +} diff --git a/state-reconstruct-fetcher/src/parser/calldata_tokens.rs b/state-reconstruct-fetcher/src/parser/calldata_tokens.rs index b4c125a..40bad10 100644 --- a/state-reconstruct-fetcher/src/parser/calldata_tokens.rs +++ b/state-reconstruct-fetcher/src/parser/calldata_tokens.rs @@ -3,7 +3,7 @@ use ethers::{ types::U256, }; -use crate::types::ParseError; +use crate::ParseError; pub struct CalldataToken { pub new_blocks_data: NewBlocksDataToken, diff --git a/state-reconstruct-fetcher/src/parser/mod.rs b/state-reconstruct-fetcher/src/parser/mod.rs index e235080..06cda29 100644 --- a/state-reconstruct-fetcher/src/parser/mod.rs +++ b/state-reconstruct-fetcher/src/parser/mod.rs @@ -19,7 +19,8 @@ use crate::{ constants::ethereum::{BLOB_BLOCK, BOOJUM_BLOCK}, l1_fetcher::{Contracts, LONG_POLLING_INTERVAL_S}, metrics::L1Metrics, - types::{v1::V1, v2::V2, CommitBlock, ParseError}, + types::{v1::V1, v2::V2, CommitBlock}, + ParseError, }; // TODO: Should use the real types format instead. diff --git a/state-reconstruct-fetcher/src/types/common.rs b/state-reconstruct-fetcher/src/types/common.rs index 7a0d77a..74835ae 100644 --- a/state-reconstruct-fetcher/src/types/common.rs +++ b/state-reconstruct-fetcher/src/types/common.rs @@ -1,9 +1,10 @@ //! A collection of functions that get reused throughout format versions. use ethers::{abi, types::U256}; -use super::{L2ToL1Pubdata, PackingType, ParseError}; -use crate::constants::zksync::{ - L2_TO_L1_LOG_SERIALIZE_SIZE, LENGTH_BITS_OFFSET, OPERATION_BITMASK, +use super::{L2ToL1Pubdata, PackingType}; +use crate::{ + constants::zksync::{L2_TO_L1_LOG_SERIALIZE_SIZE, LENGTH_BITS_OFFSET, OPERATION_BITMASK}, + ParseError, }; pub struct ExtractedToken { diff --git a/state-reconstruct-fetcher/src/types/mod.rs b/state-reconstruct-fetcher/src/types/mod.rs index 1a77494..90c4748 100644 --- a/state-reconstruct-fetcher/src/types/mod.rs +++ b/state-reconstruct-fetcher/src/types/mod.rs @@ -2,10 +2,9 @@ use ethers::{abi, types::U256}; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use serde_json_any_key::any_key_map; -use thiserror::Error; use self::{v1::V1, v2::V2, v3::V3}; -use crate::blob_http_client::BlobHttpClient; +use crate::{blob_http_client::BlobHttpClient, ParseError}; // NOTE: We should probably make these more human-readable. pub mod common; @@ -13,35 +12,6 @@ pub mod v1; pub mod v2; pub mod v3; -#[allow(clippy::enum_variant_names)] -#[derive(Error, Debug)] -pub enum ParseError { - #[error("invalid Calldata: {0}")] - InvalidCalldata(String), - - #[error("invalid StoredBlockInfo: {0}")] - InvalidStoredBlockInfo(String), - - #[error("invalid CommitBlockInfo: {0}")] - InvalidCommitBlockInfo(String), - - #[allow(dead_code)] - #[error("invalid compressed bytecode: {0}")] - InvalidCompressedByteCode(String), - - #[error("invalid compressed value: {0}")] - InvalidCompressedValue(String), - - #[error("invalid pubdata source: {0}")] - InvalidPubdataSource(String), - - #[error("blob storage error: {0}")] - BlobStorageError(String), - - #[error("blob format error: {0}")] - BlobFormatError(String, String), -} - #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum PackingType { Add(U256),