From 539e5d4912084423e0e42e166b888348797dac2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 1 Jul 2024 12:14:17 -0300 Subject: [PATCH] Fix clippy --- replay/src/main.rs | 14 ++-- .../src/blockifier_state_reader.rs | 74 ++++++++----------- rpc-state-reader/src/rpc_state.rs | 2 +- 3 files changed, 38 insertions(+), 52 deletions(-) diff --git a/replay/src/main.rs b/replay/src/main.rs index 2bf83c4..7722471 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -1,19 +1,15 @@ -use blockifier::{ - execution, state::cached_state::CachedState, transaction::objects::TransactionExecutionInfo, -}; +use blockifier::state::cached_state::CachedState; use clap::{Parser, Subcommand}; use rpc_state_reader::{ blockifier_state_reader::RpcStateReader, - rpc_state::{self, BlockValue, RpcChain, RpcState, RpcTransactionReceipt}, + rpc_state::{BlockValue, RpcChain, RpcState}, rpc_state_errors::RpcStateError, }; use rpc_state_reader::blockifier_state_reader::execute_tx_configurable; #[cfg(feature = "benchmark")] use rpc_state_reader::{ - execute_tx_configurable_with_state, - rpc_state::{RpcBlockInfo, RpcState}, - RpcStateReader, + execute_tx_configurable_with_state, rpc_state::RpcBlockInfo, RpcStateReader, }; use starknet_api::block::BlockNumber; #[cfg(feature = "benchmark")] @@ -36,7 +32,7 @@ use std::ops::Div; use std::str::FromStr; #[cfg(feature = "benchmark")] use std::{collections::HashMap, sync::Arc, time::Instant}; -use tracing::{debug, error, field, info, info_span, span}; +use tracing::{debug, error, info, info_span}; use tracing_subscriber::filter::Directive; use tracing_subscriber::{util::SubscriberInitExt, EnvFilter}; @@ -263,7 +259,7 @@ fn parse_network(network: &str) -> RpcChain { fn build_cached_state(network: &str, block_number: u64) -> CachedState { let previous_block_number = BlockNumber(block_number); - let rpc_chain = parse_network(&network); + let rpc_chain = parse_network(network); let rpc_reader = RpcStateReader( RpcState::new_rpc(rpc_chain, previous_block_number.into()) .expect("failed to create state reader"), diff --git a/rpc-state-reader/src/blockifier_state_reader.rs b/rpc-state-reader/src/blockifier_state_reader.rs index eb481d9..ff0cffc 100644 --- a/rpc-state-reader/src/blockifier_state_reader.rs +++ b/rpc-state-reader/src/blockifier_state_reader.rs @@ -1,14 +1,10 @@ use blockifier::{ blockifier::block::BlockInfo, context::{BlockContext, ChainInfo, FeeTokenAddresses}, - execution::contract_class::{ - ClassInfo, ContractClass, ContractClassV0, ContractClassV0Inner, SierraContractClassV1, - SierraContractClassV1Inner, - }, + execution::contract_class::{ClassInfo, ContractClass, ContractClassV0, ContractClassV0Inner}, state::{ cached_state::CachedState, errors::StateError, - global_cache::GlobalContractCache, state_api::{StateReader, StateResult}, }, transaction::{ @@ -21,22 +17,17 @@ use blockifier::{ }, versioned_constants::VersionedConstants, }; -use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use cairo_vm::types::program::Program; use starknet::core::types::ContractClass as SNContractClass; use starknet_api::{ block::BlockNumber, - contract_address, - core::{ - calculate_contract_address, ClassHash, CompiledClassHash, ContractAddress, Nonce, - PatriciaKey, - }, - hash::{StarkFelt, StarkHash}, - patricia_key, stark_felt, + core::{calculate_contract_address, ClassHash, CompiledClassHash, ContractAddress, Nonce}, + hash::StarkFelt, + stark_felt, state::StorageKey, transaction::{Transaction as SNTransaction, TransactionHash}, }; -use std::{collections::HashMap, sync::Arc}; +use std::sync::Arc; use crate::{ rpc_state::{RpcBlockInfo, RpcChain, RpcState, RpcTransactionReceipt, TransactionTrace}, @@ -152,25 +143,24 @@ pub fn execute_tx( // Create state from RPC reader let mut state = CachedState::new(rpc_reader); - let fee_token_address = - contract_address!("049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"); - - const N_STEPS_FEE_WEIGHT: f64 = 0.01; - let vm_resource_fee_cost = Arc::new(HashMap::from([ - ("n_steps".to_string(), N_STEPS_FEE_WEIGHT), - ("output_builtin".to_string(), 0.0), - ("pedersen_builtin".to_string(), N_STEPS_FEE_WEIGHT * 32.0), - ("range_check_builtin".to_string(), N_STEPS_FEE_WEIGHT * 16.0), - ("ecdsa_builtin".to_string(), N_STEPS_FEE_WEIGHT * 2048.0), - ("bitwise_builtin".to_string(), N_STEPS_FEE_WEIGHT * 64.0), - ("ec_op_builtin".to_string(), N_STEPS_FEE_WEIGHT * 1024.0), - ("poseidon_builtin".to_string(), N_STEPS_FEE_WEIGHT * 32.0), - ( - "segment_arena_builtin".to_string(), - N_STEPS_FEE_WEIGHT * 10.0, - ), - ("keccak_builtin".to_string(), N_STEPS_FEE_WEIGHT * 2048.0), // 2**11 - ])); + // let fee_token_address = + // contract_address!("049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"); + // const N_STEPS_FEE_WEIGHT: f64 = 0.01; + // let vm_resource_fee_cost = Arc::new(HashMap::from([ + // ("n_steps".to_string(), N_STEPS_FEE_WEIGHT), + // ("output_builtin".to_string(), 0.0), + // ("pedersen_builtin".to_string(), N_STEPS_FEE_WEIGHT * 32.0), + // ("range_check_builtin".to_string(), N_STEPS_FEE_WEIGHT * 16.0), + // ("ecdsa_builtin".to_string(), N_STEPS_FEE_WEIGHT * 2048.0), + // ("bitwise_builtin".to_string(), N_STEPS_FEE_WEIGHT * 64.0), + // ("ec_op_builtin".to_string(), N_STEPS_FEE_WEIGHT * 1024.0), + // ("poseidon_builtin".to_string(), N_STEPS_FEE_WEIGHT * 32.0), + // ( + // "segment_arena_builtin".to_string(), + // N_STEPS_FEE_WEIGHT * 10.0, + // ), + // ("keccak_builtin".to_string(), N_STEPS_FEE_WEIGHT * 2048.0), // 2**11 + // ])); let block_info = BlockInfo { block_number, @@ -240,7 +230,7 @@ pub fn execute_tx( } SNTransaction::Declare(tx) => { // Fetch the contract_class from the next block (as we don't have it in the previous one) - let mut next_block_state_reader = RpcStateReader( + let next_block_state_reader = RpcStateReader( RpcState::new_rpc(network, (block_number.next()).unwrap().into()).unwrap(), ); let contract_class = next_block_state_reader @@ -293,16 +283,16 @@ pub fn execute_tx_configurable_with_state( tx_hash: &TransactionHash, tx: SNTransaction, block_info: BlockInfo, - skip_validate: bool, - skip_nonce_check: bool, + _skip_validate: bool, + _skip_nonce_check: bool, state: &mut CachedState, ) -> TransactionExecutionResult { - let fee_token_address = FeeTokenAddresses { - strk_fee_token_address: ContractAddress::default(), - eth_fee_token_address: ContractAddress(starknet_api::patricia_key!( - "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" - )), - }; + // let _fee_token_address = FeeTokenAddresses { + // strk_fee_token_address: ContractAddress::default(), + // eth_fee_token_address: ContractAddress(starknet_api::patricia_key!( + // "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" + // )), + // }; // Get values for block context before giving ownership of the reader let chain_id = state.state.0.get_chain_name(); diff --git a/rpc-state-reader/src/rpc_state.rs b/rpc-state-reader/src/rpc_state.rs index c3dfd63..814ca1c 100644 --- a/rpc-state-reader/src/rpc_state.rs +++ b/rpc-state-reader/src/rpc_state.rs @@ -10,7 +10,7 @@ use cairo_vm::vm::runners::{ use core::fmt; use dotenv::dotenv; use serde::{Deserialize, Deserializer}; -use serde_json::{json, Value}; +use serde_json::json; use starknet::core::types::ContractClass as SNContractClass; use starknet_api::{ block::{BlockNumber, BlockTimestamp},