Skip to content

Commit

Permalink
refactor(blockifier_reexecution): inject chain ID to chain info creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Nov 12, 2024
1 parent 248a016 commit 716bed2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use blockifier::versioned_constants::VersionedConstants;
use serde::{Deserialize, Serialize};
use serde_json::{json, to_value};
use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockNumber, StarknetVersion};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_api::transaction::{Transaction, TransactionHash};
use starknet_core::types::ContractClass as StarknetContractClass;
Expand Down Expand Up @@ -131,7 +131,7 @@ impl From<SerializableOfflineReexecutionData> for OfflineReexecutionData {
offline_state_reader_prev_block,
block_context_next_block: BlockContext::new(
block_info_next_block,
get_chain_info(),
get_chain_info(&ChainId::Mainnet),
VersionedConstants::get(&starknet_version).unwrap().clone(),
BouncerConfig::max(),
),
Expand Down Expand Up @@ -327,7 +327,7 @@ impl TestStateReader {
pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
Ok(BlockContext::new(
self.get_block_info()?,
get_chain_info(),
get_chain_info(&ChainId::Mainnet),
self.get_versioned_constants()?.clone(),
BouncerConfig::max(),
))
Expand Down
16 changes: 10 additions & 6 deletions crates/blockifier_reexecution/src/state_reader/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ pub const RPC_NODE_URL: &str = "https://free-rpc.nethermind.io/mainnet-juno/";
pub const JSON_RPC_VERSION: &str = "2.0";

/// Returns the fee token addresses of mainnet.
pub fn get_fee_token_addresses() -> FeeTokenAddresses {
FeeTokenAddresses {
strk_fee_token_address: *STRK_FEE_CONTRACT_ADDRESS,
eth_fee_token_address: *ETH_FEE_CONTRACT_ADDRESS,
pub fn get_fee_token_addresses(chain_id: &ChainId) -> FeeTokenAddresses {
match chain_id {
// Mainnet, testnet and integration systems have the same fee token addresses.
ChainId::Mainnet | ChainId::Sepolia | ChainId::IntegrationSepolia => FeeTokenAddresses {
strk_fee_token_address: *STRK_FEE_CONTRACT_ADDRESS,
eth_fee_token_address: *ETH_FEE_CONTRACT_ADDRESS,
},
unknown_chain => unimplemented!("Unknown chain ID {unknown_chain}."),
}
}

Expand All @@ -41,8 +45,8 @@ pub fn get_rpc_state_reader_config() -> RpcStateReaderConfig {
}

/// Returns the chain info of mainnet.
pub fn get_chain_info() -> ChainInfo {
ChainInfo { chain_id: ChainId::Mainnet, fee_token_addresses: get_fee_token_addresses() }
pub fn get_chain_info(chain_id: &ChainId) -> ChainInfo {
ChainInfo { chain_id: chain_id.clone(), fee_token_addresses: get_fee_token_addresses(chain_id) }
}

// TODO(Aner): import the following functions instead, to reduce code duplication.
Expand Down

0 comments on commit 716bed2

Please sign in to comment.