Skip to content

Commit

Permalink
refactor(blockifier_reexecution): allow overriding chain ID explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Nov 12, 2024
1 parent fb4736b commit 7a11309
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use blockifier_reexecution::state_reader::utils::{
};
use clap::{Args, Parser, Subcommand};
use starknet_api::block::BlockNumber;
use starknet_api::core::ChainId;
use starknet_gateway::config::RpcStateReaderConfig;

/// BlockifierReexecution CLI.
Expand All @@ -24,13 +25,38 @@ pub struct BlockifierReexecutionCliArgs {
command: Command,
}

#[derive(clap::ValueEnum, Clone, Debug)]
enum SupportedChainId {
Mainnet,
Testnet,
}

impl From<SupportedChainId> for ChainId {
fn from(chain_id: SupportedChainId) -> Self {
match chain_id {
SupportedChainId::Mainnet => ChainId::Mainnet,
SupportedChainId::Testnet => ChainId::Sepolia,
}
}
}

#[derive(Debug, Args)]
struct RpcArgs {
/// Node url.
#[clap(long, short = 'n')]
node_url: String,

/// Optional chain ID (if not provided, it will be guessed from the node url).
#[clap(long, short = 'c')]
chain_id: Option<SupportedChainId>,
}

#[derive(Debug, Subcommand)]
enum Command {
/// Runs the RPC test.
RpcTest {
/// Node url.
#[clap(long, short = 'n')]
node_url: String,
#[clap(flatten)]
rpc_args: RpcArgs,

/// Block number.
#[clap(long, short = 'b')]
Expand All @@ -39,9 +65,8 @@ enum Command {

/// Writes the RPC queries to json files.
WriteRpcRepliesToJson {
/// Node url.
#[clap(long, short = 'n')]
node_url: String,
#[clap(flatten)]
rpc_args: RpcArgs,

/// Block number.
#[clap(long, short = 'b')]
Expand Down Expand Up @@ -76,7 +101,7 @@ fn main() {
let args = BlockifierReexecutionCliArgs::parse();

match args.command {
Command::RpcTest { node_url, block_number } => {
Command::RpcTest { block_number, rpc_args: RpcArgs { node_url, chain_id } } => {
println!("Running RPC test for block number {block_number} using node url {node_url}.",);

let config = RpcStateReaderConfig {
Expand All @@ -87,7 +112,9 @@ fn main() {
reexecute_and_verify_correctness(ConsecutiveTestStateReaders::new(
BlockNumber(block_number - 1),
Some(config),
guess_chain_id_from_node_url(node_url.as_str()).unwrap(),
chain_id
.map(ChainId::from)
.unwrap_or(guess_chain_id_from_node_url(node_url.as_str()).unwrap()),
false,
));

Expand All @@ -96,12 +123,18 @@ fn main() {
println!("RPC test passed successfully.");
}

Command::WriteRpcRepliesToJson { node_url, block_number, full_file_path } => {
Command::WriteRpcRepliesToJson {
block_number,
full_file_path,
rpc_args: RpcArgs { node_url, chain_id },
} => {
let full_file_path = full_file_path.unwrap_or(format!(
"./crates/blockifier_reexecution/resources/block_{block_number}/reexecution_data.\
json"
));
let chain_id = guess_chain_id_from_node_url(node_url.as_str()).unwrap();
let chain_id = chain_id
.map(ChainId::from)
.unwrap_or(guess_chain_id_from_node_url(node_url.as_str()).unwrap());

// TODO(Aner): refactor to reduce code duplication.
let config = RpcStateReaderConfig {
Expand Down

0 comments on commit 7a11309

Please sign in to comment.