diff --git a/aptos-move/block-executor/src/code_cache.rs b/aptos-move/block-executor/src/code_cache.rs index 8d875dca1ce2d8..dd89710f32bb04 100644 --- a/aptos-move/block-executor/src/code_cache.rs +++ b/aptos-move/block-executor/src/code_cache.rs @@ -54,9 +54,7 @@ impl<'a, T: Transaction, S: TStateView, X: Executable> ModuleCodeB .map_err(|err| err.finish(Location::Undefined))? .map(|state_value| { let extension = Arc::new(AptosModuleExtension::new(state_value)); - - // TODO(loader_v2): This recomputes module hash twice, we should avoid it. - let (compiled_module, _, _) = self + let compiled_module = self .runtime_environment() .deserialize_into_compiled_module(extension.bytes())?; Ok(ModuleCode::from_deserialized(compiled_module, extension)) diff --git a/aptos-move/block-executor/src/executor.rs b/aptos-move/block-executor/src/executor.rs index 603bce0fbe1abc..db6358be8ed856 100644 --- a/aptos-move/block-executor/src/executor.rs +++ b/aptos-move/block-executor/src/executor.rs @@ -1220,7 +1220,7 @@ where // Since we have successfully serialized the module when converting into this transaction // write, the deserialization should never fail. - let (compiled_module, _, _) = runtime_environment + let compiled_module = runtime_environment .deserialize_into_compiled_module(state_value.bytes()) .map_err(|err| { let msg = format!("Failed to construct the module from state value: {:?}", err); diff --git a/third_party/move/move-vm/runtime/src/storage/environment.rs b/third_party/move/move-vm/runtime/src/storage/environment.rs index bc152dd1cc06b7..bebb5099c4e01b 100644 --- a/third_party/move/move-vm/runtime/src/storage/environment.rs +++ b/third_party/move/move-vm/runtime/src/storage/environment.rs @@ -25,10 +25,7 @@ use move_core_types::{ identifier::{IdentStr, Identifier}, vm_status::{sub_status::unknown_invariant_violation::EPARANOID_FAILURE, StatusCode}, }; -use move_vm_types::{ - loaded_data::runtime_types::{StructIdentifier, StructNameIndex}, - sha3_256, -}; +use move_vm_types::loaded_data::runtime_types::{StructIdentifier, StructNameIndex}; use std::sync::Arc; /// [MoveVM] runtime environment encapsulating different configurations. Shared between the VM and @@ -193,21 +190,15 @@ impl RuntimeEnvironment { result.map_err(|e| e.finish(Location::Undefined)) } - /// Deserializes bytes into a compiled module, also returning its size and hash. - pub fn deserialize_into_compiled_module( - &self, - bytes: &Bytes, - ) -> VMResult<(CompiledModule, usize, [u8; 32])> { - let compiled_module = - CompiledModule::deserialize_with_config(bytes, &self.vm_config().deserializer_config) - .map_err(|err| { + /// Deserializes bytes into a compiled module. + pub fn deserialize_into_compiled_module(&self, bytes: &Bytes) -> VMResult { + CompiledModule::deserialize_with_config(bytes, &self.vm_config().deserializer_config) + .map_err(|err| { let msg = format!("Deserialization error: {:?}", err); PartialVMError::new(StatusCode::CODE_DESERIALIZATION_ERROR) .with_message(msg) .finish(Location::Undefined) - })?; - - Ok((compiled_module, bytes.len(), sha3_256(bytes))) + }) } /// Deserializes bytes into a compiled script. diff --git a/third_party/move/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs b/third_party/move/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs index 186b0b86f875ff..fba7581d9d3416 100644 --- a/third_party/move/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs +++ b/third_party/move/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs @@ -17,9 +17,12 @@ use move_core_types::{ account_address::AccountAddress, identifier::IdentStr, language_storage::ModuleId, metadata::Metadata, }; -use move_vm_types::code::{ - ambassador_impl_ModuleCache, ModuleBytesStorage, ModuleCache, ModuleCode, ModuleCodeBuilder, - UnsyncModuleCache, WithBytes, WithHash, +use move_vm_types::{ + code::{ + ambassador_impl_ModuleCache, ModuleBytesStorage, ModuleCache, ModuleCode, + ModuleCodeBuilder, UnsyncModuleCache, WithBytes, WithHash, + }, + sha3_256, }; use std::{borrow::Borrow, ops::Deref, sync::Arc}; @@ -137,9 +140,10 @@ impl<'s, S: ModuleBytesStorage, E: WithRuntimeEnvironment> ModuleCodeBuilder Some(bytes) => bytes, None => return Ok(None), }; - let (compiled_module, _, hash) = self + let compiled_module = self .runtime_environment() .deserialize_into_compiled_module(&bytes)?; + let hash = sha3_256(&bytes); let extension = Arc::new(BytesWithHash::new(bytes, hash)); let module = ModuleCode::from_deserialized(compiled_module, extension); Ok(Some(module))