diff --git a/crates/blockifier_reexecution/src/main.rs b/crates/blockifier_reexecution/src/main.rs index fa99d0ecc2..f058390dbe 100644 --- a/crates/blockifier_reexecution/src/main.rs +++ b/crates/blockifier_reexecution/src/main.rs @@ -8,7 +8,6 @@ use blockifier_reexecution::state_reader::utils::{ guess_chain_id_from_node_url, reexecute_and_verify_correctness, write_block_reexecution_data_to_file, - JSON_RPC_VERSION, }; use clap::{Args, Parser, Subcommand}; use google_cloud_storage::client::{Client, ClientConfig}; @@ -181,10 +180,7 @@ async fn main() { rpc_args.node_url ); - let config = RpcStateReaderConfig { - url: rpc_args.node_url.clone(), - json_rpc_version: JSON_RPC_VERSION.to_string(), - }; + let config = RpcStateReaderConfig::from_url(rpc_args.node_url.clone()); // RPC calls are "synchronous IO" (see, e.g., https://stackoverflow.com/questions/74547541/when-should-you-use-tokios-spawn-blocking) // for details), so should be executed in a blocking thread. diff --git a/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs b/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs index 55e48c3911..49084ecdb6 100644 --- a/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs +++ b/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs @@ -89,7 +89,7 @@ pub fn get_test_block_id() -> BlockId { } pub fn get_test_rpc_config() -> RpcStateReaderConfig { - RpcStateReaderConfig { url: get_test_url(), json_rpc_version: "2.0".to_string() } + RpcStateReaderConfig::from_url(get_test_url()) } #[fixture] diff --git a/crates/blockifier_reexecution/src/state_reader/utils.rs b/crates/blockifier_reexecution/src/state_reader/utils.rs index 3742e1e033..edbfa1b99f 100644 --- a/crates/blockifier_reexecution/src/state_reader/utils.rs +++ b/crates/blockifier_reexecution/src/state_reader/utils.rs @@ -31,7 +31,6 @@ pub static RPC_NODE_URL: LazyLock = LazyLock::new(|| { env::var("TEST_URL") .unwrap_or_else(|_| "https://free-rpc.nethermind.io/mainnet-juno/".to_string()) }); -pub const JSON_RPC_VERSION: &str = "2.0"; pub fn guess_chain_id_from_node_url(node_url: &str) -> ReexecutionResult { match ( @@ -59,12 +58,9 @@ pub fn get_fee_token_addresses(chain_id: &ChainId) -> FeeTokenAddresses { } } -/// Returns the RPC state reader configuration with the constants RPC_NODE_URL and JSON_RPC_VERSION. +/// Returns the RPC state reader configuration with the constant RPC_NODE_URL. pub fn get_rpc_state_reader_config() -> RpcStateReaderConfig { - RpcStateReaderConfig { - url: RPC_NODE_URL.clone(), - json_rpc_version: JSON_RPC_VERSION.to_string(), - } + RpcStateReaderConfig::from_url(RPC_NODE_URL.clone()) } /// Returns the chain info of mainnet. @@ -260,8 +256,7 @@ pub fn write_block_reexecution_data_to_file( node_url: String, chain_id: ChainId, ) { - let config = - RpcStateReaderConfig { url: node_url, json_rpc_version: JSON_RPC_VERSION.to_string() }; + let config = RpcStateReaderConfig::from_url(node_url); let consecutive_state_readers = ConsecutiveTestStateReaders::new( block_number.prev().expect("Should not run with block 0"), diff --git a/crates/papyrus_load_test/Cargo.toml b/crates/papyrus_load_test/Cargo.toml index b321a4481c..ce1ffdaf6a 100644 --- a/crates/papyrus_load_test/Cargo.toml +++ b/crates/papyrus_load_test/Cargo.toml @@ -17,7 +17,7 @@ rand.workspace = true reqwest.workspace = true serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["arbitrary_precision"] } -starknet_api.workspace = true +starknet_api = { workspace = true, features = ["testing"] } tokio.workspace = true [dev-dependencies] diff --git a/crates/starknet_gateway/src/config.rs b/crates/starknet_gateway/src/config.rs index f0e02aee90..2ce2c97654 100644 --- a/crates/starknet_gateway/src/config.rs +++ b/crates/starknet_gateway/src/config.rs @@ -11,6 +11,8 @@ use validator::Validate; use crate::compiler_version::VersionId; +const JSON_RPC_VERSION: &str = "2.0"; + #[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)] pub struct GatewayConfig { pub stateless_tx_validator_config: StatelessTransactionValidatorConfig, @@ -119,16 +121,28 @@ impl SerializeConfig for StatelessTransactionValidatorConfig { } } -#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] pub struct RpcStateReaderConfig { pub url: String, pub json_rpc_version: String, } +impl RpcStateReaderConfig { + pub fn from_url(url: String) -> Self { + Self { url, ..Default::default() } + } +} + +impl Default for RpcStateReaderConfig { + fn default() -> Self { + Self { url: Default::default(), json_rpc_version: JSON_RPC_VERSION.to_string() } + } +} + #[cfg(any(feature = "testing", test))] impl RpcStateReaderConfig { pub fn create_for_testing() -> Self { - Self { url: "http://localhost:8080".to_string(), json_rpc_version: "2.0".to_string() } + Self::from_url("http://localhost:8080".to_string()) } } diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index 6715c197b1..09fef5ddfa 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -60,7 +60,6 @@ pub(crate) fn dump_config_file_changes( required_params.eth_fee_token_address, required_params.strk_fee_token_address, required_params.validator_id, - config.rpc_state_reader_config.json_rpc_version, config.rpc_state_reader_config.url, config.batcher_config.storage.db_config.path_prefix, config.http_server_config.ip, diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index f54e7a4d61..0afe826368 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -128,11 +128,7 @@ pub fn create_consensus_manager_configs_and_channels( pub fn test_rpc_state_reader_config(rpc_server_addr: SocketAddr) -> RpcStateReaderConfig { // TODO(Tsabary): get the latest version from the RPC crate. const RPC_SPEC_VERSION: &str = "V0_8"; - const JSON_RPC_VERSION: &str = "2.0"; - RpcStateReaderConfig { - url: format!("http://{rpc_server_addr:?}/rpc/{RPC_SPEC_VERSION}"), - json_rpc_version: JSON_RPC_VERSION.to_string(), - } + RpcStateReaderConfig::from_url(format!("http://{rpc_server_addr:?}/rpc/{RPC_SPEC_VERSION}")) } /// Creates a multi-account transaction generator for integration tests.