Skip to content

Commit

Permalink
[fixes] Fix raw module data & add env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Nov 12, 2024
1 parent a7fa2c3 commit b14d5f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
8 changes: 7 additions & 1 deletion aptos-move/aptos-vm-environment/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use aptos_vm_types::storage::StorageGasParameters;
use move_vm_runtime::{config::VMConfig, RuntimeEnvironment, WithRuntimeEnvironment};
use sha3::{Digest, Sha3_256};
use std::sync::Arc;
use aptos_types::on_chain_config::FeatureFlag;

/// A runtime environment which can be used for VM initialization and more. Contains features
/// used by execution, gas parameters, VM configs and global caches. Note that it is the user's
Expand Down Expand Up @@ -175,8 +176,13 @@ impl Environment {
) -> Self {
// We compute and store a hash of configs in order to distinguish different environments.
let mut sha3_256 = Sha3_256::new();
let features =
let mut features =
fetch_config_and_update_hash::<Features>(&mut sha3_256, state_view).unwrap_or_default();
if std::env::var("USE_LOADER_V2").is_ok() {
features.enable(FeatureFlag::ENABLE_LOADER_V2);
} else {
features.disable(FeatureFlag::ENABLE_LOADER_V2);
}

// If no chain ID is in storage, we assume we are in a testing environment.
let chain_id = fetch_config_and_update_hash::<ChainId>(&mut sha3_256, state_view)
Expand Down
9 changes: 8 additions & 1 deletion aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use aptos_vm_environment::{
use aptos_vm_types::storage::change_set_configs::ChangeSetConfigs;
use move_vm_runtime::{move_vm::MoveVM, RuntimeEnvironment, WithRuntimeEnvironment};
use std::ops::Deref;
use aptos_types::on_chain_config::FeatureFlag;

/// Used by genesis to create runtime environment and VM ([GenesisMoveVM]), encapsulating all
/// configs.
Expand All @@ -30,7 +31,13 @@ pub struct GenesisRuntimeBuilder {
impl GenesisRuntimeBuilder {
/// Returns a builder, capable of creating VM and runtime environment to run genesis.
pub fn new(chain_id: ChainId) -> Self {
let features = Features::default();
let mut features = Features::default();
if std::env::var("USE_LOADER_V2").is_ok() {
features.enable(FeatureFlag::ENABLE_LOADER_V2);
} else {
features.disable(FeatureFlag::ENABLE_LOADER_V2);
}

let timed_features = TimedFeaturesBuilder::enable_all().build();

let vm_config =
Expand Down
18 changes: 14 additions & 4 deletions crates/transaction-generator-lib/src/publishing/raw_module_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3864,10 +3864,10 @@ pub static MODULES_MODULE_LOADING_CHAIN_FRIENDS: Lazy<Vec<Vec<u8>>> = Lazy::new(
pub static PACKAGE_SIMPLE_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
13, 71, 101, 110, 101, 114, 105, 99, 77, 111, 100, 117, 108, 101, 1, 0, 0, 0,
0, 0, 0, 0, 0, 64, 68, 48, 69, 53, 68, 55, 70, 65, 50, 66, 65, 54,
68, 50, 65, 48, 57, 55, 55, 56, 51, 49, 51, 67, 57, 68, 69, 51, 56, 67,
69, 69, 68, 49, 49, 49, 68, 65, 70, 49, 67, 66, 53, 53, 56, 54, 52, 65,
67, 65, 52, 55, 56, 49, 53, 67, 65, 52, 53, 57, 66, 49, 66, 66, 132, 1,
0, 0, 0, 0, 0, 64, 69, 53, 53, 57, 68, 57, 51, 68, 67, 55, 70, 65,
56, 70, 70, 66, 70, 53, 70, 65, 57, 48, 49, 52, 57, 69, 49, 65, 56, 48,
56, 55, 57, 67, 65, 52, 56, 50, 66, 67, 52, 67, 48, 50, 48, 51, 51, 50,
53, 53, 52, 67, 50, 67, 48, 52, 49, 56, 67, 54, 56, 56, 53, 69, 132, 1,
31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 77, 139, 59, 14, 194, 48, 16, 68,
251, 61, 133, 229, 30, 135, 11, 80, 208, 64, 197, 9, 162, 20, 43, 123, 64, 86,
156, 93, 203, 134, 80, 32, 238, 142, 45, 1, 138, 102, 154, 249, 188, 49, 179, 159,
Expand All @@ -3887,6 +3887,16 @@ pub static PACKAGE_SIMPLE_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {
]
});

#[rustfmt::skip]
pub static SCRIPT_SIMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
161, 28, 235, 11, 7, 0, 0, 10, 2, 5, 0, 4, 6, 4, 34, 1, 6, 12,
0, 5, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 1, 3, 11, 0, 1, 2,
]
});

#[rustfmt::skip]
pub static MODULE_SIMPLE_SIMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-vm/runtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Default for VMConfig {
ty_builder: TypeBuilder::with_limits(128, 20),
disallow_dispatch_for_native: true,
use_compatibility_checker_v2: true,
use_loader_v2: false,
use_loader_v2: std::env::var("USE_LOADER_V2").is_ok(),
}
}
}
5 changes: 5 additions & 0 deletions types/src/on_chain_config/aptos_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ impl Default for Features {
for feature in FeatureFlag::default_features() {
features.enable(feature);
}
if std::env::var("USE_LOADER_V2").is_ok() {
features.enable(FeatureFlag::ENABLE_LOADER_V2);
} else {
features.disable(FeatureFlag::ENABLE_LOADER_V2);
}
features
}
}
Expand Down

0 comments on commit b14d5f5

Please sign in to comment.