diff --git a/external-crates/move/crates/move-cli/src/sandbox/commands/publish.rs b/external-crates/move/crates/move-cli/src/sandbox/commands/publish.rs index 95b578c7e9f68..38485a47fa9d4 100644 --- a/external-crates/move/crates/move-cli/src/sandbox/commands/publish.rs +++ b/external-crates/move/crates/move-cli/src/sandbox/commands/publish.rs @@ -14,7 +14,7 @@ use move_vm_runtime::{ runtime::MoveRuntime, shared::{linkage_context::LinkageContext, types::PackageStorageId}, }; -use std::collections::{BTreeSet, HashMap}; +use std::collections::{BTreeMap, BTreeSet}; pub fn publish( natives: impl IntoIterator, @@ -55,7 +55,7 @@ pub fn publish( .collect::>(); // Build the dependency map from the package - let mut dependency_map = HashMap::new(); + let mut dependency_map = BTreeMap::new(); for (name, unit) in package.deps_compiled_units.iter() { let unit_address = *unit.unit.module.self_id().address(); if let Some(other) = dependency_map.insert(unit_address, unit_address) { @@ -77,7 +77,7 @@ pub fn publish( let mut gas_status = get_gas_status(cost_table, None)?; // Create a `LinkageContext` - let linkage_context = LinkageContext::new(package_storage_id, dependency_map); + let linkage_context = LinkageContext::new(dependency_map); // Serialize the modules into a package to prepare them for publishing let pkg = StoredPackage::from_module_for_testing_with_linkage( diff --git a/external-crates/move/crates/move-cli/src/sandbox/utils/on_disk_state_view.rs b/external-crates/move/crates/move-cli/src/sandbox/utils/on_disk_state_view.rs index 6ae6f6b722b31..f2d30ed5c0ef4 100644 --- a/external-crates/move/crates/move-cli/src/sandbox/utils/on_disk_state_view.rs +++ b/external-crates/move/crates/move-cli/src/sandbox/utils/on_disk_state_view.rs @@ -411,7 +411,6 @@ impl OnDiskStateView { "Found circular dependencies during dependency generation." ); let linkage_context = LinkageContext::new( - *package_address, all_dependencies .into_iter() .map(|id| (id, id)) diff --git a/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs b/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs index c1ee06af19c7f..69566e614cccd 100644 --- a/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs +++ b/external-crates/move/crates/move-transactional-test-runner/src/vm_test_harness.rs @@ -41,11 +41,7 @@ use move_vm_runtime::{ }; use once_cell::sync::Lazy; -use std::{ - collections::{BTreeMap, HashMap}, - path::Path, - sync::Arc, -}; +use std::{collections::BTreeMap, path::Path, sync::Arc}; const STD_ADDR: AccountAddress = AccountAddress::ONE; @@ -87,24 +83,29 @@ impl Linkage { .add_entry(*runtime_id, *storage_id) .map_err(|err| err.finish(Location::Undefined))?; } - // Remap the root address if it is in the linkage table since it may be overriden - existing_linkage.root_package = existing_linkage - .linkage_table - .get(&existing_linkage.root_package) - .unwrap_or(&existing_linkage.root_package) - .clone(); Ok(existing_linkage) } } impl PublishLinkageArgs { pub fn overlay(&self, existing_linkage: LinkageContext) -> VMResult { - let mut linkage = self.linkage.overlay(existing_linkage)?; - if let Some(location) = self.location { - linkage.root_package = location; - } + self.linkage.overlay(existing_linkage) + } - Ok(linkage) + pub fn resolve_publication_location( + &self, + sender: AccountAddress, + linkage: &LinkageContext, + ) -> AccountAddress { + // 1. Use location if specified; otherwise + // 2. Use the sender address (remapped if it exists in the linkage table). + self.location.unwrap_or( + linkage + .linkage_table + .get(&sender) + .copied() + .expect("Sender address not found in linkage table"), + ) } } @@ -218,8 +219,7 @@ impl<'a> MoveTestAdapter<'a> for SimpleRuntimeTestAdapter { let move_stdlib = MOVE_STDLIB_COMPILED.to_vec(); let sender = *move_stdlib.first().unwrap().self_id().address(); println!("generating stdlib linkage"); - let linkage_context = - LinkageContext::new(sender, HashMap::from([(sender, sender)])); + let linkage_context = LinkageContext::new(BTreeMap::from([(sender, sender)])); println!("calling stdlib publish with address {sender:?}"); let pkg = StoredPackage::from_module_for_testing_with_linkage( sender, @@ -271,16 +271,19 @@ impl<'a> MoveTestAdapter<'a> for SimpleRuntimeTestAdapter { sender, &pub_modules, )?)?; + let storage_id = extra_args.resolve_publication_location(sender, &linkage_context); println!("linkage: {linkage_context:#?}"); + println!("publication location: {storage_id}"); println!("doing publish"); let pkg = StoredPackage::from_module_for_testing_with_linkage( - sender, + storage_id, linkage_context, pub_modules.clone(), )?; + let runtime_id = pkg.runtime_id(); let publish_result = self.perform_action(gas_budget, |inner_adapter, _gas_status| { let pkg = pkg.into_serialized_package(); - inner_adapter.publish_package(sender, pkg)?; + inner_adapter.publish_package(runtime_id, pkg)?; println!("done"); Ok(()) }); @@ -322,18 +325,21 @@ impl<'a> MoveTestAdapter<'a> for SimpleRuntimeTestAdapter { sender, &pub_modules, )?)?; + let storage_id = extra_args.resolve_publication_location(sender, &linkage_context); println!("linkage: {linkage_context:#?}"); + println!("publication location: {storage_id}"); let mut gas_meter = Self::make_gas_status(gas_budget); println!("doing verification"); let pkg = StoredPackage::from_module_for_testing_with_linkage( - sender, + storage_id, linkage_context, pub_modules.clone(), )?; + let runtime_id = pkg.runtime_id(); let pkg = pkg.into_serialized_package(); let (verif_pkg, mut publish_vm) = self .perform_action_with_gas(&mut gas_meter, |inner_adapter, _gas_status| { - inner_adapter.verify_package(sender, pkg) + inner_adapter.verify_package(runtime_id, pkg) })?; println!("doing calls"); let signers: Vec<_> = signers diff --git a/external-crates/move/crates/move-vm-runtime/src/dev_utils/compilation_utils.rs b/external-crates/move/crates/move-vm-runtime/src/dev_utils/compilation_utils.rs index 16a1a6996a4f8..66790697e5fb8 100644 --- a/external-crates/move/crates/move-vm-runtime/src/dev_utils/compilation_utils.rs +++ b/external-crates/move/crates/move-vm-runtime/src/dev_utils/compilation_utils.rs @@ -114,6 +114,6 @@ pub fn compile_packages( ) -> BTreeMap { compile_packages_in_file(filename, dependencies) .into_iter() - .map(|p| (p.linkage_context.root_package(), p)) + .map(|p| (p.package_id, p)) .collect() } diff --git a/external-crates/move/crates/move-vm-runtime/src/dev_utils/in_memory_test_adapter.rs b/external-crates/move/crates/move-vm-runtime/src/dev_utils/in_memory_test_adapter.rs index 33cd91a152e59..2cb453a98efbf 100644 --- a/external-crates/move/crates/move-vm-runtime/src/dev_utils/in_memory_test_adapter.rs +++ b/external-crates/move/crates/move-vm-runtime/src/dev_utils/in_memory_test_adapter.rs @@ -123,7 +123,7 @@ impl VMTestAdapter for InMemoryTestAdapter { // TODO: VM error instead? panic!("Did not find runtime ID {runtime_id} in linkage context."); }; - assert!(storage_id == package.storage_id); + assert_eq!(storage_id, package.storage_id); let mut gas_meter = GasStatus::new_unmetered(); self.runtime.validate_package( &self.storage, @@ -204,7 +204,6 @@ impl VMTestAdapter for InMemoryTestAdapter { "Found circular dependencies during linkage generation." ); let linkage_context = LinkageContext::new( - storage_id, all_dependencies .into_iter() .map(|id| (id, id)) diff --git a/external-crates/move/crates/move-vm-runtime/src/dev_utils/storage.rs b/external-crates/move/crates/move-vm-runtime/src/dev_utils/storage.rs index 3aacd0d7b0a5c..972f3dd24fe4f 100644 --- a/external-crates/move/crates/move-vm-runtime/src/dev_utils/storage.rs +++ b/external-crates/move/crates/move-vm-runtime/src/dev_utils/storage.rs @@ -3,7 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - shared::{linkage_context::LinkageContext, types::PackageStorageId}, + shared::{ + linkage_context::LinkageContext, + types::{PackageStorageId, RuntimePackageId}, + }, validation::verification::ast as verif_ast, }; use anyhow::Result; @@ -15,7 +18,7 @@ use move_core_types::{ language_storage::ModuleId, resolver::{ModuleResolver, MoveResolver, SerializedPackage, TypeOrigin}, }; -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; // ------------------------------------------------------------------------------------------------- // Types @@ -36,6 +39,8 @@ pub struct DeltaStorage<'a, 'b, S> { /// Simple in-memory representation of packages #[derive(Debug, Clone)] pub struct StoredPackage { + /// The package ID (address) for this package. + pub package_id: PackageStorageId, pub modules: BTreeMap>, /// For each dependency (including transitive dependencies), maps runtime package ID to the /// storage ID of the package that is to be used for the linkage rooted at this package. @@ -70,20 +75,21 @@ impl<'a, 'b, S: MoveResolver> DeltaStorage<'a, 'b, S> { impl StoredPackage { fn empty(storage_id: AccountAddress) -> Self { Self { + package_id: storage_id, modules: BTreeMap::new(), - linkage_context: LinkageContext::new(storage_id, HashMap::new()), + linkage_context: LinkageContext::new(BTreeMap::new()), type_origin_table: vec![], } } pub fn from_modules_for_testing( - storage_id: AccountAddress, + storage_id: PackageStorageId, modules: Vec, ) -> Result { assert!(!modules.is_empty()); // Map the modules in this package to `storage_id` and generate the identity linkage for // all deps. - let mut linkage_table = HashMap::new(); + let mut linkage_table = BTreeMap::new(); let type_origin_table = generate_type_origins(storage_id, &modules); let modules: BTreeMap<_, _> = modules .into_iter() @@ -104,14 +110,15 @@ impl StoredPackage { .collect::>()?; Ok(Self { + package_id: storage_id, modules, - linkage_context: LinkageContext::new(storage_id, linkage_table), + linkage_context: LinkageContext::new(linkage_table), type_origin_table, }) } pub fn from_module_for_testing_with_linkage( - storage_id: AccountAddress, + storage_id: PackageStorageId, linkage_context: LinkageContext, modules: Vec, ) -> Result { @@ -126,6 +133,7 @@ impl StoredPackage { .collect::>()?; Ok(Self { + package_id: storage_id, modules, linkage_context, type_origin_table, @@ -134,6 +142,7 @@ impl StoredPackage { pub fn from_verified_package(verified_package: verif_ast::Package) -> Self { Self { + package_id: verified_package.storage_id, modules: verified_package .as_modules() .into_iter() @@ -147,7 +156,6 @@ impl StoredPackage { }) .collect(), linkage_context: LinkageContext::new( - verified_package.storage_id, verified_package.linkage_table.into_iter().collect(), ), type_origin_table: verified_package.type_origin_table, @@ -156,12 +164,26 @@ impl StoredPackage { pub fn into_serialized_package(self) -> SerializedPackage { SerializedPackage { - storage_id: self.linkage_context.root_package(), + storage_id: self.package_id, modules: self.modules.into_values().collect(), linkage_table: self.linkage_context.linkage_table.into_iter().collect(), type_origin_table: self.type_origin_table, } } + + pub fn runtime_id(&self) -> RuntimePackageId { + self.linkage_context + .linkage_table + .iter() + .find_map(|(k, v)| { + if *v == self.package_id { + Some(*k) + } else { + None + } + }) + .expect("address not found in linkage table") + } } pub fn generate_type_origins( @@ -206,10 +228,8 @@ impl InMemoryStorage { } pub fn publish_package(&mut self, stored_package: StoredPackage) { - self.accounts.insert( - stored_package.linkage_context.root_package(), - stored_package, - ); + self.accounts + .insert(stored_package.package_id, stored_package); } pub fn publish_or_overwrite_module( diff --git a/external-crates/move/crates/move-vm-runtime/src/dev_utils/vm_test_adapter.rs b/external-crates/move/crates/move-vm-runtime/src/dev_utils/vm_test_adapter.rs index a64397bead151..95b5f058baddd 100644 --- a/external-crates/move/crates/move-vm-runtime/src/dev_utils/vm_test_adapter.rs +++ b/external-crates/move/crates/move-vm-runtime/src/dev_utils/vm_test_adapter.rs @@ -13,7 +13,7 @@ use crate::{ }; use move_binary_format::{errors::VMResult, file_format::CompiledModule}; use move_core_types::resolver::{MoveResolver, SerializedPackage}; -use std::collections::HashMap; +use std::collections::BTreeMap; // FIXME(cswords): support gas @@ -76,10 +76,7 @@ pub trait VMTestAdapter { /// Retrieve the linkage context for the given package in `Storage`. fn get_linkage_context(&self, package_id: PackageStorageId) -> VMResult { let pkg = self.get_package_from_store(&package_id)?; - Ok(LinkageContext::new( - package_id, - HashMap::from_iter(pkg.linkage_table), - )) + Ok(LinkageContext::new(BTreeMap::from_iter(pkg.linkage_table))) } fn get_package_from_store(&self, package_id: &PackageStorageId) -> VMResult; diff --git a/external-crates/move/crates/move-vm-runtime/src/execution/dispatch_tables.rs b/external-crates/move/crates/move-vm-runtime/src/execution/dispatch_tables.rs index eaceed50ecc23..569ed2ab76ff7 100644 --- a/external-crates/move/crates/move-vm-runtime/src/execution/dispatch_tables.rs +++ b/external-crates/move/crates/move-vm-runtime/src/execution/dispatch_tables.rs @@ -11,7 +11,9 @@ use crate::{ cache::identifier_interner::IdentifierKey, jit::execution::ast::{Datatype, EnumType, Function, Module, Package, StructType, Type}, shared::{ - constants::{MAX_TYPE_INSTANTIATION_NODES, MAX_TYPE_TO_LAYOUT_NODES, VALUE_DEPTH_MAX}, + constants::{ + HISTORICAL_MAX_TYPE_TO_LAYOUT_NODES, MAX_TYPE_INSTANTIATION_NODES, VALUE_DEPTH_MAX, + }, types::RuntimePackageId, vm_pointer::VMPointer, }, @@ -30,6 +32,7 @@ use move_core_types::{ use move_binary_format::file_format::DatatypeTyParameter; use move_core_types::{annotated_value as A, identifier::Identifier, runtime_value as R}; +use move_vm_config::runtime::VMConfig; use parking_lot::RwLock; use std::{collections::BTreeMap, sync::Arc}; @@ -52,6 +55,7 @@ use tracing::error; /// vtable/cross-package function resolution but we will keep it simple for now. #[derive(Debug, Clone)] pub struct VMDispatchTables { + pub(crate) vm_config: Arc, pub(crate) loaded_packages: BTreeMap>, } @@ -142,8 +146,14 @@ pub struct DepthFormula { impl VMDispatchTables { /// Create a new RuntimeVTables instance. /// NOTE: This assumes linkage has already occured. - pub fn new(loaded_packages: BTreeMap>) -> VMResult { - Ok(Self { loaded_packages }) + pub fn new( + vm_config: Arc, + loaded_packages: BTreeMap>, + ) -> VMResult { + Ok(Self { + vm_config, + loaded_packages, + }) } pub fn get_package(&self, id: &RuntimePackageId) -> PartialVMResult> { @@ -654,7 +664,12 @@ impl VMDispatchTables { count: &mut u64, depth: u64, ) -> PartialVMResult { - if *count > MAX_TYPE_TO_LAYOUT_NODES { + if *count + > self + .vm_config + .max_type_to_layout_nodes + .unwrap_or(HISTORICAL_MAX_TYPE_TO_LAYOUT_NODES) + { return Err(PartialVMError::new(StatusCode::TOO_MANY_TYPE_NODES)); } if depth > VALUE_DEPTH_MAX { @@ -795,7 +810,12 @@ impl VMDispatchTables { count: &mut u64, depth: u64, ) -> PartialVMResult { - if *count > MAX_TYPE_TO_LAYOUT_NODES { + if *count + > self + .vm_config + .max_type_to_layout_nodes + .unwrap_or(HISTORICAL_MAX_TYPE_TO_LAYOUT_NODES) + { return Err(PartialVMError::new(StatusCode::TOO_MANY_TYPE_NODES)); } if depth > VALUE_DEPTH_MAX { diff --git a/external-crates/move/crates/move-vm-runtime/src/execution/vm.rs b/external-crates/move/crates/move-vm-runtime/src/execution/vm.rs index 8abf8b8e7d39b..f765977e0283b 100644 --- a/external-crates/move/crates/move-vm-runtime/src/execution/vm.rs +++ b/external-crates/move/crates/move-vm-runtime/src/execution/vm.rs @@ -325,7 +325,6 @@ impl<'extensions> MoveVM<'extensions> { // deserialization should be done outside of the VM calls. let (ref_ids, deserialized_args) = deserialize_args( &self.virtual_tables, - &self.vm_config, &mut self.base_heap, arg_types, serialized_args, @@ -348,13 +347,9 @@ impl<'extensions> MoveVM<'extensions> { deserialized_args, )?; - let serialized_return_values = serialize_return_values( - &self.virtual_tables, - &self.vm_config, - &return_types, - return_values, - ) - .map_err(|e| e.finish(Location::Undefined))?; + let serialized_return_values = + serialize_return_values(&self.virtual_tables, &return_types, return_values) + .map_err(|e| e.finish(Location::Undefined))?; let serialized_mut_ref_outputs = mut_ref_args .into_iter() .map(|(ndx, ty)| { @@ -362,8 +357,7 @@ impl<'extensions> MoveVM<'extensions> { // take the value of each reference; return values first in the case that a value // points into this local let local_val = self.base_heap.take_loc(*heap_ref_id)?; - let (bytes, layout) = - serialize_return_value(&self.virtual_tables, &self.vm_config, &ty, local_val)?; + let (bytes, layout) = serialize_return_value(&self.virtual_tables, &ty, local_val)?; Ok((ndx as LocalIndex, bytes, layout)) }) .collect::>() diff --git a/external-crates/move/crates/move-vm-runtime/src/runtime/mod.rs b/external-crates/move/crates/move-vm-runtime/src/runtime/mod.rs index 91230c2051b6d..98f0e67dbfb5e 100644 --- a/external-crates/move/crates/move-vm-runtime/src/runtime/mod.rs +++ b/external-crates/move/crates/move-vm-runtime/src/runtime/mod.rs @@ -15,10 +15,7 @@ use move_binary_format::errors::VMResult; use move_core_types::resolver::{MoveResolver, SerializedPackage}; use move_vm_config::runtime::VMConfig; -use std::{ - collections::{BTreeMap, HashMap}, - sync::Arc, -}; +use std::{collections::BTreeMap, sync::Arc}; // FIXME(cswords): This is only public for testing... pub mod package_resolution; @@ -123,7 +120,7 @@ impl MoveRuntime { .map(|pkg| (pkg.runtime.runtime_id, Arc::clone(&pkg.runtime))) .collect::>>(); - let virtual_tables = VMDispatchTables::new(runtime_packages)?; + let virtual_tables = VMDispatchTables::new(self.vm_config.clone(), runtime_packages)?; let base_heap = BaseHeap::new(); @@ -165,10 +162,7 @@ impl MoveRuntime { dbg_println!("\n\nPublishing module at {storage_id} (=> {pkg_runtime_id})\n\n"); let data_cache = TransactionDataCache::new(data_cache); - let link_context = LinkageContext::new( - pkg.storage_id, - HashMap::from_iter(pkg.linkage_table.clone()), - ); + let link_context = LinkageContext::new(BTreeMap::from_iter(pkg.linkage_table.clone())); // Verify a provided serialized package. This will validate the provided serialized // package, including attempting to jit-compile the package and verify linkage with its @@ -181,7 +175,7 @@ impl MoveRuntime { &self.vm_config, &data_cache, &link_context, - link_context.all_package_dependencies()?, + link_context.all_package_dependencies_except(pkg.storage_id)?, )?; let verified_pkg = { let deps = pkg_dependencies @@ -206,7 +200,7 @@ impl MoveRuntime { .map(|pkg| (pkg.runtime.runtime_id, Arc::clone(&pkg.runtime))) .collect::>>(); - let virtual_tables = VMDispatchTables::new(runtime_packages)?; + let virtual_tables = VMDispatchTables::new(self.vm_config.clone(), runtime_packages)?; let base_heap = BaseHeap::new(); diff --git a/external-crates/move/crates/move-vm-runtime/src/shared/constants.rs b/external-crates/move/crates/move-vm-runtime/src/shared/constants.rs index b11c38fb27b1e..cc4c219e58335 100644 --- a/external-crates/move/crates/move-vm-runtime/src/shared/constants.rs +++ b/external-crates/move/crates/move-vm-runtime/src/shared/constants.rs @@ -22,7 +22,7 @@ pub const VALUE_DEPTH_MAX: u64 = 128; /// fields for struct types. /// Maximal nodes which are allowed when converting to layout. This includes the types of /// fields for datatypes. -pub const MAX_TYPE_TO_LAYOUT_NODES: u64 = 256; +pub const HISTORICAL_MAX_TYPE_TO_LAYOUT_NODES: u64 = 256; /// Maximal nodes which are all allowed when instantiating a generic type. This does not include /// field types of datatypes. diff --git a/external-crates/move/crates/move-vm-runtime/src/shared/linkage_context.rs b/external-crates/move/crates/move-vm-runtime/src/shared/linkage_context.rs index 942dd8edf3eda..f8eff8c5b30cd 100644 --- a/external-crates/move/crates/move-vm-runtime/src/shared/linkage_context.rs +++ b/external-crates/move/crates/move-vm-runtime/src/shared/linkage_context.rs @@ -1,7 +1,7 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use std::collections::{BTreeSet, HashMap}; +use std::collections::{BTreeMap, BTreeSet}; use move_binary_format::errors::{PartialVMError, PartialVMResult, VMResult}; use move_core_types::{ @@ -15,9 +15,6 @@ use crate::shared::types::{PackageStorageId, RuntimePackageId}; /// table, allowing the same module in storage to be run against different dependencies. #[derive(Debug, Clone)] pub struct LinkageContext { - /// The root package address for linkage checking. For publication, this should be the address - /// of publication. For loading, this should be the root address being loaded. - pub root_package: PackageStorageId, // Linkage Table. This is a table indicating, for a given Address, how it should be linked. // This is purely for versioning. Assume some Package P is published at V1 and V2 as: // P V1 -> 0xCAFE @@ -25,18 +22,12 @@ pub struct LinkageContext { // All calls to P in the root package will call 0xCAFE as the Runtime ID, but during loading // and JIT compilation we need to rewrite these. The linkage table here will redirect 0xCAFE to // 0xDEAD for this purpose. - pub linkage_table: HashMap, + pub linkage_table: BTreeMap, } impl LinkageContext { - pub fn new( - root_package: PackageStorageId, - linkage_table: HashMap, - ) -> Self { - Self { - root_package, - linkage_table, - } + pub fn new(linkage_table: BTreeMap) -> Self { + Self { linkage_table } } pub fn contains_key(&self, address: &RuntimePackageId) -> bool { @@ -84,12 +75,6 @@ impl LinkageContext { } } - /// The root package identifies the root package to use for mapping from runtime `ModuleId`s to - /// the `ModuleId`s in storage that they are loaded from as returned by `relocate`. - pub fn root_package(&self) -> PackageStorageId { - self.root_package - } - /// Translate the runtime `module_id` to the on-chain `ModuleId` that it should be loaded from. pub fn relocate(&self, module_id: &ModuleId) -> PartialVMResult { self.linkage_table @@ -125,11 +110,14 @@ impl LinkageContext { /// Gives the transitive dependencies (as stored package IDs) of the linking context. This is /// computed as the values of the linkage table, minus the root package address. - pub fn all_package_dependencies(&self) -> VMResult> { + pub fn all_package_dependencies_except( + &self, + except: PackageStorageId, + ) -> VMResult> { Ok(self .linkage_table .values() - .filter(|id| *id != &self.root_package) + .filter(|id| *id != &except) .cloned() .collect::>()) } diff --git a/external-crates/move/crates/move-vm-runtime/src/shared/serialization.rs b/external-crates/move/crates/move-vm-runtime/src/shared/serialization.rs index 74a1f7a9973c6..c9336e437c5a0 100644 --- a/external-crates/move/crates/move-vm-runtime/src/shared/serialization.rs +++ b/external-crates/move/crates/move-vm-runtime/src/shared/serialization.rs @@ -14,7 +14,6 @@ use move_binary_format::{ file_format::LocalIndex, }; use move_core_types::{runtime_value::MoveTypeLayout, vm_status::StatusCode}; -use move_vm_config::runtime::VMConfig; use tracing::warn; @@ -68,7 +67,6 @@ pub fn deserialize_value( /// Returns the list of mutable references plus the vector of values. pub fn deserialize_args( vtables: &VMDispatchTables, - _vm_config: &VMConfig, heap: &mut BaseHeap, arg_tys: Vec, serialized_args: Vec>, @@ -106,7 +104,6 @@ pub fn deserialize_args( pub fn serialize_return_value( vtables: &VMDispatchTables, - vm_config: &VMConfig, ty: &Type, value: Value, ) -> PartialVMResult<(Vec, MoveTypeLayout)> { @@ -123,7 +120,7 @@ pub fn serialize_return_value( _ => (ty, value), }; - let layout = if vm_config.rethrow_serialization_type_layout_errors { + let layout = if vtables.vm_config.rethrow_serialization_type_layout_errors { vtables.type_to_type_layout(ty)? } else { vtables.type_to_type_layout(ty).map_err(|_err| { @@ -142,7 +139,6 @@ pub fn serialize_return_value( pub fn serialize_return_values( vtables: &VMDispatchTables, - vm_config: &VMConfig, return_types: &[Type], return_values: Vec, ) -> PartialVMResult, MoveTypeLayout)>> { @@ -161,6 +157,6 @@ pub fn serialize_return_values( return_types .iter() .zip(return_values) - .map(|(ty, value)| serialize_return_value(vtables, vm_config, ty, value)) + .map(|(ty, value)| serialize_return_value(vtables, ty, value)) .collect() } diff --git a/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_entry_point_tests.rs b/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_entry_point_tests.rs index 042252f1827dd..f492d18ee3055 100644 --- a/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_entry_point_tests.rs +++ b/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_entry_point_tests.rs @@ -18,14 +18,14 @@ use move_core_types::{ runtime_value::{serialize_values, MoveValue}, vm_status::StatusType, }; -use std::collections::HashMap; +use std::collections::BTreeMap; const TEST_ADDR: AccountAddress = AccountAddress::new([42; AccountAddress::LENGTH]); #[test] fn call_non_existent_module() { let adapter = InMemoryTestAdapter::new(); - let linkage = LinkageContext::new(TEST_ADDR, HashMap::new()); + let linkage = LinkageContext::new(BTreeMap::new()); let mut vm = adapter.make_vm(linkage).unwrap(); let module_id = ModuleId::new(TEST_ADDR, Identifier::new("M").unwrap()); diff --git a/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_storage_tests.rs b/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_storage_tests.rs index 35f2b71115170..f0c6bddb6a065 100644 --- a/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_storage_tests.rs +++ b/external-crates/move/crates/move-vm-runtime/src/unit_tests/bad_storage_tests.rs @@ -78,7 +78,6 @@ fn test_malformed_module() { blob, ); let linkage = LinkageContext { - root_package: TEST_ADDR, linkage_table: [(TEST_ADDR, TEST_ADDR)].into_iter().collect(), }; @@ -200,8 +199,7 @@ fn test_missing_module_dependency() { StoredPackage::from_modules_for_testing(TEST_ADDR, vec![n]).unwrap(), ); - let linkage = - LinkageContext::new(TEST_ADDR, [(TEST_ADDR, TEST_ADDR)].into_iter().collect()); + let linkage = LinkageContext::new([(TEST_ADDR, TEST_ADDR)].into_iter().collect()); let Err(err) = adapter.make_vm(linkage) else { panic!("Expected an error, but passed"); }; @@ -269,8 +267,7 @@ fn test_malformed_module_dependency() { StoredPackage::from_modules_for_testing(TEST_ADDR, vec![n.clone()]).unwrap(), ); - let linkage = - LinkageContext::new(TEST_ADDR, [(TEST_ADDR, TEST_ADDR)].into_iter().collect()); + let linkage = LinkageContext::new([(TEST_ADDR, TEST_ADDR)].into_iter().collect()); adapter.storage.publish_or_overwrite_module( *n.self_id().address(), n.self_id().name().to_owned(), @@ -342,8 +339,7 @@ fn test_unverifiable_module_dependency() { StoredPackage::from_modules_for_testing(TEST_ADDR, vec![n.clone()]).unwrap(), ); - let linkage = - LinkageContext::new(TEST_ADDR, [(TEST_ADDR, TEST_ADDR)].into_iter().collect()); + let linkage = LinkageContext::new([(TEST_ADDR, TEST_ADDR)].into_iter().collect()); adapter.storage.publish_or_overwrite_module( *n.self_id().address(), n.self_id().name().to_owned(), diff --git a/external-crates/move/crates/move-vm-runtime/src/unit_tests/instantiation_tests.rs b/external-crates/move/crates/move-vm-runtime/src/unit_tests/instantiation_tests.rs index 358a27e6388dd..b9025ae47e1e7 100644 --- a/external-crates/move/crates/move-vm-runtime/src/unit_tests/instantiation_tests.rs +++ b/external-crates/move/crates/move-vm-runtime/src/unit_tests/instantiation_tests.rs @@ -521,7 +521,6 @@ fn make_module( let module_id = module.self_id(); let mut pkg = StoredPackage::from_modules_for_testing(addr, vec![module.clone()]).unwrap(); pkg.linkage_context = LinkageContext::new( - addr, [(addr, addr)] .into_iter() .chain(module.module_handles().iter().map(|mhandle| { diff --git a/external-crates/move/crates/move-vm-runtime/src/unit_tests/loader_tests.rs b/external-crates/move/crates/move-vm-runtime/src/unit_tests/loader_tests.rs index 795276a9078e8..412694e3fcc0b 100644 --- a/external-crates/move/crates/move-vm-runtime/src/unit_tests/loader_tests.rs +++ b/external-crates/move/crates/move-vm-runtime/src/unit_tests/loader_tests.rs @@ -42,13 +42,7 @@ use move_core_types::{ use move_vm_config::{runtime::VMConfig, verifier::VerifierConfig}; use once_cell::sync::Lazy; use parking_lot::RwLock; -use std::{ - collections::{BTreeMap, HashMap}, - path::PathBuf, - str::FromStr, - sync::Arc, - thread, -}; +use std::{collections::BTreeMap, path::PathBuf, str::FromStr, sync::Arc, thread}; const ADDR2: AccountAddress = { let mut address = [0u8; AccountAddress::LENGTH]; @@ -126,7 +120,7 @@ impl Adapter { let vm = Arc::new(RwLock::new( InMemoryTestAdapter::new_with_runtime_and_storage(runtime, store), )); - let linkage = LinkageContext::new(ADDR2, HashMap::new()); + let linkage = LinkageContext::new(BTreeMap::new()); Self { store: { RelinkingStore { @@ -140,14 +134,12 @@ impl Adapter { fn with_linkage( &self, - context: PackageStorageId, - linkage: HashMap, + linkage: BTreeMap, type_origin: Vec<((&IdentStr, &IdentStr), PackageStorageId)>, ) -> Self { Self { store: { let linkage = LinkageContext { - root_package: context, linkage_table: linkage, }; let type_origin = type_origin @@ -167,20 +159,6 @@ impl Adapter { } } - fn runtime_id_for_link_context(link_ctx: &LinkageContext) -> RuntimePackageId { - link_ctx - .linkage_table - .iter() - .find_map(|(k, v)| { - if *v == link_ctx.root_package() { - Some(*k) - } else { - None - } - }) - .expect("address not found in linkage table") - } - fn publish_package(&mut self, mut pkg: StoredPackage) { if !self.store.linkage.linkage_table.is_empty() { pkg.linkage_context = self.store.linkage.clone(); @@ -188,7 +166,7 @@ impl Adapter { if !self.store.type_origin.is_empty() { pkg.type_origin_table = self.store.type_origin.clone(); } - let runtime_id = Self::runtime_id_for_link_context(&pkg.linkage_context); + let runtime_id = pkg.runtime_id(); self.runtime_adapter .write() .publish_package(runtime_id, pkg.into_serialized_package()) @@ -202,7 +180,7 @@ impl Adapter { if !self.store.type_origin.is_empty() { pkg.type_origin_table = self.store.type_origin.clone(); } - let runtime_id = Self::runtime_id_for_link_context(&pkg.linkage_context); + let runtime_id = pkg.runtime_id(); self.runtime_adapter .write() .publish_package(runtime_id, pkg.into_serialized_package()) @@ -335,7 +313,8 @@ fn get_depth_tests_modules() -> StoredPackage { } fn get_relinker_tests_modules_with_deps<'s>( - root_account_addr: RuntimePackageId, + runtime_addr: RuntimePackageId, + storage_addr: PackageStorageId, module: &'s str, deps: impl IntoIterator, ) -> anyhow::Result { @@ -352,9 +331,9 @@ fn get_relinker_tests_modules_with_deps<'s>( .build_and_report()?; let modules = expect_modules(units) - .filter(|m| *m.self_id().address() == root_account_addr) + .filter(|m| *m.self_id().address() == runtime_addr) .collect(); - Ok(StoredPackage::from_modules_for_testing(root_account_addr, modules).unwrap()) + Ok(StoredPackage::from_modules_for_testing(storage_addr, modules).unwrap()) } #[test] @@ -362,7 +341,7 @@ fn load() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let pkg = get_loader_tests_modules(); adapter.publish_package(pkg); // calls all functions sequentially @@ -373,7 +352,7 @@ fn load() { fn test_depth() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let modules = get_depth_tests_modules(); let structs = vec![ ( @@ -576,7 +555,7 @@ fn test_depth() { fn load_concurrent() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let modules = get_loader_tests_modules(); adapter.publish_package(modules); // makes 15 threads @@ -587,7 +566,7 @@ fn load_concurrent() { fn load_concurrent_many() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let modules = get_loader_tests_modules(); adapter.publish_package(modules); // makes 150 threads @@ -598,42 +577,35 @@ fn load_concurrent_many() { fn relink() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let a0 = ModuleId::new(ADDR4, ident_str!("a").to_owned()); let b0 = ModuleId::new(ADDR3, ident_str!("b").to_owned()); let c0 = ModuleId::new(ADDR2, ident_str!("c").to_owned()); let c1 = ModuleId::new(ADDR5, ident_str!("c").to_owned()); - let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); - let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v1", []).unwrap(); - let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v0", ["c_v0"]).unwrap(); - let a0_modules = get_relinker_tests_modules_with_deps(ADDR4, "a_v0", ["b_v0", "c_v1"]).unwrap(); + let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); + let c1_modules = + get_relinker_tests_modules_with_deps(ADDR2, *c1.address(), "c_v1", []).unwrap(); + let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, ADDR3, "b_v0", ["c_v0"]).unwrap(); + let a0_modules = + get_relinker_tests_modules_with_deps(ADDR4, ADDR4, "a_v0", ["b_v0", "c_v1"]).unwrap(); // Publish the first version of C, and B which is published depending on it. adapter.publish_package(c0_modules); adapter - .with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ) + .with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]) .publish_package(b0_modules); assert_eq!( vec![MoveValue::U64(42 + 1)], adapter - .with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3),]), - vec![], - ) + .with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3),]), vec![],) .call_function_with_return(&b0, ident_str!("b")), ); let mut adapter = adapter.with_linkage( - ADDR5, - /* linkage */ HashMap::from_iter([(ADDR2, ADDR5)]), + /* linkage */ BTreeMap::from_iter([(ADDR2, ADDR5)]), /* type origin */ vec![ ((c0.name(), ident_str!("S")), *c0.address()), @@ -645,8 +617,7 @@ fn relink() { // B will be relinked to use C when executed in the adapter relinking against A. adapter.publish_package(c1_modules); let mut adapter = adapter.with_linkage( - ADDR4, - HashMap::from([(ADDR2, ADDR5), (ADDR3, ADDR3), (ADDR4, ADDR4)]), + BTreeMap::from([(ADDR2, ADDR5), (ADDR3, ADDR3), (ADDR4, ADDR4)]), vec![], ); adapter.publish_package(a0_modules); @@ -661,18 +632,17 @@ fn relink() { fn relink_publish_err() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); - let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); - let b1_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v1", ["c_v1"]).unwrap(); + let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); + let b1_modules = get_relinker_tests_modules_with_deps(ADDR3, ADDR2, "b_v1", ["c_v1"]).unwrap(); // B was built against the later version of C but published against the earlier version, // which should fail because a function is missing. adapter.publish_package(c0_modules); adapter .with_linkage( - ADDR3, - HashMap::from_iter([(ADDR2, ADDR2), (ADDR3, ADDR3)]), + BTreeMap::from_iter([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![], ) .publish_package_with_error(b1_modules); @@ -688,22 +658,19 @@ fn relink_load_err() { let c0 = ModuleId::new(ADDR2, ident_str!("c").to_owned()); let c1 = ModuleId::new(ADDR5, ident_str!("c").to_owned()); - let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); - let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v1", []).unwrap(); - let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v0", ["c_v0"]).unwrap(); - let b1_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v1", ["c_v1"]).unwrap(); + let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); + let c1_modules = + get_relinker_tests_modules_with_deps(ADDR2, *c1.address(), "c_v1", []).unwrap(); + let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, ADDR3, "b_v0", ["c_v0"]).unwrap(); + let b1_modules = + get_relinker_tests_modules_with_deps(ADDR3, *b1.address(), "b_v1", ["c_v1"]).unwrap(); // B v0 works with C v0 adapter - .with_linkage( - *c0.address(), - HashMap::from([(*c0.address(), *c0.address())]), - vec![], - ) + .with_linkage(BTreeMap::from([(*c0.address(), *c0.address())]), vec![]) .publish_package(c0_modules); let mut adapter = adapter.with_linkage( - *b0.address(), - HashMap::from([ + BTreeMap::from([ (*c0.address(), *c0.address()), (*b0.address(), *b0.address()), ]), @@ -718,9 +685,8 @@ fn relink_load_err() { adapter .with_linkage( - *c1.address(), /* linkage */ - HashMap::from_iter([(*c0.address(), *c1.address())]), + BTreeMap::from_iter([(*c0.address(), *c1.address())]), /* type origin */ vec![ ((c0.name(), ident_str!("S")), *c0.address()), @@ -731,9 +697,8 @@ fn relink_load_err() { // B v1 works with C v1 let mut adapter = adapter.with_linkage( - *b1.address(), /* linkage */ - HashMap::from_iter([ + BTreeMap::from_iter([ (*b0.address(), *b1.address()), (*c0.address(), *c1.address()), ]), @@ -754,9 +719,8 @@ fn relink_load_err() { // But B v1 *does not* work with C v0 adapter .with_linkage( - *b1.address(), /* linkage */ - HashMap::from_iter([ + BTreeMap::from_iter([ (*b0.address(), *b1.address()), (*c0.address(), *c0.address()), ]), @@ -779,23 +743,21 @@ fn relink_type_identity() { let c0 = ModuleId::new(ADDR2, ident_str!("c").to_owned()); let b1 = ModuleId::new(ADDR6, ident_str!("b").to_owned()); let c1 = ModuleId::new(ADDR5, ident_str!("c").to_owned()); - let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); - let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v1", []).unwrap(); - let b1_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v1", ["c_v1"]).unwrap(); + let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); + let c1_modules = + get_relinker_tests_modules_with_deps(ADDR2, *c1.address(), "c_v1", []).unwrap(); + let b1_modules = + get_relinker_tests_modules_with_deps(ADDR3, *b1.address(), "b_v1", ["c_v1"]).unwrap(); - let mut adapter = adapter.with_linkage( - *c0.address(), - HashMap::from([(*c0.address(), *c0.address())]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(*c0.address(), *c0.address())]), vec![]); adapter.publish_package(c0_modules); let c0_s = adapter.load_type(&TypeTag::from_str("0x2::c::S").unwrap()); adapter .with_linkage( - *c1.address(), /* linkage */ - HashMap::from_iter([(*c0.address(), *c1.address())]), + BTreeMap::from_iter([(*c0.address(), *c1.address())]), /* type origin */ vec![ ((c0.name(), ident_str!("S")), *c0.address()), @@ -805,9 +767,8 @@ fn relink_type_identity() { .publish_package(c1_modules); let mut adapter = adapter.with_linkage( - *b1.address(), /* linkage */ - HashMap::from_iter([ + BTreeMap::from_iter([ (*b0.address(), *b1.address()), (*c0.address(), *c1.address()), ]), @@ -827,7 +788,6 @@ fn relink_type_identity() { assert_ne!(c1_s, b1_s); } -/// XXX/TODO(vm-rework): need to fix defining IDs for types for this test to pass #[test] fn relink_defining_module_successive() { let c0 = ModuleId::new(ADDR2, ident_str!("c").to_owned()); @@ -836,21 +796,21 @@ fn relink_defining_module_successive() { // This test simulates building up a sequence of upgraded packages over a number of publishes let data_store = InMemoryStorage::new(); let mut adapter = Adapter::new(data_store).with_linkage( - *c0.address(), - HashMap::from([(ADDR2, ADDR2)]), + BTreeMap::from([(ADDR2, ADDR2)]), vec![((c0.name(), ident_str!("S")), *c0.address())], ); - let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); - let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v1", []).unwrap(); - let c2_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v2", []).unwrap(); + let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); + let c1_modules = + get_relinker_tests_modules_with_deps(ADDR2, *c1.address(), "c_v1", []).unwrap(); + let c2_modules = + get_relinker_tests_modules_with_deps(ADDR2, *c2.address(), "c_v2", []).unwrap(); adapter.publish_package(c0_modules); let c0_s = adapter.load_type(&TypeTag::from_str("0x2::c::S").unwrap()); let mut adapter = adapter.with_linkage( - *c1.address(), - /* linkage */ HashMap::from_iter([(*c0.address(), *c1.address())]), + /* linkage */ BTreeMap::from_iter([(*c0.address(), *c1.address())]), /* type origin */ vec![ ((c0.name(), ident_str!("S")), *c0.address()), @@ -863,8 +823,7 @@ fn relink_defining_module_successive() { let c1_r = adapter.load_type(&TypeTag::from_str("0x2::c::R").unwrap()); let mut adapter = adapter.with_linkage( - *c2.address(), - /* linkage */ HashMap::from_iter([(*c0.address(), *c2.address())]), + /* linkage */ BTreeMap::from_iter([(*c0.address(), *c2.address())]), /* type origin */ vec![ ((c0.name(), ident_str!("S")), *c0.address()), @@ -901,7 +860,6 @@ fn relink_defining_module_successive() { assert_eq!(st.module_id(), c2); } -/// XXX/TODO(vm-rework): need to fix defining IDs for types for this test to pass #[test] fn relink_defining_module_oneshot() { // Simulates the loader being made aware of the final package in a sequence of upgrades (perhaps @@ -915,11 +873,11 @@ fn relink_defining_module_oneshot() { let c1 = ModuleId::new(ADDR5, ident_str!("c").to_owned()); let c2 = ModuleId::new(ADDR6, ident_str!("c").to_owned()); - let c2_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v2", []).unwrap(); + let c2_modules = + get_relinker_tests_modules_with_deps(ADDR2, *c2.address(), "c_v2", []).unwrap(); let mut adapter = Adapter::new(data_store).with_linkage( - *c2.address(), - /* linkage */ HashMap::from_iter([(*c0.address(), *c2.address())]), + /* linkage */ BTreeMap::from_iter([(*c0.address(), *c2.address())]), /* type origin */ vec![ ((c0.name(), ident_str!("S")), *c0.address()), @@ -962,8 +920,8 @@ fn relink_defining_module_oneshot() { // let b1 = ModuleId::new(ADDR6, ident_str!("b").to_owned()); // // let adapter = Adapter::new(data_store); -// let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); -// let b1_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v1", ["c_v1"]).unwrap(); +// let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); +// let b1_modules = get_relinker_tests_modules_with_deps(ADDR3, *b1.address(), "b_v1", ["c_v1"]).unwrap(); // // // B was built against the later version of C but published against the earlier version, // // which should fail because a function is missing. @@ -971,9 +929,9 @@ fn relink_defining_module_oneshot() { // .linkage( // *c0.address(), // /* linkage */ -// HashMap::from_iter([(*c0.address(), *c0.address())]), +// BTreeMap::from_iter([(*c0.address(), *c0.address())]), // /* type origin */ -// HashMap::from_iter([((c0.clone(), ident_str!("S").to_owned()), c0.clone())]), +// BTreeMap::from_iter([((c0.clone(), ident_str!("S").to_owned()), c0.clone())]), // ) // .publish_modules(c0_modules); // @@ -982,12 +940,12 @@ fn relink_defining_module_oneshot() { // let mut adapter = adapter.linkage( // *b0.address(), // /* linkage */ -// HashMap::from_iter([ +// BTreeMap::from_iter([ // (*b0.address(), *b1.address()), // (*c0.address(), *c0.address()), // ]), // /* type origin */ -// HashMap::from_iter([ +// BTreeMap::from_iter([ // ((c0.clone(), ident_str!("S").to_owned()), c0.clone()), // ((b0.clone(), ident_str!("S").to_owned()), b1.clone()), // ]), @@ -1007,25 +965,21 @@ fn publish_bundle_and_load() { let adapter = Adapter::new(data_store); let a0 = ModuleId::new(ADDR4, ident_str!("a").to_owned()); - let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v1", []).unwrap(); - let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v0", ["c_v0"]).unwrap(); - let a0_modules = get_relinker_tests_modules_with_deps(ADDR4, "a_v0", ["b_v0", "c_v1"]).unwrap(); + let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v1", []).unwrap(); + let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, ADDR3, "b_v0", ["c_v0"]).unwrap(); + let a0_modules = + get_relinker_tests_modules_with_deps(ADDR4, ADDR4, "a_v0", ["b_v0", "c_v1"]).unwrap(); adapter - .with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]) + .with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]) .publish_package(c1_modules); adapter - .with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ) + .with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]) .publish_package(b0_modules); let mut adapter = adapter.with_linkage( - ADDR4, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3), (ADDR4, ADDR4)]), + BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3), (ADDR4, ADDR4)]), vec![], ); adapter.publish_package(a0_modules); @@ -1039,44 +993,38 @@ fn publish_bundle_and_load() { #[test] fn publish_bundle_with_err_retry() { let data_store = InMemoryStorage::new(); - let adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + let adapter = Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let a0 = ModuleId::new(ADDR4, ident_str!("a").to_owned()); - let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v0", []).unwrap(); - let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, "c_v1", []).unwrap(); - let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, "b_v0", ["c_v0"]).unwrap(); - let a0_modules = get_relinker_tests_modules_with_deps(ADDR4, "a_v0", ["b_v0", "c_v1"]).unwrap(); + let c0_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR2, "c_v0", []).unwrap(); + let c1_modules = get_relinker_tests_modules_with_deps(ADDR2, ADDR5, "c_v1", []).unwrap(); + let b0_modules = get_relinker_tests_modules_with_deps(ADDR3, ADDR3, "b_v0", ["c_v0"]).unwrap(); + let a0_modules = + get_relinker_tests_modules_with_deps(ADDR4, ADDR4, "a_v0", ["b_v0", "c_v1"]).unwrap(); adapter - .with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]) + .with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]) .publish_package(c0_modules); adapter - .with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ) + .with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]) .publish_package(b0_modules); // Publishing the bundle should fail, because `a0` should not link with `c0`. adapter .with_linkage( - ADDR4, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3), (ADDR4, ADDR4)]), + BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3), (ADDR4, ADDR4)]), vec![], ) .publish_package_with_error(a0_modules.clone()); // publish the upgrade of c0 to ADDR5 adapter - .with_linkage(ADDR5, HashMap::from([(ADDR2, ADDR5)]), vec![]) + .with_linkage(BTreeMap::from([(ADDR2, ADDR5)]), vec![]) .publish_package(c1_modules); let mut adapter = adapter.with_linkage( - ADDR4, - HashMap::from([(ADDR2, ADDR5), (ADDR3, ADDR3), (ADDR4, ADDR4)]), + BTreeMap::from([(ADDR2, ADDR5), (ADDR3, ADDR3), (ADDR4, ADDR4)]), vec![], ); @@ -1094,7 +1042,7 @@ fn publish_bundle_with_err_retry() { fn deep_dependency_list_0() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1104,11 +1052,8 @@ fn deep_dependency_list_0() { let pkg = StoredPackage::from_modules_for_testing(ADDR2, modules).unwrap(); adapter.publish_package(pkg); - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = format!("A{}", max); let dep_name = format!("A{}", max - 1); let deps = vec![dep_name]; @@ -1121,7 +1066,7 @@ fn deep_dependency_list_0() { fn deep_dependency_list_1() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1131,11 +1076,8 @@ fn deep_dependency_list_1() { let pkg = StoredPackage::from_modules_for_testing(ADDR2, modules).unwrap(); adapter.publish_package(pkg); - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = format!("A{}", max); let dep_name = format!("A{}", max - 1); let deps = vec![dep_name]; @@ -1148,7 +1090,7 @@ fn deep_dependency_list_1() { fn deep_dependency_list_ok_0() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1158,11 +1100,8 @@ fn deep_dependency_list_ok_0() { let pkg = StoredPackage::from_modules_for_testing(ADDR2, modules).unwrap(); adapter.publish_package(pkg); - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = format!("A{}", max); let dep_name = format!("A{}", max - 1); let deps = vec![dep_name]; @@ -1175,7 +1114,7 @@ fn deep_dependency_list_ok_0() { fn deep_dependency_list_ok_1() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1185,11 +1124,8 @@ fn deep_dependency_list_ok_1() { let pkg = StoredPackage::from_modules_for_testing(ADDR2, modules).unwrap(); adapter.publish_package(pkg); - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = format!("A{}", max); let dep_name = format!("A{}", max - 1); let deps = vec![dep_name]; @@ -1202,7 +1138,7 @@ fn deep_dependency_list_ok_1() { fn deep_dependency_tree_0() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1214,11 +1150,8 @@ fn deep_dependency_tree_0() { adapter.publish_package(pkg); // use one of the module in the tree - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = "ASome".to_string(); let dep_name = format!("A_{}_{}", height - 1, width - 1); let deps = vec![dep_name]; @@ -1231,7 +1164,7 @@ fn deep_dependency_tree_0() { fn deep_dependency_tree_1() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1243,11 +1176,8 @@ fn deep_dependency_tree_1() { adapter.publish_package(pkg); // use one of the module in the tree - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = "ASome".to_string(); let dep_name = format!("A_{}_{}", height - 1, width - 1); let deps = vec![dep_name]; @@ -1260,7 +1190,7 @@ fn deep_dependency_tree_1() { fn deep_dependency_tree_ok_0() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1272,11 +1202,8 @@ fn deep_dependency_tree_ok_0() { adapter.publish_package(pkg); // use one of the module in the tree - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = "ASome".to_string(); let dep_name = format!("A_{}_{}", height - 1, width - 1); let deps = vec![dep_name]; @@ -1289,7 +1216,7 @@ fn deep_dependency_tree_ok_0() { fn deep_dependency_tree_ok_1() { let data_store = InMemoryStorage::new(); let mut adapter = - Adapter::new(data_store).with_linkage(ADDR2, HashMap::from([(ADDR2, ADDR2)]), vec![]); + Adapter::new(data_store).with_linkage(BTreeMap::from([(ADDR2, ADDR2)]), vec![]); let mut modules = vec![]; @@ -1301,11 +1228,8 @@ fn deep_dependency_tree_ok_1() { adapter.publish_package(pkg); // use one of the module in the tree - let mut adapter = adapter.with_linkage( - ADDR3, - HashMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), - vec![], - ); + let mut adapter = + adapter.with_linkage(BTreeMap::from([(ADDR2, ADDR2), (ADDR3, ADDR3)]), vec![]); let name = "ASome".to_string(); let dep_name = format!("A_{}_{}", height - 1, width - 1); let deps = vec![dep_name]; diff --git a/external-crates/move/crates/move-vm-runtime/src/validation/deserialization/translate.rs b/external-crates/move/crates/move-vm-runtime/src/validation/deserialization/translate.rs index 93eca56188fde..3f6e43ee11f3b 100644 --- a/external-crates/move/crates/move-vm-runtime/src/validation/deserialization/translate.rs +++ b/external-crates/move/crates/move-vm-runtime/src/validation/deserialization/translate.rs @@ -13,12 +13,7 @@ pub(crate) fn package(vm_config: &VMConfig, pkg: SerializedPackage) -> VMResult< let mut modules = BTreeMap::new(); for module in pkg.modules.iter() { let module = CompiledModule::deserialize_with_config(module, &vm_config.binary_config) - .map_err(|err| -> move_binary_format::errors::VMError { - let msg = format!("Deserialization error: {:?}", err); - PartialVMError::new(StatusCode::CODE_DESERIALIZATION_ERROR) - .with_message(msg) - .finish(Location::Undefined) // TODO(tzakian): add Location::Package - })?; + .map_err(|err| err.finish(Location::Undefined))?; // TODO: add Location::Package modules.insert(module.self_id(), module); }