Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
refactor(execution, native_blockifier): make TransactionExecutor.fina…
Browse files Browse the repository at this point in the history
…lize() work without Py objects
  • Loading branch information
barak-b-starkware committed Feb 5, 2024
1 parent 6b9cadc commit 1ba0733
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 8 additions & 1 deletion crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ impl PyBlockExecutor {
/// visited PC values.
pub fn finalize(&mut self, is_pending_block: bool) -> (PyStateDiff, Vec<(PyFelt, Vec<usize>)>) {
log::debug!("Finalizing execution...");
let finalized_state = self.tx_executor().finalize(is_pending_block);
let (commitment_state_diff, visited_pcs) = self.tx_executor().finalize(is_pending_block);
let visited_pcs = visited_pcs
.into_iter()
.map(|(class_hash, class_visited_pcs_vec)| {
(PyFelt::from(class_hash), class_visited_pcs_vec)
})
.collect();
let finalized_state = (PyStateDiff::from(commitment_state_diff), visited_pcs);
log::debug!("Finalized execution.");

finalized_state
Expand Down
14 changes: 9 additions & 5 deletions crates/native_blockifier/src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use blockifier::execution::call_info::{CallInfo, MessageL1CostInfo};
use blockifier::execution::entry_point::ExecutionResources;
use blockifier::fee::actual_cost::ActualCost;
use blockifier::state::cached_state::{
CachedState, GlobalContractCache, StagedTransactionalState, StorageEntry, TransactionalState,
CachedState, CommitmentStateDiff, GlobalContractCache, StagedTransactionalState, StorageEntry,
TransactionalState,
};
use blockifier::state::state_api::{State, StateReader};
use blockifier::transaction::account_transaction::AccountTransaction;
Expand All @@ -23,7 +24,7 @@ use starknet_api::core::ClassHash;

use crate::errors::{NativeBlockifierError, NativeBlockifierResult};
use crate::py_block_executor::{into_block_context, PyGeneralConfig};
use crate::py_state_diff::{PyBlockInfo, PyStateDiff};
use crate::py_state_diff::PyBlockInfo;
use crate::py_transaction_execution_info::PyBouncerInfo;
use crate::py_utils::PyFelt;

Expand Down Expand Up @@ -176,7 +177,10 @@ impl<S: StateReader> TransactionExecutor<S> {

/// Returns the state diff and a list of contract class hash with the corresponding list of
/// visited PC values.
pub fn finalize(&mut self, is_pending_block: bool) -> (PyStateDiff, Vec<(PyFelt, Vec<usize>)>) {
pub fn finalize(
&mut self,
is_pending_block: bool,
) -> (CommitmentStateDiff, Vec<(ClassHash, Vec<usize>)>) {
// Do not cache classes that were declared during a pending block.
// They will be redeclared, and should not be cached since the content of this block is
// transient.
Expand All @@ -192,11 +196,11 @@ impl<S: StateReader> TransactionExecutor<S> {
.map(|(class_hash, class_visited_pcs)| {
let mut class_visited_pcs_vec: Vec<_> = class_visited_pcs.iter().cloned().collect();
class_visited_pcs_vec.sort();
(PyFelt::from(*class_hash), class_visited_pcs_vec)
(*class_hash, class_visited_pcs_vec)
})
.collect();

(PyStateDiff::from(self.state.to_state_diff()), visited_pcs)
(self.state.to_state_diff(), visited_pcs)
}

// Block pre-processing; see `block::pre_process_block` documentation.
Expand Down

0 comments on commit 1ba0733

Please sign in to comment.