Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Nov 29, 2024
1 parent 049873c commit 54617b6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
72 changes: 39 additions & 33 deletions rpc-state-reader/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ use crate::{
reader::{RpcChain, RpcStateReader},
};
use blockifier::{
bouncer::BouncerConfig, context::{BlockContext, ChainInfo, FeeTokenAddresses}, state::{cached_state::CachedState, state_api::StateReader}, test_utils::MAX_FEE, transaction::{
objects::{TransactionExecutionInfo, TransactionExecutionResult}, transaction_execution::Transaction as BlockiTransaction, transactions::ExecutableTransaction
}, versioned_constants::{VersionedConstants, VersionedConstantsOverrides}
bouncer::BouncerConfig,
context::{BlockContext, ChainInfo, FeeTokenAddresses},
state::{cached_state::CachedState, state_api::StateReader},
test_utils::MAX_FEE,
transaction::{
objects::{TransactionExecutionInfo, TransactionExecutionResult},
transaction_execution::Transaction as BlockiTransaction,
transactions::ExecutableTransaction,
},
versioned_constants::{VersionedConstants, VersionedConstantsOverrides},
};
use blockifier_reexecution::state_reader::compile::{
legacy_to_contract_class_v0, sierra_to_contact_class_v1,
Expand All @@ -14,7 +21,7 @@ use starknet::core::types::ContractClass as SNContractClass;
use starknet_api::{
block::{BlockInfo, BlockNumber},
contract_class::ClassInfo,
core:: ContractAddress,
core::ContractAddress,
felt,
hash::StarkHash,
patricia_key,
Expand Down Expand Up @@ -75,28 +82,23 @@ pub fn execute_tx(

// Map starknet_api transaction to blockifier's
let blockifier_tx = match tx {
SNTransaction::Invoke(_)
| SNTransaction::DeployAccount(_) =>
BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap(),
SNTransaction::Invoke(_) | SNTransaction::DeployAccount(_) => {
BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap()
}
SNTransaction::Declare(ref declare_tx) => {
let block_number = block_context.block_info().block_number;
let network = parse_to_rpc_chain(&block_context.chain_info().chain_id.to_string());
// we need to retrieve the next block in order to get the contract_class
let next_reader = RpcStateReader::new(network, block_number.next().unwrap());
let contract_class = next_reader.get_contract_class(&declare_tx.class_hash()).unwrap();
let contract_class = next_reader
.get_contract_class(&declare_tx.class_hash())
.unwrap();
let class_info = calculate_class_info_for_testing(contract_class);

BlockiTransaction::from_api(tx, tx_hash, Some(class_info), None, None, false).unwrap()
}
SNTransaction::L1Handler(_) => {
BlockiTransaction::from_api(
tx,
tx_hash,
None,
Some(MAX_FEE),
None,
false,
).unwrap()
BlockiTransaction::from_api(tx, tx_hash, None, Some(MAX_FEE), None, false).unwrap()
}
_ => todo!(),
};
Expand Down Expand Up @@ -172,28 +174,23 @@ pub fn execute_tx_configurable_with_state(

// Get transaction before giving ownership of the reader
let blockifier_tx = match tx {
SNTransaction::Invoke(_)
| SNTransaction::DeployAccount(_) =>
BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap(),
SNTransaction::Invoke(_) | SNTransaction::DeployAccount(_) => {
BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap()
}
SNTransaction::Declare(ref declare_tx) => {
let block_number = block_context.block_info().block_number;
let network = parse_to_rpc_chain(&chain_id.to_string());
// we need to retrieve the next block in order to get the contract_class
let next_reader = RpcStateReader::new(network, block_number.next().unwrap());
let contract_class = next_reader.get_contract_class(&declare_tx.class_hash()).unwrap();
let contract_class = next_reader
.get_contract_class(&declare_tx.class_hash())
.unwrap();
let class_info = calculate_class_info_for_testing(contract_class);

BlockiTransaction::from_api(tx, tx_hash, Some(class_info), None, None, false).unwrap()
}
SNTransaction::L1Handler(_) => {
BlockiTransaction::from_api(
tx,
tx_hash,
None,
Some(MAX_FEE),
None,
false,
).unwrap()
BlockiTransaction::from_api(tx, tx_hash, None, Some(MAX_FEE), None, false).unwrap()
}
_ => unimplemented!(),
};
Expand Down Expand Up @@ -236,18 +233,27 @@ pub fn execute_tx_with_blockifier(
transaction_hash: TransactionHash,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let account_transaction: BlockiTransaction = match transaction {
SNTransaction::Invoke(_)
| SNTransaction::DeployAccount(_) =>
BlockiTransaction::from_api(transaction, transaction_hash, None, None, None, false)?,
SNTransaction::Invoke(_) | SNTransaction::DeployAccount(_) => {
BlockiTransaction::from_api(transaction, transaction_hash, None, None, None, false)?
}
SNTransaction::Declare(ref declare_tx) => {
let block_number = context.block_info().block_number;
let network = parse_to_rpc_chain(&context.chain_info().chain_id.to_string());
// we need to retrieve the next block in order to get the contract_class
let next_reader = RpcStateReader::new(network, block_number.next().unwrap());
let contract_class = next_reader.get_contract_class(&declare_tx.class_hash()).unwrap();
let contract_class = next_reader
.get_contract_class(&declare_tx.class_hash())
.unwrap();
let class_info = calculate_class_info_for_testing(contract_class);

BlockiTransaction::from_api(transaction, transaction_hash, Some(class_info), None, None, false)?
BlockiTransaction::from_api(
transaction,
transaction_hash,
Some(class_info),
None,
None,
false,
)?
}
SNTransaction::L1Handler(_) => {
// As L1Hanlder is not an account transaction we execute it here and return the result
Expand Down
5 changes: 0 additions & 5 deletions rpc-state-reader/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,11 @@ impl StateReader for RpcStateReader {
}

fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
dbg!("ENTERED_GET_COMPILED_CLASS");
Ok(match self.get_contract_class(&class_hash)? {
SNContractClass::Legacy(compressed_legacy_cc) => {
dbg!("ENTERED_LEGACY");
compile_legacy_cc(compressed_legacy_cc)
}
SNContractClass::Sierra(flattened_sierra_cc) => {
dbg!("ENTERED_SIERRA");
compile_sierra_cc(flattened_sierra_cc, class_hash)
}
})
Expand Down Expand Up @@ -353,9 +350,7 @@ fn compile_sierra_cc(

RunnableCompiledClass::V1(casm_cc.try_into().unwrap())
} else {
dbg!("COMPILED_EXECUTOR");
let executor = utils::get_native_executor(&sierra_cc, class_hash);
dbg!("COMPILED_EXECUTOR_PASSED");
let casm = CasmContractClass::from_contract_class(sierra_cc, false, usize::MAX).unwrap();
let casm = CompiledClassV1::try_from(casm).unwrap();

Expand Down
6 changes: 5 additions & 1 deletion rpc-state-reader/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ pub fn decode_reader(bytes: Vec<u8>) -> io::Result<String> {
pub fn get_native_executor(contract: &ContractClass, class_hash: ClassHash) -> AotContractExecutor {
let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| RwLock::new(HashMap::new()));

let executor = cache_lock.read().unwrap().get(&class_hash).map(Clone::clone);
let executor = cache_lock
.read()
.unwrap()
.get(&class_hash)
.map(Clone::clone);

match executor {
Some(executor) => executor,
Expand Down

0 comments on commit 54617b6

Please sign in to comment.