Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blockifier_reexecution): add chain ID to TestStateReader #1971

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 Down Expand Up @@ -130,6 +131,7 @@ async fn main() {
reexecute_and_verify_correctness(ConsecutiveTestStateReaders::new(
BlockNumber(block_number - 1),
Some(config),
ChainId::Mainnet,
false,
))
})
Expand All @@ -155,6 +157,7 @@ async fn main() {
BlockNumber(block_number),
full_file_path,
node_url,
ChainId::Mainnet,
);
})
.await
Expand All @@ -179,7 +182,12 @@ async fn main() {
// TODO(Aner): make only the RPC calls blocking, not the whole function.
tokio::task::spawn_blocking(move || {
println!("Computing reexecution data for block {block_number}.");
write_block_reexecution_data_to_file(block_number, full_file_path, node_url)
write_block_reexecution_data_to_file(
block_number,
full_file_path,
node_url,
ChainId::Mainnet,
)
})
.await
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use blockifier::blockifier::block::BlockInfo;
use rstest::{fixture, rstest};
use starknet_api::block::BlockNumber;
use starknet_api::class_hash;
use starknet_api::core::ChainId;
use starknet_api::transaction::{
DeclareTransaction,
DeployAccountTransaction,
Expand Down Expand Up @@ -93,6 +94,7 @@ pub fn test_state_reader() -> TestStateReader {
block_id: get_test_block_id(),
},
retry_config: RetryConfig::default(),
chain_id: ChainId::Mainnet,
contract_class_mapping_dumper: Arc::new(Mutex::new(None)),
}
}
Expand All @@ -111,7 +113,7 @@ pub fn last_constructed_block(test_block_number: BlockNumber) -> BlockNumber {
pub fn test_state_readers_last_and_current_block(
last_constructed_block: BlockNumber,
) -> ConsecutiveTestStateReaders {
ConsecutiveTestStateReaders::new(last_constructed_block, None, false)
ConsecutiveTestStateReaders::new(last_constructed_block, None, ChainId::Mainnet, false)
}

/// Test that the block info can be retrieved from the RPC server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl Default for RetryConfig {
pub struct TestStateReader {
pub(crate) rpc_state_reader: RpcStateReader,
pub(crate) retry_config: RetryConfig,
pub(crate) chain_id: ChainId,
#[allow(dead_code)]
pub(crate) contract_class_mapping_dumper: Arc<Mutex<Option<StarknetContractClassMapping>>>,
}
Expand All @@ -185,6 +186,7 @@ impl Default for TestStateReader {
Self {
rpc_state_reader: RpcStateReader::from_latest(&get_rpc_state_reader_config()),
retry_config: RetryConfig::default(),
chain_id: ChainId::Mainnet,
contract_class_mapping_dumper: Arc::new(Mutex::new(None)),
}
}
Expand Down Expand Up @@ -236,20 +238,26 @@ impl StateReader for TestStateReader {
}

impl TestStateReader {
pub fn new(config: &RpcStateReaderConfig, block_number: BlockNumber, dump_mode: bool) -> Self {
pub fn new(
config: &RpcStateReaderConfig,
chain_id: ChainId,
block_number: BlockNumber,
dump_mode: bool,
) -> Self {
let contract_class_mapping_dumper = Arc::new(Mutex::new(match dump_mode {
true => Some(HashMap::new()),
false => None,
}));
Self {
rpc_state_reader: RpcStateReader::from_number(config, block_number),
contract_class_mapping_dumper,
retry_config: RetryConfig::default(),
chain_id,
contract_class_mapping_dumper,
}
}

pub fn new_for_testing(block_number: BlockNumber) -> Self {
TestStateReader::new(&get_rpc_state_reader_config(), block_number, false)
TestStateReader::new(&get_rpc_state_reader_config(), ChainId::Mainnet, block_number, false)
}

/// Get the block info of the current block.
Expand Down Expand Up @@ -334,7 +342,7 @@ impl TestStateReader {
pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
Ok(BlockContext::new(
self.get_block_info()?,
get_chain_info(&ChainId::Mainnet),
get_chain_info(&self.chain_id),
self.get_versioned_constants()?.clone(),
BouncerConfig::max(),
))
Expand Down Expand Up @@ -468,17 +476,20 @@ impl ConsecutiveTestStateReaders {
pub fn new(
last_constructed_block_number: BlockNumber,
config: Option<RpcStateReaderConfig>,
chain_id: ChainId,
dump_mode: bool,
) -> Self {
let config = config.unwrap_or(get_rpc_state_reader_config());
Self {
last_block_state_reader: TestStateReader::new(
&config,
chain_id.clone(),
last_constructed_block_number,
dump_mode,
),
next_block_state_reader: TestStateReader::new(
&config,
chain_id,
last_constructed_block_number.next().expect("Overflow in block number"),
dump_mode,
),
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier_reexecution/src/state_reader/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ pub fn write_block_reexecution_data_to_file(
block_number: BlockNumber,
full_file_path: String,
node_url: String,
chain_id: ChainId,
) {
let config =
RpcStateReaderConfig { url: node_url, json_rpc_version: JSON_RPC_VERSION.to_string() };

let consecutive_state_readers = ConsecutiveTestStateReaders::new(
block_number.prev().expect("Should not run with block 0"),
Some(config),
chain_id,
true,
);

Expand Down
Loading