Skip to content

Commit

Permalink
change to domain errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sayon committed Feb 6, 2025
1 parent 402b9e6 commit fb6f92f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
43 changes: 21 additions & 22 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ use anvil_zksync_core::node::{
};
use anvil_zksync_core::observability::Observability;
use anvil_zksync_core::system_contracts::SystemContracts;

Check warning on line 19 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
use anyhow::{anyhow, Context};
use anyhow::Context;
use clap::Parser;
use zksync_error::anvil::AnvilError;
use std::fs::File;
use std::sync::Arc;
use std::time::Duration;
use std::{env, net::SocketAddr, str::FromStr};
use tokio::sync::RwLock;
use tower_http::cors::AllowOrigin;

Check warning on line 28 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
use tracing_subscriber::filter::LevelFilter;
use zksync_error::anvil::gen::{to_generic, AnvilGenericError};
use zksync_error::anvil::gen::{generic_error, to_domain};
use zksync_types::fee_model::{FeeModelConfigV2, FeeParams};
use zksync_types::{L2BlockNumber, H160};

Expand All @@ -35,25 +36,25 @@ mod cli;
mod utils;

#[tokio::main]
async fn main() -> Result<(), AnvilGenericError> {
async fn main() -> Result<(), AnvilError> {
// Check for deprecated options
Cli::deprecated_config_option();

let opt = Cli::parse();
let command = opt.command.clone();

let mut config = opt.into_test_node_config().map_err(|e| anyhow!(e))?;
let mut config = opt.into_test_node_config().map_err(to_domain)?;

let log_level_filter = LevelFilter::from(config.log_level);
let log_file = File::create(&config.log_file_path).map_err(to_generic)?;
let log_file = File::create(&config.log_file_path).map_err(to_domain)?;

// Initialize the tracing subscriber
let observability = Observability::init(
vec!["anvil_zksync".into()],
log_level_filter,

Check warning on line 54 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
log_file,
config.silent,
)?;
).map_err(to_domain)?;

// Use `Command::Run` as default.
let command = command.as_ref().unwrap_or(&Command::Run);
Expand Down Expand Up @@ -83,8 +84,8 @@ async fn main() -> Result<(), AnvilGenericError> {
} else {
// Initialize the client to get the fee params
let client =
ForkClient::at_block_number(ForkUrl::Mainnet.to_config(), None).await?;
let fee = client.get_fee_params().await?;
ForkClient::at_block_number(ForkUrl::Mainnet.to_config(), None).await.map_err(to_domain)?;
let fee = client.get_fee_params().await.map_err(to_domain)?;

match fee {
FeeParams::V2(fee_v2) => {
Expand Down Expand Up @@ -112,7 +113,7 @@ async fn main() -> Result<(), AnvilGenericError> {
.with_chain_id(config.chain_id.or(Some(TEST_NODE_NETWORK_ID)));

Check warning on line 113 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
}
FeeParams::V1(_) => {
return Err(anyhow!("Unsupported FeeParams::V1 in this context").into());
return Err(generic_error!("Unsupported FeeParams::V1 in this context").into());
}
}

Expand All @@ -122,15 +123,15 @@ async fn main() -> Result<(), AnvilGenericError> {
Command::Fork(fork) => {

Check warning on line 123 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
let (fork_client, earlier_txs) = if let Some(tx_hash) = fork.fork_transaction_hash {
// If transaction hash is provided, we fork at the parent of block containing tx
ForkClient::at_before_tx(fork.fork_url.to_config(), tx_hash).await?
ForkClient::at_before_tx(fork.fork_url.to_config(), tx_hash).await.map_err(to_domain)?
} else {
// Otherwise, we fork at the provided block
(
ForkClient::at_block_number(
fork.fork_url.to_config(),

Check warning on line 131 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
fork.fork_block_number.map(|bn| L2BlockNumber(bn as u32)),
)
.await?,
.await.map_err(to_domain)?,
Vec::new(),
)
};
Expand All @@ -140,7 +141,7 @@ async fn main() -> Result<(), AnvilGenericError> {
}

Check warning on line 141 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
Command::ReplayTx(replay_tx) => {
let (fork_client, earlier_txs) =
ForkClient::at_before_tx(replay_tx.fork_url.to_config(), replay_tx.tx).await?;
ForkClient::at_before_tx(replay_tx.fork_url.to_config(), replay_tx.tx).await.map_err(to_domain)?;

update_with_fork_details(&mut config, &fork_client.details).await;
(Some(fork_client), earlier_txs)
Expand Down Expand Up @@ -170,11 +171,10 @@ async fn main() -> Result<(), AnvilGenericError> {
}
}
_ => {
return Err(anyhow!(
return Err(to_domain(generic_error!(
"fork is using unsupported fee parameters: {:?}",
fork_client.details.fee_params
)
.into())
)))
}
};

Expand Down Expand Up @@ -267,7 +267,7 @@ async fn main() -> Result<(), AnvilGenericError> {

Check warning on line 267 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
if !transactions_to_replay.is_empty() {
node.apply_txs(transactions_to_replay, config.max_transactions)
.await?;
.await.map_err(to_domain)?;
}

// TODO: Consider moving to `InMemoryNodeInner::init`
Expand Down Expand Up @@ -298,7 +298,7 @@ async fn main() -> Result<(), AnvilGenericError> {
config

Check warning on line 298 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/anvil-zksync/anvil-zksync/crates/cli/src/main.rs
.allow_origin
.parse()
.context("allow origin is malformed")?,
.context("allow origin is malformed").map_err(to_domain)?,
),
);
if config.health_check_endpoint {
Expand Down Expand Up @@ -337,12 +337,11 @@ async fn main() -> Result<(), AnvilGenericError> {
server_handles.push(server.run());
}
Err(err) => {
return Err(anyhow!(
return Err(to_domain(generic_error!(
"Failed to start server on host {} with port: {}",
host,
err
)
.into());
)));
}
}
}
Expand All @@ -356,13 +355,13 @@ async fn main() -> Result<(), AnvilGenericError> {
let bytes = std::fs::read(load_state_path).expect("Failed to read load state file");
node.load_state(zksync_types::web3::Bytes(bytes))
.await
.map_err(to_generic)?;
.map_err(to_domain)?;
}
if let Some(ref state_path) = config.state {
let bytes = std::fs::read(state_path).expect("Failed to read load state file");
node.load_state(zksync_types::web3::Bytes(bytes))
.await
.map_err(to_generic)?;
.map_err(to_domain)?;
}

let state_path = config.dump_state.clone().or_else(|| config.state.clone());
Expand Down
1 change: 0 additions & 1 deletion crates/zksync_error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod anvil {
pub mod env {
pub use crate::error::definitions::AnvilEnvironment as AnvilEnvironmentError;
pub use crate::error::definitions::AnvilEnvironment::GenericError;
pub use crate::error::definitions::AnvilEnvironment::LogFileAccessError;
#[macro_export]
macro_rules ! anvil_env_generic_error { ($ ($ arg : tt) *) => { zksync_error :: error :: definitions :: AnvilEnvironment :: GenericError { message : format ! ($ ($ arg) *) } } ; }
pub use crate::anvil_env_generic_error as generic_error;
Expand Down

0 comments on commit fb6f92f

Please sign in to comment.