Skip to content

Commit

Permalink
Loader V2 refactoring:
Browse files Browse the repository at this point in the history
  - Unify imports
  - Move environment from storages into ModuleBytesStorages
  - Move unsync code storage implementation tests
  - Remove V1 loader test flows
  • Loading branch information
georgemitenkov committed Nov 14, 2024
1 parent 9d0662e commit 9d7c430
Show file tree
Hide file tree
Showing 62 changed files with 1,053 additions and 1,607 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion aptos-move/aptos-vm-environment/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use aptos_types::{
state_store::StateView,
};
use aptos_vm_types::storage::StorageGasParameters;
use move_vm_runtime::{config::VMConfig, RuntimeEnvironment, WithRuntimeEnvironment};
use move_vm_runtime::{
config::VMConfig,
storage::environment::{RuntimeEnvironment, WithRuntimeEnvironment},
};
use sha3::{Digest, Sha3_256};
use std::sync::Arc;

Expand Down
13 changes: 9 additions & 4 deletions aptos-move/aptos-vm-profiling/src/bins/run_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ use move_core_types::{
};
use move_ir_compiler::Compiler;
use move_vm_runtime::{
module_traversal::*, move_vm::MoveVM, native_extensions::NativeContextExtensions,
native_functions::NativeFunction, AsUnsyncCodeStorage, RuntimeEnvironment,
module_traversal::*,
move_vm::MoveVM,
native_extensions::NativeContextExtensions,
native_functions::NativeFunction,
storage::{
environment::RuntimeEnvironment, implementations::unsync_code_storage::AsUnsyncCodeStorage,
},
};
use move_vm_test_utils::InMemoryStorage;
use move_vm_types::{
Expand Down Expand Up @@ -161,7 +166,7 @@ fn main() -> Result<()> {

let runtime_environment = RuntimeEnvironment::new(natives);
let vm = MoveVM::new_with_runtime_environment(&runtime_environment);
let mut storage = InMemoryStorage::new();
let mut storage = InMemoryStorage::new(runtime_environment);

let test_modules = compile_test_modules();
for module in &test_modules {
Expand All @@ -188,7 +193,7 @@ fn main() -> Result<()> {
let mut sess = vm.new_session_with_extensions(&storage, extensions);

let traversal_storage = TraversalStorage::new();
let code_storage = storage.as_unsync_code_storage(runtime_environment);
let code_storage = storage.as_unsync_code_storage();

let args: Vec<Vec<u8>> = vec![];
match entrypoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::module_and_script_storage::module_storage::AptosModuleStorage;
use move_vm_runtime::CodeStorage;
use move_vm_runtime::storage::code_storage::CodeStorage;

/// Represents code storage used by the Aptos blockchain, capable of caching scripts and modules.
pub trait AptosCodeStorage: AptosModuleStorage + CodeStorage {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use aptos_types::state_store::state_value::StateValueMetadata;
use move_binary_format::errors::PartialVMResult;
use move_core_types::{account_address::AccountAddress, identifier::IdentStr};
use move_vm_runtime::ModuleStorage;
use move_vm_runtime::storage::module_storage::ModuleStorage;

/// Represents module storage used by the Aptos blockchain.
pub trait AptosModuleStorage: ModuleStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ use move_core_types::{
metadata::Metadata,
};
use move_vm_runtime::{
ambassador_impl_CodeStorage, ambassador_impl_ModuleStorage,
ambassador_impl_WithRuntimeEnvironment, AsUnsyncCodeStorage, BorrowedOrOwned, CodeStorage,
Module, ModuleStorage, RuntimeEnvironment, Script, UnsyncCodeStorage, UnsyncModuleStorage,
WithRuntimeEnvironment,
storage::{
code_storage::{ambassador_impl_CodeStorage, CodeStorage},
environment::{
ambassador_impl_WithRuntimeEnvironment, RuntimeEnvironment, WithRuntimeEnvironment,
},
implementations::{
unsync_code_storage::{AsUnsyncCodeStorage, UnsyncCodeStorage},
unsync_module_storage::{BorrowedOrOwned, UnsyncModuleStorage},
},
module_storage::{ambassador_impl_ModuleStorage, ModuleStorage},
},
Module, Script,
};
use move_vm_types::{
code::{ModuleBytesStorage, ModuleCode},
Expand All @@ -31,11 +39,14 @@ use move_vm_types::{
use std::{ops::Deref, sync::Arc};

/// Avoids orphan rule to implement [ModuleBytesStorage] for [StateView].
struct StateViewAdapter<'s, S> {
struct StateViewAdapter<'s, S, E> {
environment: E,
state_view: BorrowedOrOwned<'s, S>,
}

impl<'s, S: StateView> ModuleBytesStorage for StateViewAdapter<'s, S> {
impl<'s, S: StateView, E: WithRuntimeEnvironment> ModuleBytesStorage
for StateViewAdapter<'s, S, E>
{
fn fetch_module_bytes(
&self,
address: &AccountAddress,
Expand All @@ -48,7 +59,15 @@ impl<'s, S: StateView> ModuleBytesStorage for StateViewAdapter<'s, S> {
}
}

impl<'s, S: StateView> Deref for StateViewAdapter<'s, S> {
impl<'s, S: StateView, E: WithRuntimeEnvironment> WithRuntimeEnvironment
for StateViewAdapter<'s, S, E>
{
fn runtime_environment(&self) -> &RuntimeEnvironment {
self.environment.runtime_environment()
}
}

impl<'s, S: StateView, E: WithRuntimeEnvironment> Deref for StateViewAdapter<'s, S, E> {
type Target = S;

fn deref(&self) -> &Self::Target {
Expand All @@ -67,27 +86,29 @@ impl<'s, S: StateView> Deref for StateViewAdapter<'s, S> {
#[delegate(ModuleStorage, where = "S: StateView, E: WithRuntimeEnvironment")]
#[delegate(CodeStorage, where = "S: StateView, E: WithRuntimeEnvironment")]
pub struct AptosCodeStorageAdapter<'s, S, E> {
storage: UnsyncCodeStorage<UnsyncModuleStorage<'s, StateViewAdapter<'s, S>, E>>,
storage: UnsyncCodeStorage<UnsyncModuleStorage<'s, StateViewAdapter<'s, S, E>>>,
}

impl<'s, S: StateView, E: WithRuntimeEnvironment> AptosCodeStorageAdapter<'s, S, E> {
/// Creates new instance of [AptosCodeStorageAdapter] built on top of the passed state view and
/// the provided runtime environment.
fn from_borrowed(state_view: &'s S, runtime_environment: E) -> Self {
fn from_borrowed(state_view: &'s S, environment: E) -> Self {
let adapter = StateViewAdapter {
environment,
state_view: BorrowedOrOwned::Borrowed(state_view),
};
let storage = adapter.into_unsync_code_storage(runtime_environment);
let storage = adapter.into_unsync_code_storage();
Self { storage }
}

/// Creates new instance of [AptosCodeStorageAdapter] capturing the passed state view and the
/// provided environment.
fn from_owned(state_view: S, runtime_environment: E) -> Self {
fn from_owned(state_view: S, environment: E) -> Self {
let adapter = StateViewAdapter {
environment,
state_view: BorrowedOrOwned::Owned(state_view),
};
let storage = adapter.into_unsync_code_storage(runtime_environment);
let storage = adapter.into_unsync_code_storage();
Self { storage }
}

Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm-types/src/module_write_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use move_core_types::{
account_address::AccountAddress, identifier::IdentStr, language_storage::ModuleId,
vm_status::StatusCode,
};
use move_vm_runtime::ModuleStorage;
use move_vm_runtime::storage::module_storage::ModuleStorage;
use std::collections::BTreeMap;

/// A write with a published module, also containing the information about its address and name.
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ use move_vm_metrics::{Timer, VM_TIMER};
use move_vm_runtime::{
logging::expect_no_verification_errors,
module_traversal::{TraversalContext, TraversalStorage},
RuntimeEnvironment, WithRuntimeEnvironment,
storage::environment::{RuntimeEnvironment, WithRuntimeEnvironment},
};
use move_vm_types::gas::{GasMeter, UnmeteredGasMeter};
use num_cpus;
Expand Down
6 changes: 4 additions & 2 deletions aptos-move/aptos-vm/src/move_vm_ext/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ use move_core_types::{
vm_status::StatusCode,
};
use move_vm_runtime::{
move_vm::MoveVM, native_extensions::NativeContextExtensions, session::Session, ModuleStorage,
VerifiedModuleBundle,
move_vm::MoveVM,
native_extensions::NativeContextExtensions,
session::Session,
storage::{module_storage::ModuleStorage, publishing::VerifiedModuleBundle},
};
use move_vm_types::{value_serde::serialize_and_allow_delayed_values, values::Value};
use std::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use aptos_vm_types::{
storage::change_set_configs::ChangeSetConfigs,
};
use move_core_types::vm_status::{err_msg, StatusCode, VMStatus};
use move_vm_runtime::ModuleStorage;
use move_vm_runtime::storage::module_storage::ModuleStorage;

fn unwrap_or_invariant_violation<T>(value: Option<T>, msg: &str) -> Result<T, VMStatus> {
value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use move_binary_format::{compatibility::Compatibility, errors::Location, Compile
use move_core_types::{
account_address::AccountAddress, ident_str, value::MoveValue, vm_status::VMStatus,
};
use move_vm_runtime::{module_traversal::TraversalContext, ModuleStorage, StagingModuleStorage};
use move_vm_runtime::{
module_traversal::TraversalContext,
storage::{module_storage::ModuleStorage, publishing::StagingModuleStorage},
};

#[derive(Deref, DerefMut)]
pub struct UserSession<'r, 'l> {
Expand Down
5 changes: 4 additions & 1 deletion aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use aptos_vm_environment::{
prod_configs::{aptos_default_ty_builder, aptos_prod_vm_config},
};
use aptos_vm_types::storage::change_set_configs::ChangeSetConfigs;
use move_vm_runtime::{move_vm::MoveVM, RuntimeEnvironment, WithRuntimeEnvironment};
use move_vm_runtime::{
move_vm::MoveVM,
storage::environment::{RuntimeEnvironment, WithRuntimeEnvironment},
};
use std::ops::Deref;

/// Used by genesis to create runtime environment and VM ([GenesisMoveVM]), encapsulating all
Expand Down
4 changes: 3 additions & 1 deletion aptos-move/aptos-vm/src/move_vm_ext/warm_vm_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use move_core_types::{
language_storage::{ModuleId, CORE_CODE_ADDRESS},
vm_status::StatusCode,
};
use move_vm_runtime::{config::VMConfig, move_vm::MoveVM, WithRuntimeEnvironment};
use move_vm_runtime::{
config::VMConfig, move_vm::MoveVM, storage::environment::WithRuntimeEnvironment,
};
use once_cell::sync::Lazy;
use std::collections::HashMap;

Expand Down
5 changes: 4 additions & 1 deletion aptos-move/block-executor/src/code_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use move_binary_format::{
use move_core_types::{
account_address::AccountAddress, identifier::IdentStr, language_storage::ModuleId,
};
use move_vm_runtime::{Module, RuntimeEnvironment, Script, WithRuntimeEnvironment};
use move_vm_runtime::{
storage::environment::{RuntimeEnvironment, WithRuntimeEnvironment},
Module, Script,
};
use move_vm_types::code::{
ambassador_impl_ScriptCache, Code, ModuleCache, ModuleCode, ModuleCodeBuilder, ScriptCache,
WithBytes,
Expand Down
5 changes: 4 additions & 1 deletion aptos-move/block-executor/src/code_cache_global_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use move_binary_format::{
use move_core_types::{
account_address::AccountAddress, ident_str, language_storage::ModuleId, vm_status::VMStatus,
};
use move_vm_runtime::{Module, ModuleStorage, WithRuntimeEnvironment};
use move_vm_runtime::{
storage::{environment::WithRuntimeEnvironment, module_storage::ModuleStorage},
Module,
};
use move_vm_types::code::WithSize;
use parking_lot::{Mutex, MutexGuard};
use std::{hash::Hash, ops::Deref, sync::Arc};
Expand Down
5 changes: 4 additions & 1 deletion aptos-move/block-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ use core::panic;
use fail::fail_point;
use move_binary_format::CompiledModule;
use move_core_types::{language_storage::ModuleId, value::MoveTypeLayout, vm_status::StatusCode};
use move_vm_runtime::{Module, RuntimeEnvironment, WithRuntimeEnvironment};
use move_vm_runtime::{
storage::environment::{RuntimeEnvironment, WithRuntimeEnvironment},
Module,
};
use move_vm_types::code::ModuleCache;
use num_cpus;
use rayon::ThreadPool;
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/block-executor/src/txn_last_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crossbeam::utils::CachePadded;
use dashmap::DashSet;
use move_binary_format::CompiledModule;
use move_core_types::{language_storage::ModuleId, value::MoveTypeLayout};
use move_vm_runtime::{Module, RuntimeEnvironment};
use move_vm_runtime::{storage::environment::RuntimeEnvironment, Module};
use std::{
collections::{BTreeMap, HashSet},
fmt::Debug,
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/block-executor/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use move_binary_format::{
CompiledModule,
};
use move_core_types::{language_storage::ModuleId, value::MoveTypeLayout, vm_status::StatusCode};
use move_vm_runtime::{Module, RuntimeEnvironment};
use move_vm_runtime::{storage::environment::RuntimeEnvironment, Module};
use move_vm_types::{
delayed_values::delayed_field_id::ExtractUniqueIndex,
value_serde::{
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-tests/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use move_core_types::{
};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
ModuleStorage,
storage::module_storage::ModuleStorage,
};
use move_vm_types::gas::UnmeteredGasMeter;
use serde::Serialize;
Expand Down
17 changes: 14 additions & 3 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ use aptos_vm_types::{
};
use bytes::Bytes;
use claims::assert_ok;
use move_binary_format::errors::{Location, VMResult};
use move_binary_format::{
compatibility::Compatibility,
errors::{Location, VMResult},
};
use move_core_types::{
account_address::AccountAddress,
identifier::Identifier,
Expand All @@ -62,7 +65,10 @@ use move_core_types::{
};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
ModuleStorage, RuntimeEnvironment, StagingModuleStorage,
storage::{
environment::RuntimeEnvironment, module_storage::ModuleStorage,
publishing::StagingModuleStorage,
},
};
use move_vm_types::gas::UnmeteredGasMeter;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -992,7 +998,12 @@ fn publish_framework_with_loader_v1(

#[allow(deprecated)]
session
.publish_module_bundle(code, addr, &mut UnmeteredGasMeter)
.publish_module_bundle_with_compat_config(
code,
addr,
&mut UnmeteredGasMeter,
Compatibility::full_check(),
)
.unwrap_or_else(|e| {
panic!(
"Failure publishing package `{}`: {:?}",
Expand Down
1 change: 1 addition & 0 deletions third_party/move/move-vm/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
bytes = { workspace = true }
claims = { workspace = true }
memory-stats = { workspace = true }
move-binary-format = { path = "../../move-binary-format", features = ["testing"] }
move-bytecode-verifier = { path = "../../move-bytecode-verifier" }
Expand Down
Loading

0 comments on commit 9d7c430

Please sign in to comment.