Skip to content

Commit

Permalink
refactor: move state reader modules to a new crate
Browse files Browse the repository at this point in the history
commit-id:53ab0222
  • Loading branch information
Itay-Tsabary-Starkware committed Jul 16, 2024
1 parent f5eb2d5 commit e112905
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 22 deletions.
40 changes: 36 additions & 4 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ testing = []
[dependencies]
async-trait.workspace = true
axum.workspace = true
blockifier= { workspace = true, features = ["testing"] }
blockifier = { workspace = true, features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
cairo-vm.workspace = true
hyper.workspace = true
mempool_test_utils = { path = "../mempool_test_utils", version = "0.0" }
num-traits.workspace = true
papyrus_config.workspace = true
papyrus_rpc.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
starknet_sierra_compile = { path = "../starknet_sierra_compile", version = "0.0" }
starknet-types-core.workspace = true
mempool_test_utils = { path = "../mempool_test_utils", version = "0.0"}
starknet_state_reader = { path = "../state_reader", version = "0.0" }
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use starknet_api::transaction::TransactionHash;
use starknet_mempool_infra::component_runner::{ComponentStartError, ComponentStarter};
use starknet_mempool_types::communication::SharedMempoolClient;
use starknet_mempool_types::mempool_types::{Account, MempoolInput};
use starknet_state_reader::state_reader::StateReaderFactory;
use tracing::{info, instrument};

use crate::compilation::GatewayCompiler;
use crate::config::{GatewayConfig, GatewayNetworkConfig, RpcStateReaderConfig};
use crate::errors::{GatewayError, GatewayResult, GatewayRunError};
use crate::rpc_state_reader::RpcStateReaderFactory;
use crate::state_reader::StateReaderFactory;
use crate::stateful_transaction_validator::StatefulTransactionValidator;
use crate::stateless_transaction_validator::StatelessTransactionValidator;
use crate::utils::{external_tx_to_thin_tx, get_sender_address};
Expand Down
4 changes: 3 additions & 1 deletion crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ use starknet_api::rpc_transaction::RPCTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_mempool_types::communication::MockMempoolClient;
use starknet_mempool_types::mempool_types::{Account, AccountState, MempoolInput, ThinTransaction};
use starknet_state_reader::state_reader_test_utils::{
local_test_state_reader_factory, TestStateReaderFactory,
};

use crate::compilation::GatewayCompiler;
use crate::config::{
GatewayCompilerConfig, StatefulTransactionValidatorConfig, StatelessTransactionValidatorConfig,
};
use crate::gateway::{add_tx, AppState, SharedMempoolClient};
use crate::state_reader_test_utils::{local_test_state_reader_factory, TestStateReaderFactory};
use crate::stateful_transaction_validator::StatefulTransactionValidator;
use crate::stateless_transaction_validator::StatelessTransactionValidator;
use crate::utils::{external_tx_to_account_tx, get_tx_hash};
Expand Down
4 changes: 1 addition & 3 deletions crates/gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ mod rpc_objects;
mod rpc_state_reader;
#[cfg(test)]
mod rpc_state_reader_test;
mod state_reader;
#[cfg(test)]
mod state_reader_test_utils;

mod stateful_transaction_validator;
mod stateless_transaction_validator;
#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/rpc_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde_json::{json, Value};
use starknet_api::block::BlockNumber;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_state_reader::state_reader::{MempoolStateReader, StateReaderFactory};
use starknet_types_core::felt::Felt;

use crate::config::RpcStateReaderConfig;
Expand All @@ -18,7 +19,6 @@ use crate::rpc_objects::{
GetCompiledContractClassParams, GetNonceParams, GetStorageAtParams, RpcResponse,
RPC_CLASS_HASH_NOT_FOUND, RPC_ERROR_BLOCK_NOT_FOUND, RPC_ERROR_CONTRACT_ADDRESS_NOT_FOUND,
};
use crate::state_reader::{MempoolStateReader, StateReaderFactory};

pub struct RpcStateReader {
pub config: RpcStateReaderConfig,
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/rpc_state_reader_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde_json::json;
use starknet_api::block::{BlockNumber, GasPrice};
use starknet_api::core::{ClassHash, ContractAddress, Nonce, PatriciaKey};
use starknet_api::{class_hash, contract_address, felt, patricia_key};
use starknet_state_reader::state_reader::MempoolStateReader;

use crate::config::RpcStateReaderConfig;
use crate::rpc_objects::{
Expand All @@ -15,7 +16,6 @@ use crate::rpc_objects::{
RpcSuccessResponse,
};
use crate::rpc_state_reader::RpcStateReader;
use crate::state_reader::MempoolStateReader;

async fn run_rpc_server() -> mockito::ServerGuard {
mockito::Server::new_async().await
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/stateful_transaction_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use blockifier::versioned_constants::VersionedConstants;
use starknet_api::core::Nonce;
use starknet_api::rpc_transaction::{RPCInvokeTransaction, RPCTransaction};
use starknet_api::transaction::TransactionHash;
use starknet_state_reader::state_reader::{MempoolStateReader, StateReaderFactory};
use starknet_types_core::felt::Felt;

use crate::config::StatefulTransactionValidatorConfig;
use crate::errors::{StatefulTransactionValidatorError, StatefulTransactionValidatorResult};
use crate::state_reader::{MempoolStateReader, StateReaderFactory};
use crate::utils::{external_tx_to_account_tx, get_sender_address, get_tx_hash};

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions crates/gateway/src/stateful_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::felt;
use starknet_api::rpc_transaction::RPCTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_state_reader::state_reader_test_utils::{
local_test_state_reader_factory, local_test_state_reader_factory_for_deploy_account,
TestStateReader, TestStateReaderFactory,
};
use starknet_types_core::felt::Felt;

use crate::compilation::GatewayCompiler;
use crate::config::{GatewayCompilerConfig, StatefulTransactionValidatorConfig};
use crate::errors::{StatefulTransactionValidatorError, StatefulTransactionValidatorResult};
use crate::state_reader_test_utils::{
local_test_state_reader_factory, local_test_state_reader_factory_for_deploy_account,
TestStateReader, TestStateReaderFactory,
};
use crate::stateful_transaction_validator::StatefulTransactionValidator;

#[fixture]
Expand Down
37 changes: 34 additions & 3 deletions crates/state_reader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
[package]
name = "state_reader"
name = "starknet_state_reader"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]

[lints]
workspace = true

[dependencies]
async-trait.workspace = true
axum.workspace = true
blockifier = { workspace = true, features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
cairo-vm.workspace = true
hyper.workspace = true
mempool_test_utils = { path = "../mempool_test_utils", version = "0.0" }
num-traits.workspace = true
papyrus_config.workspace = true
papyrus_rpc.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
starknet_sierra_compile = { path = "../starknet_sierra_compile", version = "0.0" }
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
validator.workspace = true

[dev-dependencies]
assert_matches.workspace = true
mockall.workspace = true
mockito.workspace = true
num-bigint.workspace = true
pretty_assertions.workspace = true
rstest.workspace = true
starknet_mempool = { path = "../mempool", version = "0.0" }
2 changes: 2 additions & 0 deletions crates/state_reader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub mod state_reader;

pub mod state_reader_test_utils;
File renamed without changes.

0 comments on commit e112905

Please sign in to comment.