Skip to content

Commit

Permalink
ref: move ParseError to lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
zeapoz committed Mar 21, 2024
1 parent 23594a4 commit 3972fa7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion state-reconstruct-fetcher/src/blob_http_client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
31 changes: 31 additions & 0 deletions state-reconstruct-fetcher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
#![feature(array_chunks)]
#![feature(iter_next_chunk)]
use thiserror::Error;

pub mod blob_http_client;
pub mod constants;
pub mod database;
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),
}
2 changes: 1 addition & 1 deletion state-reconstruct-fetcher/src/parser/calldata_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ethers::{
types::U256,
};

use crate::types::ParseError;
use crate::ParseError;

pub struct CalldataToken {
pub new_blocks_data: NewBlocksDataToken,
Expand Down
3 changes: 2 additions & 1 deletion state-reconstruct-fetcher/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions state-reconstruct-fetcher/src/types/common.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
32 changes: 1 addition & 31 deletions state-reconstruct-fetcher/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,16 @@ 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;
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),
Expand Down

0 comments on commit 3972fa7

Please sign in to comment.