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 84e5e13 commit 6bbb895
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 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 @@ -130,7 +130,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
13 changes: 7 additions & 6 deletions crates/native_blockifier/src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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, StagedTransactionalState, StorageEntry, TransactionalState,
CachedState, CommitmentStateDiff, StagedTransactionalState, StorageEntry, TransactionalState,
};
use blockifier::state::state_api::{State, StateReader};
use blockifier::transaction::account_transaction::AccountTransaction;
Expand All @@ -19,9 +19,7 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources as VmExecutionResour
use starknet_api::core::ClassHash;

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

pub(crate) type RawTransactionExecutionInfo = Vec<u8>;

Expand Down Expand Up @@ -168,7 +166,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 @@ -184,11 +185,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)
}

pub fn commit(&mut self) {
Expand Down

0 comments on commit 6bbb895

Please sign in to comment.