Skip to content

Commit eccb269

Browse files
committed
blockifier_reexecution: move rpc_state_reader from apollo_gateway into
1 parent 615b58b commit eccb269

File tree

20 files changed

+89
-89
lines changed

20 files changed

+89
-89
lines changed

Cargo.lock

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_gateway/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ apollo_mempool_types.workspace = true
2727
apollo_metrics.workspace = true
2828
apollo_network_types.workspace = true
2929
apollo_proc_macros.workspace = true
30-
apollo_rpc.workspace = true
3130
apollo_state_sync_types.workspace = true
3231
async-trait.workspace = true
3332
axum.workspace = true
3433
blockifier.workspace = true
3534
blockifier_test_utils = { workspace = true, optional = true }
36-
cairo-lang-starknet-classes.workspace = true
3735
clap.workspace = true
3836
mempool_test_utils.workspace = true
3937
num-rational.workspace = true
40-
reqwest.workspace = true
41-
serde.workspace = true
4238
serde_json.workspace = true
4339
starknet-types-core.workspace = true
4440
starknet_api.workspace = true

crates/apollo_gateway/src/errors.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ use apollo_gateway_types::errors::GatewaySpecError;
1010
use apollo_gateway_types::gateway_types::SUPPORTED_TRANSACTION_VERSIONS;
1111
use apollo_mempool_types::communication::{MempoolClientError, MempoolClientResult};
1212
use apollo_mempool_types::errors::MempoolError;
13-
use blockifier::state::errors::StateError;
14-
use reqwest::StatusCode;
15-
use serde_json::{Error as SerdeError, Value};
1613
use starknet_api::block::GasPrice;
1714
use starknet_api::executable_transaction::ValidateCompiledClassHashError;
1815
use starknet_api::execution_resources::GasAmount;
@@ -21,8 +18,6 @@ use starknet_api::StarknetApiError;
2118
use thiserror::Error;
2219
use tracing::{debug, error, warn};
2320

24-
use crate::rpc_objects::{RpcErrorCode, RpcErrorResponse};
25-
2621
pub type GatewayResult<T> = Result<T, StarknetError>;
2722

2823
#[derive(Debug, Error)]
@@ -291,49 +286,6 @@ pub type StatelessTransactionValidatorResult<T> = Result<T, StatelessTransaction
291286

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

294-
#[derive(Debug, Error)]
295-
pub enum RPCStateReaderError {
296-
#[error("Block not found for request {0}")]
297-
BlockNotFound(Value),
298-
#[error("Class hash not found for request {0}")]
299-
ClassHashNotFound(Value),
300-
#[error("Contract address not found for request {0}")]
301-
ContractAddressNotFound(Value),
302-
#[error("Failed to parse gas price {:?}", 0)]
303-
GasPriceParsingFailure(GasPrice),
304-
#[error("Invalid params: {0:?}")]
305-
InvalidParams(Box<RpcErrorResponse>),
306-
#[error("RPC error: {0}")]
307-
RPCError(StatusCode),
308-
#[error(transparent)]
309-
ReqwestError(#[from] reqwest::Error),
310-
#[error("Unexpected error code: {0}")]
311-
UnexpectedErrorCode(RpcErrorCode),
312-
#[error(transparent)]
313-
StarknetApi(#[from] StarknetApiError),
314-
}
315-
316-
pub type RPCStateReaderResult<T> = Result<T, RPCStateReaderError>;
317-
318-
impl From<RPCStateReaderError> for StateError {
319-
fn from(err: RPCStateReaderError) -> Self {
320-
match err {
321-
RPCStateReaderError::ClassHashNotFound(request) => {
322-
match serde_json::from_value(request["params"]["class_hash"].clone()) {
323-
Ok(class_hash) => StateError::UndeclaredClassHash(class_hash),
324-
Err(e) => serde_err_to_state_err(e),
325-
}
326-
}
327-
_ => StateError::StateReadError(err.to_string()),
328-
}
329-
}
330-
}
331-
332-
// Converts a serde error to the error type of the state reader.
333-
pub fn serde_err_to_state_err(err: SerdeError) -> StateError {
334-
StateError::StateReadError(format!("Failed to parse rpc result {:?}", err.to_string()))
335-
}
336-
337289
pub fn transaction_converter_err_to_deprecated_gw_err(
338290
tx_signature: &TransactionSignature,
339291
err: TransactionConverterError,

crates/apollo_gateway/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ pub mod errors;
33
pub mod gateway;
44
pub mod gateway_fixed_block_state_reader;
55
pub mod metrics;
6-
pub mod rpc_objects;
7-
pub mod rpc_state_reader;
8-
#[cfg(test)]
9-
mod rpc_state_reader_test;
106
mod state_reader;
117
#[cfg(any(feature = "testing", test))]
128
mod state_reader_test_utils;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
pub mod compiler_version;
22
pub mod config;
3-
pub mod rpc_state_reader_config;

crates/blockifier_reexecution/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ cairo_native = ["blockifier/cairo_native"]
1212
[dependencies]
1313
apollo_compile_to_casm.workspace = true
1414
apollo_compile_to_casm_types.workspace = true
15-
apollo_gateway.workspace = true
16-
apollo_gateway_config.workspace = true
15+
apollo_config.workspace = true
16+
apollo_rpc.workspace = true
1717
apollo_rpc_execution.workspace = true
1818
apollo_sierra_compilation_config.workspace = true
1919
assert_matches.workspace = true
@@ -23,16 +23,20 @@ flate2.workspace = true
2323
google-cloud-storage.workspace = true
2424
indexmap = { workspace = true, features = ["serde"] }
2525
pretty_assertions.workspace = true
26+
reqwest = { workspace = true, features = ["blocking", "json"] }
2627
retry.workspace = true
2728
serde.workspace = true
2829
serde_json.workspace = true
2930
starknet-core.workspace = true
3031
starknet-types-core.workspace = true
31-
starknet_api.workspace = true
32+
starknet_api = { workspace = true, features = ["testing"] }
3233
thiserror.workspace = true
3334
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
35+
validator.workspace = true
3436

3537
[dev-dependencies]
38+
cairo-lang-starknet-classes.workspace = true
39+
mockito.workspace = true
3640
rstest.workspace = true
3741

3842
[lints]

crates/blockifier_reexecution/src/errors.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,60 @@
1-
use apollo_gateway::errors::RPCStateReaderError;
21
use blockifier::blockifier::transaction_executor::TransactionExecutorError;
32
use blockifier::blockifier_versioned_constants::VersionedConstantsError;
43
use blockifier::state::errors::StateError;
54
use blockifier::transaction::errors::TransactionExecutionError;
6-
use serde_json::Error as SerdeError;
5+
use reqwest::StatusCode;
6+
use serde_json::{Error as SerdeError, Value};
7+
use starknet_api::block::GasPrice;
78
use starknet_api::StarknetApiError;
89
use thiserror::Error;
910

11+
use crate::rpc_state_reader::rpc_objects::{RpcErrorCode, RpcErrorResponse};
12+
13+
#[derive(Debug, Error)]
14+
pub enum RPCStateReaderError {
15+
#[error("Block not found for request {0}")]
16+
BlockNotFound(Value),
17+
#[error("Class hash not found for request {0}")]
18+
ClassHashNotFound(Value),
19+
#[error("Contract address not found for request {0}")]
20+
ContractAddressNotFound(Value),
21+
#[error("Failed to parse gas price {:?}", 0)]
22+
GasPriceParsingFailure(GasPrice),
23+
#[error("Invalid params: {0:?}")]
24+
InvalidParams(Box<RpcErrorResponse>),
25+
#[error("RPC error: {0}")]
26+
RPCError(StatusCode),
27+
#[error(transparent)]
28+
ReqwestError(#[from] reqwest::Error),
29+
#[error("Unexpected error code: {0}")]
30+
UnexpectedErrorCode(RpcErrorCode),
31+
#[error(transparent)]
32+
StarknetApi(#[from] StarknetApiError),
33+
#[error("Internal error: {0}")]
34+
InternalError(String),
35+
}
36+
37+
pub type RPCStateReaderResult<T> = Result<T, RPCStateReaderError>;
38+
39+
impl From<RPCStateReaderError> for StateError {
40+
fn from(err: RPCStateReaderError) -> Self {
41+
match err {
42+
RPCStateReaderError::ClassHashNotFound(request) => {
43+
match serde_json::from_value(request["params"]["class_hash"].clone()) {
44+
Ok(class_hash) => StateError::UndeclaredClassHash(class_hash),
45+
Err(e) => serde_err_to_state_err(e),
46+
}
47+
}
48+
_ => StateError::StateReadError(err.to_string()),
49+
}
50+
}
51+
}
52+
53+
// Converts a serde error to the error type of the state reader.
54+
pub fn serde_err_to_state_err(err: SerdeError) -> StateError {
55+
StateError::StateReadError(format!("Failed to parse rpc result {:?}", err.to_string()))
56+
}
57+
1058
#[derive(Debug, Error)]
1159
#[allow(clippy::enum_variant_names)]
1260
pub enum ReexecutionError {

crates/blockifier_reexecution/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
pub mod cli;
22
pub mod compile;
33
pub mod errors;
4+
pub mod rpc_state_reader;
45
pub mod serde_utils;
56
pub mod state_reader;
67
pub mod utils;
78

8-
use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
99
use blockifier::blockifier::config::ContractClassManagerConfig;
1010
use blockifier::blockifier::transaction_executor::TransactionExecutionOutput;
1111
use blockifier::context::BlockContext;
1212
use blockifier::state::cached_state::StateMaps;
1313
use blockifier::state::contract_class_manager::ContractClassManager;
1414
use errors::ReexecutionResult;
15+
use rpc_state_reader::config::RpcStateReaderConfig;
1516
use starknet_api::block::BlockNumber;
1617
use starknet_api::core::ChainId;
1718
use starknet_api::transaction::Transaction;

crates/blockifier_reexecution/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::fs;
22
use std::path::Path;
33

4-
use apollo_gateway_config::rpc_state_reader_config::RpcStateReaderConfig;
54
use blockifier::blockifier::config::ContractClassManagerConfig;
65
use blockifier::state::contract_class_manager::ContractClassManager;
76
use blockifier_reexecution::cli::{
@@ -11,6 +10,7 @@ use blockifier_reexecution::cli::{
1110
TransactionInput,
1211
FULL_RESOURCES_DIR,
1312
};
13+
use blockifier_reexecution::rpc_state_reader::config::RpcStateReaderConfig;
1414
use blockifier_reexecution::state_reader::offline_state_reader::OfflineConsecutiveStateReaders;
1515
use blockifier_reexecution::state_reader::reexecution_state_reader::ConsecutiveReexecutionStateReaders;
1616
use blockifier_reexecution::state_reader::rpc_state_reader::ConsecutiveRpcStateReaders;

crates/apollo_gateway_config/src/rpc_state_reader_config.rs renamed to crates/blockifier_reexecution/src/rpc_state_reader/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Default for RpcStateReaderConfig {
2525
}
2626
}
2727

28-
#[cfg(any(feature = "testing", test))]
28+
#[cfg(test)]
2929
impl RpcStateReaderConfig {
3030
pub fn create_for_testing() -> Self {
3131
Self::from_url("http://localhost:8080".to_string())

0 commit comments

Comments
 (0)