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

Commit

Permalink
feat(concurrency): add consumers to the versioned state (#1949)
Browse files Browse the repository at this point in the history
  • Loading branch information
barak-b-starkware authored Jun 6, 2024
1 parent 9fe3969 commit 2327bdb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/blockifier/src/concurrency/versioned_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const READ_ERR: &str = "Error: read value missing in the versioned storage";
/// Reader functionality is injected through initial state.
#[derive(Debug)]
pub struct VersionedState<S: StateReader> {
// TODO(barak, 01/08/2024): Change initial_state to state.
initial_state: S,
storage: VersionedStorage<(ContractAddress, StorageKey), StarkFelt>,
nonces: VersionedStorage<ContractAddress, Nonce>,
Expand Down Expand Up @@ -197,6 +198,11 @@ impl<S: StateReader> VersionedState<S> {
self.compiled_contract_classes.delete_write(key, tx_index);
}
}

#[allow(dead_code)]
fn into_initial_state(self) -> S {
self.initial_state
}
}

pub struct ThreadSafeVersionedState<S: StateReader>(Arc<Mutex<VersionedState<S>>>);
Expand All @@ -210,6 +216,19 @@ impl<S: StateReader> ThreadSafeVersionedState<S> {
pub fn pin_version(&self, tx_index: TxIndex) -> VersionedStateProxy<S> {
VersionedStateProxy { tx_index, state: self.0.clone() }
}

#[allow(dead_code)]
fn into_inner_state(self) -> VersionedState<S> {
Arc::try_unwrap(self.0)
.unwrap_or_else(|_| {
panic!(
"To consume the versioned state, you must have only one strong reference to \
self. Consider dropping objects that hold a reference to it."
)
})
.into_inner()
.expect("No other mutex should hold the versioned state while calling this method.")
}
}

impl<S: StateReader> Clone for ThreadSafeVersionedState<S> {
Expand Down

0 comments on commit 2327bdb

Please sign in to comment.