Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Jul 1, 2024
1 parent 3d543fd commit 539e5d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 52 deletions.
14 changes: 5 additions & 9 deletions replay/src/main.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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};

Expand Down Expand Up @@ -263,7 +259,7 @@ fn parse_network(network: &str) -> RpcChain {

fn build_cached_state(network: &str, block_number: u64) -> CachedState<RpcStateReader> {
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"),
Expand Down
74 changes: 32 additions & 42 deletions rpc-state-reader/src/blockifier_state_reader.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<RpcStateReader>,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
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();
Expand Down
2 changes: 1 addition & 1 deletion rpc-state-reader/src/rpc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 539e5d4

Please sign in to comment.