Skip to content

Commit

Permalink
[block-stm] versioned entry tests and basic generic interface
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Sep 5, 2024
1 parent 84f69bf commit 6ae08f6
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 118 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions aptos-move/block-executor/src/captured_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use aptos_mvhashmap::{
};
use aptos_types::{
delayed_fields::PanicError, state_store::state_value::StateValueMetadata,
transaction::BlockExecutableTransaction as Transaction, write_set::TransactionWrite,
transaction::BlockExecutableTransaction as Transaction, vm::modules::ModuleStorageEntry,
write_set::TransactionWrite,
};
use aptos_vm_types::resolver::ResourceGroupSize;
use derivative::Derivative;
Expand Down Expand Up @@ -302,7 +303,7 @@ pub(crate) struct CapturedReads<T: Transaction> {
/// Captured module reads if V1 loader is used.
pub(crate) module_reads: Vec<T::Key>,
/// Captured module reads if V2 loader is used.
module_storage_reads: HashMap<T::Key, ModuleStorageRead>,
module_storage_reads: HashMap<T::Key, ModuleStorageRead<ModuleStorageEntry>>,

delayed_field_reads: HashMap<T::Identifier, DelayedFieldRead>,

Expand Down Expand Up @@ -481,14 +482,17 @@ impl<T: Transaction> CapturedReads<T> {
pub(crate) fn get_captured_module_storage_read(
&self,
key: &T::Key,
) -> Option<&ModuleStorageRead> {
) -> Option<&ModuleStorageRead<ModuleStorageEntry>> {
self.module_storage_reads.get(key)
}

Check warning on line 487 in aptos-move/block-executor/src/captured_reads.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/block-executor/src/captured_reads.rs#L482-L487

Added lines #L482 - L487 were not covered by tests

/// Captures the read of a module storage entry.
pub(crate) fn capture_module_storage_read(&mut self, key: T::Key, read: ModuleStorageRead) {
let _prev = self.module_storage_reads.insert(key, read);
// assert!(prev.is_none() || prev.is_some_and(|e| e.));
pub(crate) fn capture_module_storage_read(
&mut self,
key: T::Key,
read: ModuleStorageRead<ModuleStorageEntry>,
) {
self.module_storage_reads.insert(key, read);
}

Check warning on line 496 in aptos-move/block-executor/src/captured_reads.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/block-executor/src/captured_reads.rs#L490-L496

Added lines #L490 - L496 were not covered by tests

pub(crate) fn capture_delayed_field_read(
Expand Down Expand Up @@ -605,7 +609,7 @@ impl<T: Transaction> CapturedReads<T> {
/// also have the same version X.
pub(crate) fn validate_module_reads(
&self,
module_storage: &VersionedModuleStorage<T::Key>,
module_storage: &VersionedModuleStorage<T::Key, ModuleStorageEntry>,
idx_to_validate: TxnIndex,
) -> bool {
if self.speculative_failure {
Expand Down
11 changes: 7 additions & 4 deletions aptos-move/block-executor/src/modules_and_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aptos_types::{
executable::{Executable, ModulePath},
state_store::{state_key::StateKey, state_value::StateValueMetadata, TStateView},
transaction::BlockExecutableTransaction as Transaction,
vm::modules::ModuleStorageEntry,
vm::modules::{ModuleStorageEntry, ModuleStorageEntryInterface},
};
use aptos_vm_types::module_and_script_storage::{
code_storage::AptosCodeStorage, module_storage::AptosModuleStorage,
Expand Down Expand Up @@ -162,7 +162,10 @@ impl<'a, T: Transaction, S: TStateView<Key = T::Key>, X: Executable> LatestView<

/// Returns the module storage entry built from the current view. If it is not in
/// multi-version or non-sync data structures, fetches it from the base view.
fn read_module_storage_by_key(&self, key: &T::Key) -> VMResult<ModuleStorageRead> {
fn read_module_storage_by_key(
&self,
key: &T::Key,
) -> VMResult<ModuleStorageRead<ModuleStorageEntry>> {
match &self.latest_view {
ViewState::Sync(state) => {

Check warning on line 170 in aptos-move/block-executor/src/modules_and_scripts.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/block-executor/src/modules_and_scripts.rs#L165-L170

Added lines #L165 - L170 were not covered by tests
// If the module read has been previously cached, return early.
Expand Down Expand Up @@ -211,7 +214,7 @@ impl<'a, T: Transaction, S: TStateView<Key = T::Key>, X: Executable> LatestView<
&self,
address: &AccountAddress,
module_name: &IdentStr,
) -> VMResult<ModuleStorageRead> {
) -> VMResult<ModuleStorageRead<ModuleStorageEntry>> {
let key = T::Key::from_address_and_module_name(address, module_name);
self.read_module_storage_by_key(&key)
}

Check warning on line 220 in aptos-move/block-executor/src/modules_and_scripts.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/block-executor/src/modules_and_scripts.rs#L213-L220

Added lines #L213 - L220 were not covered by tests
Expand Down Expand Up @@ -251,7 +254,7 @@ impl<'a, T: Transaction, S: TStateView<Key = T::Key>, X: Executable> LatestView<
// 2. Entry exists at this index.

// Otherwise, run the local verification first.
let size = entry.bytes().len();
let size = entry.size_in_bytes();
let cm = entry.as_compiled_module();
let partially_verified_module = self
.runtime_environment
Expand Down
1 change: 1 addition & 0 deletions aptos-move/mvhashmap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde = { workspace = true }

[dev-dependencies]
aptos-aggregator = { workspace = true, features = ["testing"] }
move-vm-runtime = { workspace = true }
proptest = { workspace = true }
proptest-derive = { workspace = true }
rayon = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions aptos-move/mvhashmap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
};
use aptos_types::{
executable::{Executable, ModulePath},
vm::modules::ModuleStorageEntry,
write_set::TransactionWrite,
};
use serde::Serialize;
Expand Down Expand Up @@ -39,7 +40,7 @@ pub struct MVHashMap<K, T, V: TransactionWrite, X: Executable, I: Clone> {
group_data: VersionedGroupData<K, T, V>,
delayed_fields: VersionedDelayedFields<I>,
modules: VersionedModules<K, V, X>,
module_storage: VersionedModuleStorage<K>,
module_storage: VersionedModuleStorage<K, ModuleStorageEntry>,
}

impl<
Expand Down Expand Up @@ -94,7 +95,7 @@ impl<
&self.modules
}

pub fn module_storage(&self) -> &VersionedModuleStorage<K> {
pub fn module_storage(&self) -> &VersionedModuleStorage<K, ModuleStorageEntry> {
&self.module_storage
}
}
Expand Down
Loading

0 comments on commit 6ae08f6

Please sign in to comment.