Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions crates/apollo_gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ apollo_metrics.workspace = true
apollo_network_types.workspace = true
apollo_proc_macros.workspace = true
apollo_proof_manager_types.workspace = true
apollo_rpc.workspace = true
apollo_state_sync_types.workspace = true
async-trait.workspace = true
axum.workspace = true
blockifier.workspace = true
blockifier_test_utils = { workspace = true, optional = true }
cairo-lang-starknet-classes.workspace = true
clap.workspace = true
google-cloud-storage.workspace = true
mempool_test_utils.workspace = true
mockall.workspace = true
num-rational.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
Expand Down
48 changes: 0 additions & 48 deletions crates/apollo_gateway/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use apollo_gateway_types::errors::GatewaySpecError;
use apollo_gateway_types::gateway_types::SUPPORTED_TRANSACTION_VERSIONS;
use apollo_mempool_types::communication::{MempoolClientError, MempoolClientResult};
use apollo_mempool_types::errors::MempoolError;
use blockifier::state::errors::StateError;
use reqwest::StatusCode;
use serde_json::{Error as SerdeError, Value};
use starknet_api::block::GasPrice;
use starknet_api::executable_transaction::ValidateCompiledClassHashError;
use starknet_api::execution_resources::GasAmount;
Expand All @@ -21,8 +18,6 @@ use starknet_api::StarknetApiError;
use thiserror::Error;
use tracing::{debug, error, warn};

use crate::rpc_objects::{RpcErrorCode, RpcErrorResponse};

pub type GatewayResult<T> = Result<T, StarknetError>;

#[derive(Debug, Error)]
Expand Down Expand Up @@ -301,49 +296,6 @@ pub type StatelessTransactionValidatorResult<T> = Result<T, StatelessTransaction

pub type StatefulTransactionValidatorResult<T> = Result<T, StarknetError>;

#[derive(Debug, Error)]
pub enum RPCStateReaderError {
#[error("Block not found for request {0}")]
BlockNotFound(Value),
#[error("Class hash not found for request {0}")]
ClassHashNotFound(Value),
#[error("Contract address not found for request {0}")]
ContractAddressNotFound(Value),
#[error("Failed to parse gas price {:?}", 0)]
GasPriceParsingFailure(GasPrice),
#[error("Invalid params: {0:?}")]
InvalidParams(Box<RpcErrorResponse>),
#[error("RPC error: {0}")]
RPCError(StatusCode),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
#[error("Unexpected error code: {0}")]
UnexpectedErrorCode(RpcErrorCode),
#[error(transparent)]
StarknetApi(#[from] StarknetApiError),
}

pub type RPCStateReaderResult<T> = Result<T, RPCStateReaderError>;

impl From<RPCStateReaderError> for StateError {
fn from(err: RPCStateReaderError) -> Self {
match err {
RPCStateReaderError::ClassHashNotFound(request) => {
match serde_json::from_value(request["params"]["class_hash"].clone()) {
Ok(class_hash) => StateError::UndeclaredClassHash(class_hash),
Err(e) => serde_err_to_state_err(e),
}
}
_ => StateError::StateReadError(err.to_string()),
}
}
}

// Converts a serde error to the error type of the state reader.
pub fn serde_err_to_state_err(err: SerdeError) -> StateError {
StateError::StateReadError(format!("Failed to parse rpc result {:?}", err.to_string()))
}

pub fn transaction_converter_err_to_deprecated_gw_err(
tx_signature: &TransactionSignature,
err: TransactionConverterError,
Expand Down
4 changes: 0 additions & 4 deletions crates/apollo_gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ pub mod gateway;
pub mod gateway_fixed_block_state_reader;
pub mod metrics;
pub mod proof_archive_writer;
pub mod rpc_objects;
pub mod rpc_state_reader;
#[cfg(test)]
mod rpc_state_reader_test;
mod state_reader;
#[cfg(any(feature = "testing", test))]
mod state_reader_test_utils;
Expand Down
1 change: 0 additions & 1 deletion crates/apollo_gateway_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod compiler_version;
pub mod config;
pub mod rpc_state_reader_config;
9 changes: 7 additions & 2 deletions crates/blockifier_reexecution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cairo_native = ["blockifier/cairo_native"]
[dependencies]
apollo_compile_to_casm.workspace = true
apollo_compile_to_casm_types.workspace = true
apollo_gateway.workspace = true
apollo_gateway_config.workspace = true
apollo_config.workspace = true
apollo_rpc.workspace = true
apollo_rpc_execution.workspace = true
apollo_sierra_compilation_config.workspace = true
assert_matches.workspace = true
Expand All @@ -24,6 +24,7 @@ flate2.workspace = true
google-cloud-storage.workspace = true
indexmap = { workspace = true, features = ["serde"] }
pretty_assertions.workspace = true
reqwest = { workspace = true, features = ["blocking", "json"] }
retry.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -32,9 +33,13 @@ starknet-types-core.workspace = true
starknet_api.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
validator.workspace = true

[dev-dependencies]
cairo-lang-starknet-classes.workspace = true
mockito.workspace = true
rstest.workspace = true
starknet_api = { workspace = true, features = ["testing"] }

[lints]
workspace = true
52 changes: 50 additions & 2 deletions crates/blockifier_reexecution/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
use apollo_gateway::errors::RPCStateReaderError;
use blockifier::blockifier::transaction_executor::TransactionExecutorError;
use blockifier::blockifier_versioned_constants::VersionedConstantsError;
use blockifier::state::errors::StateError;
use blockifier::transaction::errors::TransactionExecutionError;
use serde_json::Error as SerdeError;
use reqwest::StatusCode;
use serde_json::{Error as SerdeError, Value};
use starknet_api::block::GasPrice;
use starknet_api::StarknetApiError;
use thiserror::Error;

use crate::rpc_state_reader::rpc_objects::{RpcErrorCode, RpcErrorResponse};

#[derive(Debug, Error)]
pub enum RPCStateReaderError {
#[error("Block not found for request {0}")]
BlockNotFound(Value),
#[error("Class hash not found for request {0}")]
ClassHashNotFound(Value),
#[error("Contract address not found for request {0}")]
ContractAddressNotFound(Value),
#[error("Failed to parse gas price {:?}", 0)]
GasPriceParsingFailure(GasPrice),
#[error("Invalid params: {0:?}")]
InvalidParams(Box<RpcErrorResponse>),
#[error("RPC error: {0}")]
RPCError(StatusCode),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
#[error("Unexpected error code: {0}")]
UnexpectedErrorCode(RpcErrorCode),
#[error(transparent)]
StarknetApi(#[from] StarknetApiError),
#[error("Internal error: {0}")]
InternalError(String),
}

pub type RPCStateReaderResult<T> = Result<T, RPCStateReaderError>;

impl From<RPCStateReaderError> for StateError {
fn from(err: RPCStateReaderError) -> Self {
match err {
RPCStateReaderError::ClassHashNotFound(request) => {
match serde_json::from_value(request["params"]["class_hash"].clone()) {
Ok(class_hash) => StateError::UndeclaredClassHash(class_hash),
Err(e) => serde_err_to_state_err(e),
}
}
_ => StateError::StateReadError(err.to_string()),
}
}
}

// Converts a serde error to the error type of the state reader.
pub fn serde_err_to_state_err(err: SerdeError) -> StateError {
StateError::StateReadError(format!("Failed to parse rpc result {:?}", err.to_string()))
}

#[derive(Debug, Error)]
#[allow(clippy::enum_variant_names)]
pub enum ReexecutionError {
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier_reexecution/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
pub mod cli;
pub mod compile;
pub mod errors;
pub mod rpc_state_reader;
pub mod serde_utils;
pub mod state_reader;
pub mod utils;

use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
use blockifier::blockifier::config::ContractClassManagerConfig;
use blockifier::blockifier::transaction_executor::TransactionExecutionOutput;
use blockifier::context::BlockContext;
use blockifier::state::cached_state::StateMaps;
use blockifier::state::contract_class_manager::ContractClassManager;
use errors::ReexecutionResult;
use rpc_state_reader::config::RpcStateReaderConfig;
use starknet_api::block::BlockNumber;
use starknet_api::core::ChainId;
use starknet_api::transaction::Transaction;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fs;
use std::path::Path;

use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
use blockifier::blockifier::config::ContractClassManagerConfig;
use blockifier::state::contract_class_manager::ContractClassManager;
use blockifier_reexecution::cli::{
Expand All @@ -11,6 +10,7 @@ use blockifier_reexecution::cli::{
TransactionInput,
FULL_RESOURCES_DIR,
};
use blockifier_reexecution::rpc_state_reader::config::RpcStateReaderConfig;
use blockifier_reexecution::state_reader::offline_state_reader::OfflineConsecutiveStateReaders;
use blockifier_reexecution::state_reader::reexecution_state_reader::ConsecutiveReexecutionStateReaders;
use blockifier_reexecution::state_reader::rpc_state_reader::ConsecutiveRpcStateReaders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Default for RpcStateReaderConfig {
}
}

#[cfg(any(feature = "testing", test))]
#[cfg(test)]
impl RpcStateReaderConfig {
pub fn create_for_testing() -> Self {
Self::from_url("http://localhost:8080".to_string())
Expand Down
6 changes: 6 additions & 0 deletions crates/blockifier_reexecution/src/rpc_state_reader/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod config;
pub mod rpc_objects;
#[allow(clippy::module_inception)]
pub mod rpc_state_reader;
#[cfg(test)]
mod rpc_state_reader_test;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
use apollo_rpc::CompiledContractClass;
use blockifier::execution::contract_class::{
CompiledClassV0,
Expand All @@ -17,7 +16,8 @@ use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;

use crate::errors::{serde_err_to_state_err, RPCStateReaderError, RPCStateReaderResult};
use crate::rpc_objects::{
use crate::rpc_state_reader::config::RpcStateReaderConfig;
use crate::rpc_state_reader::rpc_objects::{
BlockId,
GetClassHashAtParams,
GetCompiledClassParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
use apollo_rpc::CompiledContractClass;
use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::state::state_api::StateReader;
Expand All @@ -8,7 +7,8 @@ use serde_json::json;
use starknet_api::contract_class::SierraVersion;
use starknet_api::{class_hash, contract_address, felt, nonce};

use crate::rpc_objects::{
use crate::rpc_state_reader::config::RpcStateReaderConfig;
use crate::rpc_state_reader::rpc_objects::{
BlockId,
GetClassHashAtParams,
GetCompiledClassParams,
Expand All @@ -17,7 +17,7 @@ use crate::rpc_objects::{
RpcResponse,
RpcSuccessResponse,
};
use crate::rpc_state_reader::RpcStateReader;
use crate::rpc_state_reader::rpc_state_reader::RpcStateReader;

async fn run_rpc_server() -> mockito::ServerGuard {
mockito::Server::new_async().await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use apollo_gateway::rpc_objects::BlockHeader;
use assert_matches::assert_matches;
use blockifier::state::cached_state::StateMaps;
use pretty_assertions::assert_eq;
Expand All @@ -17,6 +16,7 @@ use starknet_api::{class_hash, compiled_class_hash, contract_address, felt, nonc
use starknet_core::types::ContractClass;

use crate::compile::legacy_to_contract_class_v0;
use crate::rpc_state_reader::rpc_objects::BlockHeader;
use crate::serde_utils::deserialize_transaction_json_to_starknet_api_tx;

#[fixture]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use std::collections::HashMap;
use std::fs::read_to_string;
use std::sync::{Arc, Mutex};

use apollo_gateway::errors::{serde_err_to_state_err, RPCStateReaderError};
use apollo_gateway::rpc_objects::{BlockHeader, BlockId, GetBlockWithTxHashesParams};
use apollo_gateway::rpc_state_reader::RpcStateReader as GatewayRpcStateReader;
use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
use assert_matches::assert_matches;
use blockifier::abi::constants;
use blockifier::blockifier::config::TransactionExecutorConfig;
Expand Down Expand Up @@ -40,8 +36,11 @@ use starknet_types_core::felt::Felt;

use crate::cli::TransactionInput;
use crate::compile::{legacy_to_contract_class_v0, sierra_to_versioned_contract_class_v1};
use crate::errors::ReexecutionResult;
use crate::errors::{serde_err_to_state_err, RPCStateReaderError, ReexecutionResult};
use crate::retry_request;
use crate::rpc_state_reader::config::RpcStateReaderConfig;
use crate::rpc_state_reader::rpc_objects::{BlockHeader, BlockId, GetBlockWithTxHashesParams};
use crate::rpc_state_reader::rpc_state_reader::RpcStateReader as GatewayRpcStateReader;
use crate::serde_utils::{
deserialize_transaction_json_to_starknet_api_tx,
hashmap_from_raw,
Expand Down
Loading
Loading