diff --git a/aptos-move/aptos-vm-types/src/module_and_script_storage/module_storage.rs b/aptos-move/aptos-vm-types/src/module_and_script_storage/module_storage.rs index b7c828d00eda2..6f120feb35766 100644 --- a/aptos-move/aptos-vm-types/src/module_and_script_storage/module_storage.rs +++ b/aptos-move/aptos-vm-types/src/module_and_script_storage/module_storage.rs @@ -1,9 +1,29 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 +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::{DummyCodeStorage, ModuleStorage}; /// Represents module storage used by the Aptos blockchain. -pub trait AptosModuleStorage: ModuleStorage {} +pub trait AptosModuleStorage: ModuleStorage { + /// Returns the state value metadata of an associated with this module. The + /// error is returned if there is a storage error. If the module does not exist, + /// `None` is returned. + fn fetch_state_value_metadata( + &self, + address: &AccountAddress, + module_name: &IdentStr, + ) -> PartialVMResult>; +} -impl AptosModuleStorage for DummyCodeStorage {} +impl AptosModuleStorage for DummyCodeStorage { + fn fetch_state_value_metadata( + &self, + _address: &AccountAddress, + _module_name: &IdentStr, + ) -> PartialVMResult> { + Ok(None) + } +} diff --git a/aptos-move/aptos-vm-types/src/module_and_script_storage/state_view_adapter.rs b/aptos-move/aptos-vm-types/src/module_and_script_storage/state_view_adapter.rs index 84367a7320216..2072d18f9243f 100644 --- a/aptos-move/aptos-vm-types/src/module_and_script_storage/state_view_adapter.rs +++ b/aptos-move/aptos-vm-types/src/module_and_script_storage/state_view_adapter.rs @@ -1,13 +1,16 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -use crate::module_and_script_storage::{ - module_storage::AptosModuleStorage, script_storage::AptosScriptStorage, - state_view_adapter::ModuleStorageEntry::Deserialized, +use crate::{ + module_and_script_storage::{ + module_storage::AptosModuleStorage, script_storage::AptosScriptStorage, + state_view_adapter::ModuleStorageEntry::Deserialized, + }, + resolver::TModuleView, }; use aptos_types::{ on_chain_config::{Features, OnChainConfig}, - state_store::{state_key::StateKey, StateView}, + state_store::{state_key::StateKey, state_value::StateValueMetadata, StateView}, vm::configs::aptos_prod_deserializer_config, }; use bytes::Bytes; @@ -224,7 +227,16 @@ impl<'s, S: StateView> ModuleStorage for AptosCodeStorageAdapter<'s, S> { } } -impl<'s, S: StateView> AptosModuleStorage for AptosCodeStorageAdapter<'s, S> {} +impl<'s, S: StateView> AptosModuleStorage for AptosCodeStorageAdapter<'s, S> { + fn fetch_state_value_metadata( + &self, + address: &AccountAddress, + module_name: &IdentStr, + ) -> PartialVMResult> { + let state_key = StateKey::module(address, module_name); + self.state_view.get_module_state_value_metadata(&state_key) + } +} impl<'s, S: StateView> ScriptStorage for AptosCodeStorageAdapter<'s, S> { fn fetch_deserialized_script( diff --git a/aptos-move/aptos-vm/src/move_vm_ext/write_op_converter.rs b/aptos-move/aptos-vm/src/move_vm_ext/write_op_converter.rs index 3fe5bd7184494..d2d75dc741126 100644 --- a/aptos-move/aptos-vm/src/move_vm_ext/write_op_converter.rs +++ b/aptos-move/aptos-vm/src/move_vm_ext/write_op_converter.rs @@ -177,7 +177,6 @@ impl<'r> WriteOpConverter<'r> { for (bytes, compiled_module) in code_and_modules.into_iter() { let addr = compiled_module.self_addr(); let name = compiled_module.self_name(); - let state_key = StateKey::module(addr, name); let module_exists = module_storage.check_module_exists(addr, name)?; let op = if module_exists { @@ -186,8 +185,15 @@ impl<'r> WriteOpConverter<'r> { Op::New(bytes) }; - // TODO(loader_v2): Query state value metadata from module storage. - let write_op = self.convert_module(&state_key, op, false)?; + let state_value_metadata = module_storage.fetch_state_value_metadata(addr, name)?; + let write_op = self.convert( + state_value_metadata, + op, + // For modules, creation is never a modification. + false, + )?; + + let state_key = StateKey::module(addr, name); write_ops.insert(state_key, write_op); } Ok(write_ops)