Skip to content

Commit

Permalink
chore: renamed associated type T to Pcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eagle941 committed Sep 17, 2024
1 parent 43c3396 commit c2ad1f0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/blockifier/src/concurrency/fee_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod test;
pub(crate) const STORAGE_READ_SEQUENCER_BALANCE_INDICES: (usize, usize) = (2, 3);

// Completes the fee transfer flow if needed (if the transfer was made in concurrent mode).
pub fn complete_fee_transfer_flow<V: VisitedPcs, U: UpdatableState<T = V>>(
pub fn complete_fee_transfer_flow<V: VisitedPcs, U: UpdatableState<Pcs = V>>(
tx_context: &TransactionContext,
tx_execution_info: &mut TransactionExecutionInfo,
state: &mut U,
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn fill_sequencer_balance_reads(
storage_read_values[high_index] = high;
}

pub fn add_fee_to_sequencer_balance<V: VisitedPcs, U: UpdatableState<T = V>>(
pub fn add_fee_to_sequencer_balance<V: VisitedPcs, U: UpdatableState<Pcs = V>>(
fee_token_address: ContractAddress,
state: &mut U,
actual_fee: Fee,
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/concurrency/versioned_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<S: StateReader> VersionedState<S> {
}
}

impl<V: VisitedPcs, U: UpdatableState<T = V>> VersionedState<U> {
impl<V: VisitedPcs, U: UpdatableState<Pcs = V>> VersionedState<U> {
pub fn commit_chunk_and_recover_block_state(
mut self,
n_committed_txs: usize,
Expand Down Expand Up @@ -283,7 +283,7 @@ impl<S: StateReader, V: VisitedPcs> VersionedStateProxy<S, V> {

// TODO(Noa, 15/5/24): Consider using visited_pcs.
impl<V: VisitedPcs, S: StateReader> UpdatableState for VersionedStateProxy<S, V> {
type T = V;
type Pcs = V;

fn apply_writes(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'a, S: StateReader, V: VisitedPcs> WorkerExecutor<'a, S, V> {
}
}

impl<'a, V: VisitedPcs, U: UpdatableState<T = V>> WorkerExecutor<'a, U, V> {
impl<'a, V: VisitedPcs, U: UpdatableState<Pcs = V>> WorkerExecutor<'a, U, V> {
pub fn commit_chunk_and_recover_block_state(self, n_committed_txs: usize, visited_pcs: V) -> U {
self.state
.into_inner_state()
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<S: StateReader, V: VisitedPcs> CachedState<S, V> {
}

impl<S: StateReader, V: VisitedPcs> UpdatableState for CachedState<S, V> {
type T = V;
type Pcs = V;

fn apply_writes(
&mut self,
Expand Down Expand Up @@ -535,7 +535,7 @@ impl<'a, S: StateReader, V: VisitedPcs> TransactionalState<'a, S, V> {
}

/// Adds the ability to perform a transactional execution.
impl<'a, V: VisitedPcs, U: UpdatableState<T = V>> TransactionalState<'a, U, V> {
impl<'a, V: VisitedPcs, U: UpdatableState<Pcs = V>> TransactionalState<'a, U, V> {
/// Commits changes in the child (wrapping) state to its parent.
pub fn commit(self) {
let state = self.state.0;
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/state/state_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ pub trait State: StateReader {

/// A class defining the API for updating a state with transactions writes.
pub trait UpdatableState: StateReader {
type T;
type Pcs;

fn apply_writes(
&mut self,
writes: &StateMaps,
class_hash_to_class: &ContractClassMapping,
visited_pcs: &Self::T,
visited_pcs: &Self::Pcs,
);
}
22 changes: 11 additions & 11 deletions crates/blockifier/src/state/visited_pcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ where
Self: Default + Debug,
{
/// This is the type which contains visited program counters.
type T: Clone;
type Pcs: Clone;

fn new() -> Self;

Expand All @@ -23,25 +23,25 @@ where
fn insert(&mut self, class_hash: &ClassHash, pcs: &[usize]);

/// The function `extend` is used to extend an instance of `VisitedPcs` with another one.
fn extend(&mut self, class_hash: &ClassHash, pcs: &Self::T);
fn extend(&mut self, class_hash: &ClassHash, pcs: &Self::Pcs);

/// This function returns an iterator of `VisitedPcs`.
fn iter(&self) -> impl Iterator<Item = (&ClassHash, &Self::T)>;
fn iter(&self) -> impl Iterator<Item = (&ClassHash, &Self::Pcs)>;

/// Get the recorded visited program counters for a specific `class_hash`.
fn entry(&mut self, class_hash: ClassHash) -> Entry<'_, ClassHash, Self::T>;
fn entry(&mut self, class_hash: ClassHash) -> Entry<'_, ClassHash, Self::Pcs>;

/// Marks the given PC values as visited for the given class hash.
fn add_visited_pcs(state: &mut dyn State, class_hash: &ClassHash, pcs: Self::T);
fn add_visited_pcs(state: &mut dyn State, class_hash: &ClassHash, pcs: Self::Pcs);

/// This function returns the program counters in a set.
fn to_set(pcs: Self::T) -> HashSet<usize>;
fn to_set(pcs: Self::Pcs) -> HashSet<usize>;
}

#[derive(Debug, Default, PartialEq, Eq)]
pub struct VisitedPcsSet(HashMap<ClassHash, HashSet<usize>>);
impl VisitedPcs for VisitedPcsSet {
type T = HashSet<usize>;
type Pcs = HashSet<usize>;

fn new() -> Self {
VisitedPcsSet(HashMap::default())
Expand All @@ -51,23 +51,23 @@ impl VisitedPcs for VisitedPcsSet {
self.0.entry(*class_hash).or_default().extend(pcs);
}

fn iter(&self) -> impl Iterator<Item = (&ClassHash, &Self::T)> {
fn iter(&self) -> impl Iterator<Item = (&ClassHash, &Self::Pcs)> {
self.0.iter()
}

fn entry(&mut self, class_hash: ClassHash) -> Entry<'_, ClassHash, HashSet<usize>> {
self.0.entry(class_hash)
}

fn add_visited_pcs(state: &mut dyn State, class_hash: &ClassHash, pcs: Self::T) {
fn add_visited_pcs(state: &mut dyn State, class_hash: &ClassHash, pcs: Self::Pcs) {
state.add_visited_pcs(*class_hash, &Vec::from_iter(pcs));
}

fn extend(&mut self, class_hash: &ClassHash, pcs: &Self::T) {
fn extend(&mut self, class_hash: &ClassHash, pcs: &Self::Pcs) {
self.0.entry(*class_hash).or_default().extend(pcs);
}

fn to_set(pcs: Self::T) -> HashSet<usize> {
fn to_set(pcs: Self::Pcs) -> HashSet<usize> {
pcs
}
}
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ impl AccountTransaction {
}
}

impl<V: VisitedPcs, U: UpdatableState<T = V>> ExecutableTransaction<V, U> for AccountTransaction {
impl<V: VisitedPcs, U: UpdatableState<Pcs = V>> ExecutableTransaction<V, U> for AccountTransaction {
fn execute_raw(
&self,
state: &mut TransactionalState<'_, U, V>,
Expand Down
6 changes: 4 additions & 2 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ impl TransactionInfoCreator for Transaction {
}
}

impl<V: VisitedPcs, U: UpdatableState<T = V>> ExecutableTransaction<V, U> for L1HandlerTransaction {
impl<V: VisitedPcs, U: UpdatableState<Pcs = V>> ExecutableTransaction<V, U>
for L1HandlerTransaction
{
fn execute_raw(
&self,
state: &mut TransactionalState<'_, U, V>,
Expand Down Expand Up @@ -152,7 +154,7 @@ impl<V: VisitedPcs, U: UpdatableState<T = V>> ExecutableTransaction<V, U> for L1
}
}

impl<V: VisitedPcs, U: UpdatableState<T = V>> ExecutableTransaction<V, U> for Transaction {
impl<V: VisitedPcs, U: UpdatableState<Pcs = V>> ExecutableTransaction<V, U> for Transaction {
fn execute_raw(
&self,
state: &mut TransactionalState<'_, U, V>,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct ExecutionFlags {
pub concurrency_mode: bool,
}

pub trait ExecutableTransaction<V: VisitedPcs, U: UpdatableState<T = V>>: Sized {
pub trait ExecutableTransaction<V: VisitedPcs, U: UpdatableState<Pcs = V>>: Sized {
/// Executes the transaction in a transactional manner
/// (if it fails, given state does not modify).
fn execute(
Expand Down

0 comments on commit c2ad1f0

Please sign in to comment.