Skip to content

Commit

Permalink
refactor(blockifier_reexecution): set chain ID by inspecting RPC URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Nov 12, 2024
1 parent a4d664b commit f729381
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use blockifier_reexecution::state_reader::test_state_reader::{
SerializableOfflineReexecutionData,
};
use blockifier_reexecution::state_reader::utils::{
guess_chain_id_from_node_url,
reexecute_and_verify_correctness,
JSON_RPC_VERSION,
};
use clap::{Args, Parser, Subcommand};
use starknet_api::block::BlockNumber;
use starknet_api::core::ChainId;
use starknet_gateway::config::RpcStateReaderConfig;

/// BlockifierReexecution CLI.
Expand Down Expand Up @@ -80,14 +80,14 @@ fn main() {
println!("Running RPC test for block number {block_number} using node url {node_url}.",);

let config = RpcStateReaderConfig {
url: node_url,
url: node_url.clone(),
json_rpc_version: JSON_RPC_VERSION.to_string(),
};

reexecute_and_verify_correctness(ConsecutiveTestStateReaders::new(
BlockNumber(block_number - 1),
Some(config),
ChainId::Mainnet,
guess_chain_id_from_node_url(node_url.as_str()).unwrap(),
false,
));

Expand All @@ -101,6 +101,7 @@ fn main() {
"./crates/blockifier_reexecution/resources/block_{block_number}/reexecution_data.\
json"
));
let chain_id = guess_chain_id_from_node_url(node_url.as_str()).unwrap();

// TODO(Aner): refactor to reduce code duplication.
let config = RpcStateReaderConfig {
Expand All @@ -111,7 +112,7 @@ fn main() {
let consecutive_state_readers = ConsecutiveTestStateReaders::new(
BlockNumber(block_number - 1),
Some(config),
ChainId::Mainnet,
chain_id.clone(),
true,
);

Expand All @@ -134,7 +135,7 @@ fn main() {
SerializableOfflineReexecutionData {
serializable_data_prev_block,
serializable_data_next_block,
chain_id: ChainId::Mainnet,
chain_id,
old_block_hash,
}
.write_to_file(&full_file_path)
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier_reexecution/src/state_reader/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use thiserror::Error;
#[derive(Debug, Error)]
#[allow(clippy::enum_variant_names)]
pub enum ReexecutionError {
#[error("Cannot discern chain ID from URL: {0}")]
AmbiguousChainIdFromUrl(String),
#[error(transparent)]
Rpc(#[from] RPCStateReaderError),
#[error(transparent)]
Expand Down
13 changes: 13 additions & 0 deletions crates/blockifier_reexecution/src/state_reader/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ use crate::state_reader::errors::ReexecutionError;
use crate::state_reader::test_state_reader::{
ConsecutiveStateReaders,
OfflineConsecutiveStateReaders,
ReexecutionResult,
};

pub const RPC_NODE_URL: &str = "https://free-rpc.nethermind.io/mainnet-juno/";
pub const JSON_RPC_VERSION: &str = "2.0";

pub fn guess_chain_id_from_node_url(node_url: &str) -> ReexecutionResult<ChainId> {
if node_url.contains("mainnet") {
Ok(ChainId::Mainnet)
} else if node_url.contains("sepolia") && !node_url.contains("integration") {
Ok(ChainId::Sepolia)
} else if node_url.contains("integration") {
Ok(ChainId::IntegrationSepolia)
} else {
Err(ReexecutionError::AmbiguousChainIdFromUrl(node_url.to_string()))
}
}

/// Returns the fee token addresses of mainnet.
pub fn get_fee_token_addresses(chain_id: &ChainId) -> FeeTokenAddresses {
match chain_id {
Expand Down

0 comments on commit f729381

Please sign in to comment.