Skip to content

Commit

Permalink
[tests] fixed loading script errors & format
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Sep 4, 2024
1 parent 37d2315 commit c164354
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
3 changes: 1 addition & 2 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use aptos_vm_types::{
module_and_script_storage::{AptosCodeStorageAdapter, AsAptosCodeStorage},
storage::change_set_configs::ChangeSetConfigs,
};
use move_vm_runtime::move_vm::MoveVM;
use move_vm_runtime::{move_vm::MoveVM, RuntimeEnvironment};
use std::{ops::Deref, sync::Arc};
use move_vm_runtime::RuntimeEnvironment;

/// MoveVM wrapper which is used to run genesis initializations. Designed as a
/// stand-alone struct to ensure all genesis configurations are in one place,
Expand Down
9 changes: 6 additions & 3 deletions aptos-move/block-executor/src/modules_and_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use move_binary_format::{
};
use move_core_types::{account_address::AccountAddress, identifier::IdentStr, metadata::Metadata};
use move_vm_runtime::{
deserialize_script, module_cyclic_dependency_error, module_linker_error, script_hash,
CodeStorage, Module, ModuleStorage, Script,
deserialize_script, logging::expect_no_verification_errors, module_cyclic_dependency_error,
module_linker_error, script_hash, CodeStorage, Module, ModuleStorage, Script,
};
use std::{collections::HashSet, sync::Arc};

Expand Down Expand Up @@ -120,7 +120,10 @@ impl<'a, T: Transaction, S: TStateView<Key = T::Key>, X: Executable> CodeStorage
// Verify the script by also looking at its dependencies.
let immediate_dependencies = partially_verified_script
.immediate_dependencies_iter()
.map(|(addr, name)| self.fetch_verified_module(addr, name))
.map(|(addr, name)| {
self.fetch_verified_module(addr, name)
.map_err(|e| expect_no_verification_errors(e))
})
.collect::<VMResult<Vec<_>>>()?;
let script = self
.runtime_environment
Expand Down
12 changes: 7 additions & 5 deletions aptos-move/vm-genesis/src/genesis_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

#![forbid(unsafe_code)]

use aptos_types::state_store::{
errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage,
state_value::StateValue, TStateView,
use aptos_types::{
executable::ModulePath,
state_store::{
errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage,
state_value::StateValue, TStateView,
},
write_set::WriteOp,
};
use bytes::Bytes;
use move_core_types::language_storage::ModuleId;
use std::collections::{BTreeMap, HashMap};
use aptos_types::executable::ModulePath;
use aptos_types::write_set::WriteOp;

type Result<T, E = StateviewError> = std::result::Result<T, E>;

Expand Down
25 changes: 18 additions & 7 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,31 @@ use aptos_types::{
APTOS_MAX_KNOWN_VERSION,
},
transaction::{authenticator::AuthenticationKey, ChangeSet, Transaction, WriteSetPayload},
write_set::{TransactionWrite},
write_set::TransactionWrite,
};
use aptos_vm::{
data_cache::AsMoveResolver,
move_vm_ext::{GenesisMoveVM, SessionExt},
};
use aptos_vm_types::{
module_and_script_storage::module_storage::AptosModuleStorage, module_write_set::ModuleWriteSet,
change_set::VMChangeSet, module_and_script_storage::module_storage::AptosModuleStorage,
module_write_set::ModuleWriteSet,
};
use move_core_types::{
account_address::AccountAddress,
identifier::Identifier,
language_storage::{ModuleId, TypeTag},
value::{serialize_values, MoveTypeLayout, MoveValue},
};
use move_vm_runtime::{module_traversal::{TraversalContext, TraversalStorage}, ModuleStorage, TemporaryModuleStorage, UnreachableCodeStorage};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
ModuleStorage, TemporaryModuleStorage, UnreachableCodeStorage,
};
use move_vm_types::gas::UnmeteredGasMeter;
use once_cell::sync::Lazy;
use rand::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use aptos_vm_types::change_set::VMChangeSet;

// The seed is arbitrarily picked to produce a consistent key. XXX make this more formal?
const GENESIS_SEED: [u8; 32] = [42; 32];
Expand Down Expand Up @@ -179,7 +182,8 @@ pub fn encode_aptos_mainnet_genesis_transaction(
let mut new_id = [0u8; 32];
new_id[31] = 1;

let (additional_change_set, module_write_set) = publish_framework(&vm, HashValue::new(new_id), framework);
let (additional_change_set, module_write_set) =
publish_framework(&vm, HashValue::new(new_id), framework);
change_set
.squash_additional_change_set(additional_change_set)
.unwrap();
Expand Down Expand Up @@ -308,7 +312,8 @@ pub fn encode_genesis_change_set(
// Publish the framework, using a different id, in case both scripts create tables.
let mut new_id = [0u8; 32];
new_id[31] = 1;
let (additional_change_set, module_write_set) = publish_framework(&vm, HashValue::new(new_id), framework);
let (additional_change_set, module_write_set) =
publish_framework(&vm, HashValue::new(new_id), framework);
change_set
.squash_additional_change_set(additional_change_set)
.unwrap();
Expand Down Expand Up @@ -916,7 +921,13 @@ fn publish_framework_with_loader_v2(
let mut session = vm.new_genesis_session(&resolver, hash_value);

for pack in &framework.packages {
let addr = *pack.sorted_code_and_modules().first().unwrap().1.self_id().address();
let addr = *pack
.sorted_code_and_modules()
.first()
.unwrap()
.1
.self_id()
.address();
initialize_package(&mut session, &module_storage, addr, pack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
logging::expect_no_verification_errors,
script_hash,
storage::{
code_storage::deserialize_script,
Expand Down Expand Up @@ -100,7 +101,11 @@ impl<M: ModuleStorage + WithRuntimeEnvironment> UnsyncCodeStorage<M> {
.build_partially_verified_script(compiled_script.clone())?;
let immediate_dependencies = compiled_script
.immediate_dependencies_iter()
.map(|(addr, name)| self.module_storage.fetch_verified_module(addr, name))
.map(|(addr, name)| {
self.module_storage
.fetch_verified_module(addr, name)
.map_err(|e| expect_no_verification_errors(e))
})
.collect::<VMResult<Vec<_>>>()?;
Ok(Arc::new(
self.module_storage
Expand Down

0 comments on commit c164354

Please sign in to comment.