Skip to content

Commit

Permalink
cherrypick (#13882)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov authored Jul 1, 2024
1 parent daea1c7 commit 4da8cad
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
5 changes: 4 additions & 1 deletion aptos-move/aptos-gas-schedule/src/ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/// - Changing how gas is calculated in any way
///
/// Change log:
/// - V21
/// - Fix type to type tag conversion in MoveVM
/// - V20
/// - Limits for bounding MoveVM type sizes
/// - V19
Expand Down Expand Up @@ -64,7 +66,7 @@
/// global operations.
/// - V1
/// - TBA
pub const LATEST_GAS_FEATURE_VERSION: u64 = 20;
pub const LATEST_GAS_FEATURE_VERSION: u64 = gas_feature_versions::RELEASE_V1_16;

pub mod gas_feature_versions {
pub const RELEASE_V1_8: u64 = 11;
Expand All @@ -76,4 +78,5 @@ pub mod gas_feature_versions {
pub const RELEASE_V1_13: u64 = 18;
pub const RELEASE_V1_14: u64 = 19;
pub const RELEASE_V1_15: u64 = 20;
pub const RELEASE_V1_16: u64 = 21;
}
6 changes: 2 additions & 4 deletions aptos-move/aptos-vm-types/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ impl Environment {
chain_id: ChainId,
ty_builder: TypeBuilder,
) -> Self {
// By default, do not use delayed field optimization. Instead, clients should enable it
// manually where applicable.
let delayed_field_optimization_enabled = false;
let pseudo_meter_vector_ty_to_ty_tag_construction = true;

let vm_config = aptos_prod_vm_config(
&features,
&timed_features,
delayed_field_optimization_enabled,
pseudo_meter_vector_ty_to_ty_tag_construction,
ty_builder,
);

Expand Down
27 changes: 9 additions & 18 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::{
use aptos_crypto::HashValue;
use aptos_gas_algebra::DynamicExpression;
use aptos_gas_schedule::{
AptosGasParameters, MiscGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION,
gas_feature_versions::RELEASE_V1_16, AptosGasParameters, MiscGasParameters,
NativeGasParameters, LATEST_GAS_FEATURE_VERSION,
};
use aptos_native_interface::SafeNativeBuilder;
use aptos_types::{
Expand All @@ -21,7 +22,7 @@ use aptos_vm_types::{
environment::{aptos_default_ty_builder, aptos_prod_ty_builder, Environment},
storage::change_set_configs::ChangeSetConfigs,
};
use move_vm_runtime::{config::VMConfig, move_vm::MoveVM};
use move_vm_runtime::move_vm::MoveVM;
use std::{ops::Deref, sync::Arc};

/// MoveVM wrapper which is used to run genesis initializations. Designed as a
Expand All @@ -39,13 +40,11 @@ impl GenesisMoveVM {
let features = Features::default();
let timed_features = TimedFeaturesBuilder::enable_all().build();

// Genesis runs sessions, where there is no concept of block execution.
// Hence, delayed fields are not enabled.
let delayed_field_optimization_enabled = false;
let pseudo_meter_vector_ty_to_ty_tag_construction = true;
let vm_config = aptos_prod_vm_config(
&features,
&timed_features,
delayed_field_optimization_enabled,
pseudo_meter_vector_ty_to_ty_tag_construction,
aptos_default_ty_builder(&features),
);

Expand Down Expand Up @@ -142,18 +141,10 @@ impl MoveVmExt {
);

// TODO(George): Move gas configs to environment to avoid this clone!
let vm_config = VMConfig {
verifier_config: env.vm_config().verifier_config.clone(),
deserializer_config: env.vm_config().deserializer_config.clone(),
paranoid_type_checks: env.vm_config().paranoid_type_checks,
check_invariant_in_swap_loc: env.vm_config().check_invariant_in_swap_loc,
max_value_nest_depth: env.vm_config().max_value_nest_depth,
type_max_cost: env.vm_config().type_max_cost,
type_base_cost: env.vm_config().type_base_cost,
type_byte_cost: env.vm_config().type_byte_cost,
delayed_field_optimization_enabled: env.vm_config().delayed_field_optimization_enabled,
ty_builder,
};
let mut vm_config = env.vm_config().clone();
vm_config.pseudo_meter_vector_ty_to_ty_tag_construction =
gas_feature_version >= RELEASE_V1_16;
vm_config.ty_builder = ty_builder;

Self {
inner: WarmVmCache::get_warm_vm(
Expand Down
2 changes: 2 additions & 0 deletions third_party/move/move-vm/runtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct VMConfig {
pub type_max_cost: u64,
pub type_base_cost: u64,
pub type_byte_cost: u64,
pub pseudo_meter_vector_ty_to_ty_tag_construction: bool,
pub delayed_field_optimization_enabled: bool,
pub ty_builder: TypeBuilder,
}
Expand All @@ -37,6 +38,7 @@ impl Default for VMConfig {
type_max_cost: 0,
type_base_cost: 0,
type_byte_cost: 0,
pseudo_meter_vector_ty_to_ty_tag_construction: true,
delayed_field_optimization_enabled: false,
ty_builder: TypeBuilder::Legacy,
}
Expand Down
9 changes: 8 additions & 1 deletion third_party/move/move-vm/runtime/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,14 @@ impl Loader {
Type::U256 => TypeTag::U256,
Type::Address => TypeTag::Address,
Type::Signer => TypeTag::Signer,
Type::Vector(ty) => TypeTag::Vector(Box::new(self.type_to_type_tag(ty)?)),
Type::Vector(ty) => {
let el_ty_tag = if self.vm_config.pseudo_meter_vector_ty_to_ty_tag_construction {
self.type_to_type_tag_impl(ty, gas_context)?
} else {
self.type_to_type_tag(ty)?
};
TypeTag::Vector(Box::new(el_ty_tag))
},
Type::Struct { idx, .. } => TypeTag::Struct(Box::new(self.struct_name_to_type_tag(
*idx,
&[],
Expand Down
7 changes: 5 additions & 2 deletions types/src/vm/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn aptos_prod_verifier_config(features: &Features) -> VerifierConfig {
pub fn aptos_prod_vm_config(
features: &Features,
timed_features: &TimedFeatures,
delayed_field_optimization_enabled: bool,
pseudo_meter_vector_ty_to_ty_tag_construction: bool,
ty_builder: TypeBuilder,
) -> VMConfig {
let check_invariant_in_swap_loc =
Expand Down Expand Up @@ -98,7 +98,10 @@ pub fn aptos_prod_vm_config(
type_max_cost,
type_base_cost,
type_byte_cost,
delayed_field_optimization_enabled,
pseudo_meter_vector_ty_to_ty_tag_construction,
// By default, do not use delayed field optimization. Instead, clients should enable it
// manually where applicable.
delayed_field_optimization_enabled: false,
ty_builder,
}
}
Expand Down

0 comments on commit 4da8cad

Please sign in to comment.