Skip to content

Commit

Permalink
Changed update_visited_pcs_cache to match previous format
Browse files Browse the repository at this point in the history
  • Loading branch information
Eagle941 committed Aug 12, 2024
1 parent a8a651a commit f8f105c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
6 changes: 3 additions & 3 deletions crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::bouncer::{Bouncer, BouncerWeights};
#[cfg(feature = "concurrency")]
use crate::concurrency::worker_logic::WorkerExecutor;
use crate::context::BlockContext;
use crate::state::cached_state::{
CachedState, CommitmentStateDiff, TransactionalState, VisitedPcs,
};
#[cfg(feature = "concurrency")]
use crate::state::cached_state::VisitedPcs;
use crate::state::cached_state::{CachedState, CommitmentStateDiff, TransactionalState};
use crate::state::errors::StateError;
use crate::state::state_api::StateReader;
use crate::transaction::errors::TransactionExecutionError;
Expand Down
7 changes: 1 addition & 6 deletions crates/blockifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
// length to pointer type ([not necessarily true](https://github.com/rust-lang/rust/issues/65473),
// but it is a reasonable assumption for now), this attribute protects against potential overflow
// when converting usize to u128.
#![cfg(any(
target_pointer_width = "16",
target_pointer_width = "32",
target_pointer_width = "64",
target_pointer_width = "128"
))]
#![cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))]

#[cfg(feature = "jemalloc")]
// Override default allocator.
Expand Down
29 changes: 27 additions & 2 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ pub struct CachedState<S: StateReader> {
// Using interior mutability to update caches during `State`'s immutable getters.
pub(crate) cache: RefCell<StateCache>,
pub(crate) class_hash_to_class: RefCell<ContractClassMapping>,
/// A map from class hash to the set of PC values that were visited in the class.
// A map from class hash the PC values that were visited in the class.
//
// If the feature `vector_of_visited_program_counters` is selected, `visited_pcs` contains the
// full vector of visited program counters for each class hash call. Otherwise, it contains
// the just the set of visited program counters.
pub visited_pcs: VisitedPcs,
}

Expand All @@ -71,6 +75,7 @@ impl<S: StateReader> CachedState<S> {
Ok(self.to_state_diff()?.into())
}

/// Returns the set of visited program counters given a `class_hash`.
pub fn get_set_visited_pcs(&self, class_hash: &ClassHash) -> HashSet<usize> {
#[cfg(not(feature = "vector_of_visited_program_counters"))]
fn from_set(class_hash: &ClassHash, visited_pcs: &VisitedPcs) -> HashSet<usize> {
Expand Down Expand Up @@ -105,8 +110,28 @@ impl<S: StateReader> CachedState<S> {
}

pub fn update_visited_pcs_cache(&mut self, visited_pcs: &VisitedPcs) {
#[cfg(not(feature = "vector_of_visited_program_counters"))]
fn from_set<S: StateReader>(
cached_state: &mut CachedState<S>,
class_hash: &ClassHash,
visited_pcs: &Pcs,
) {
cached_state.add_visited_pcs(*class_hash, visited_pcs);
}

#[cfg(feature = "vector_of_visited_program_counters")]
fn from_set<S: StateReader>(
cached_state: &mut CachedState<S>,
class_hash: &ClassHash,
visited_pcs: &Vec<Vec<usize>>,
) {
for pcs in visited_pcs {
cached_state.add_visited_pcs(*class_hash, pcs);
}
}

for (class_hash, class_visited_pcs) in visited_pcs {
self.visited_pcs.entry(*class_hash).or_default().extend(class_visited_pcs.clone());
from_set(self, class_hash, class_visited_pcs);
}
}

Expand Down
7 changes: 1 addition & 6 deletions crates/native_blockifier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// The blockifier crate supports only these specific architectures.
#![cfg(any(
target_pointer_width = "16",
target_pointer_width = "32",
target_pointer_width = "64",
target_pointer_width = "128"
))]
#![cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))]

pub mod errors;
pub mod py_block_executor;
Expand Down

0 comments on commit f8f105c

Please sign in to comment.