Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rahxephon89 committed Jul 18, 2024
1 parent 2591aae commit 8d829ed
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 40 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions aptos-move/aptos-e2e-comparison-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ bcs = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
itertools = { workspace = true }
move-command-line-common = { workspace = true }
move-compiler = { workspace = true }
move-compiler-v2 = { workspace = true }
move-core-types = { workspace = true }
move-model = { workspace = true }
move-package = { workspace = true }
Expand Down
81 changes: 67 additions & 14 deletions aptos-move/aptos-e2e-comparison-testing/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
use crate::{
check_aptos_packages_availability, compile_aptos_packages, compile_package,
data_state_view::DataStateView, generate_compiled_blob, is_aptos_package, CompilationCache,
DataManager, IndexReader, PackageInfo, TxnIndex, APTOS_COMMONS,
DataManager, IndexReader, PackageInfo, TxnIndex, APTOS_COMMONS, DISABLE_REF_CHECK,
DISABLE_SPEC_CHECK, ENABLE_REF_CHECK,
};
use anyhow::Result;
use aptos_framework::APTOS_PACKAGES;
use aptos_language_e2e_tests::{data_store::FakeDataStore, executor::FakeExecutor};
use aptos_types::{
access_path::Path,
contract_event::ContractEvent,
on_chain_config::{FeatureFlag, Features, OnChainConfig},
state_store::state_key::{inner::StateKeyInner, StateKey},
transaction::{Transaction, Version},
vm_status::VMStatus,
write_set::WriteSet,
write_set::{WriteSet, TOTAL_SUPPLY_STATE_KEY},
};
use aptos_validator_interface::AptosValidatorInterface;
use clap::ValueEnum;
use itertools::Itertools;
use move_core_types::{account_address::AccountAddress, language_storage::ModuleId};
use move_model::metadata::CompilerVersion;
use std::{cmp, collections::HashMap, path::PathBuf, sync::Arc};
use std::{cmp, collections::HashMap, env, path::PathBuf, sync::Arc};

fn add_packages_to_data_store(
data_store: &mut FakeDataStore,
Expand Down Expand Up @@ -90,18 +93,34 @@ pub struct Execution {
input_path: PathBuf,
pub execution_mode: ExecutionMode,
pub bytecode_version: u32,
pub skip_ref_packages: Option<String>,
}

impl Execution {
pub fn check_package_skip(&self, package_name: &str) -> bool {
println!("package name:{}", package_name);
if let Some(p) = &self.skip_ref_packages {
let packages = p.split(',').collect_vec();
packages.contains(&package_name)
} else {
false
}
}

pub fn output_result_str(&self, msg: String) {
eprintln!("{}", msg);
}

pub fn new(input_path: PathBuf, execution_mode: ExecutionMode) -> Self {
pub fn new(
input_path: PathBuf,
execution_mode: ExecutionMode,
skip_ref_packages: Option<String>,
) -> Self {
Self {
input_path,
execution_mode,
bytecode_version: 6,
skip_ref_packages,
}
}

Expand Down Expand Up @@ -220,6 +239,17 @@ impl Execution {
if compiled_cache.failed_packages_v2.contains(&package_info) {
v2_failed = true;
} else {
if self.check_package_skip(&package_info.package_name) {
env::set_var(
"MOVE_COMPILER_EXP",
format!("{},{}", DISABLE_SPEC_CHECK, DISABLE_REF_CHECK),
);
} else {
env::set_var(
"MOVE_COMPILER_EXP",
format!("{},{}", DISABLE_SPEC_CHECK, ENABLE_REF_CHECK),
);
}
let compiled_res_v2 =
compile_package(package_dir, &package_info, Some(CompilerVersion::V2_0));
if let Ok(compiled_res) = compiled_res_v2 {
Expand All @@ -237,7 +267,10 @@ impl Execution {
}
}
if v1_failed || v2_failed {
let mut err_msg = "compilation failed at ".to_string();
let mut err_msg = format!(
"compilation for the package {} failed at",
package_info.package_name
);
if v1_failed {
err_msg = format!("{} v1", err_msg);
}
Expand All @@ -262,11 +295,9 @@ impl Execution {
{
let compiled_result = self.compile_code(&txn_idx, compiled_cache);
if compiled_result.is_err() {
self.output_result_str(format!(
"compilation failed for the package:{} at version:{}",
txn_idx.package_info.package_name, cur_version
));
return compiled_result;
let err = compiled_result.unwrap_err();
self.output_result_str(format!("{} at version:{}", err, cur_version));
return Err(err);
}
}
// read the state data
Expand Down Expand Up @@ -381,6 +412,25 @@ impl Execution {
}
}

fn filter_stake_key(&self, key: &StateKey) -> bool {
if let StateKeyInner::AccessPath(p) = key.inner() {
let path = p.get_path();
if let Path::Resource(tag) = path {
if tag.name.as_str() == "CoinStore" && !tag.type_args.is_empty() {
let para_type = &tag.type_args[0];
if para_type.to_string() == "0x1::aptos_coin::AptosCoin" {
return true;
}
}
}
}
*key == *TOTAL_SUPPLY_STATE_KEY
}

fn filter_event_key(&self, event: &ContractEvent) -> bool {
event.type_tag().to_string() == "0x1::transaction_fee::FeeStatement"
}

fn print_mismatches(
&self,
cur_version: u64,
Expand Down Expand Up @@ -419,7 +469,7 @@ impl Execution {
for idx in 0..cmp::min(res_1.1.len(), res_2.1.len()) {
let event_1 = &res_1.1[idx];
let event_2 = &res_2.1[idx];
if event_1 != event_2 {
if event_1 != event_2 && !self.filter_event_key(event_1) {
event_error = true;
self.output_result_str(format!(
"event raised from V1: {} at index: {}",
Expand Down Expand Up @@ -462,11 +512,14 @@ impl Execution {
write_set_2.0, idx
));
}
if write_set_1.1 != write_set_2.1 {
if write_set_1.1 != write_set_2.1
&& write_set_1.0 == write_set_2.0
&& !self.filter_stake_key(write_set_1.0)
{
write_set_error = true;
self.output_result_str(format!(
"write set value is different at version: {}, index: {}",
cur_version, idx
"write set value is different at version: {}, index: {} for key:{:?}, key eq:{}",
cur_version, idx, write_set_1.0, write_set_1.0 == write_set_2.0
));
self.output_result_str(format!(
"state value at V1: {:?} at index: {}",
Expand Down
43 changes: 33 additions & 10 deletions aptos-move/aptos-e2e-comparison-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const ERR_LOG: &str = "err_log.txt";
const ROCKS_INDEX_DB: &str = "rocks_txn_idx_db";
pub const APTOS_COMMONS: &str = "aptos-commons";
const MAX_TO_FLUSH: usize = 50000;
pub const DISABLE_SPEC_CHECK: &str = "spec-check=off";
pub const DISABLE_REF_CHECK: &str = "reference-safety=off";
pub const ENABLE_REF_CHECK: &str = "reference-safety=on";

struct IndexWriter {
index_writer: BufWriter<File>,
Expand Down Expand Up @@ -436,10 +439,10 @@ fn compile_aptos_packages(
fn compile_package(
root_dir: PathBuf,
package_info: &PackageInfo,
compiler_verion: Option<CompilerVersion>,
compiler_version: Option<CompilerVersion>,
) -> anyhow::Result<CompiledPackage> {
let mut build_options = aptos_framework::BuildOptions {
compiler_version: compiler_verion,
compiler_version,
..Default::default()
};
build_options
Expand All @@ -450,8 +453,9 @@ fn compile_package(
Ok(built_package.package)
} else {
Err(anyhow::Error::msg(format!(
"compilation failed for compiler: {:?}",
compiler_verion
"compilation failed for the package:{} when using compiler: {:?}",
package_info.package_name.clone(),
compiler_version
)))
}
}
Expand All @@ -465,7 +469,16 @@ fn dump_and_compile_from_package_metadata(
) -> anyhow::Result<()> {
let root_package_dir = root_dir.join(format!("{}", package_info,));
if compilation_cache.failed_packages_v1.contains(&package_info) {
return Err(anyhow::Error::msg("compilation failed"));
return Err(anyhow::Error::msg(format!(
"compilation failed for the package:{} when using compiler v1",
package_info.package_name
)));
}
if compilation_cache.failed_packages_v2.contains(&package_info) {
return Err(anyhow::Error::msg(format!(
"compilation failed for the package:{} when using compiler v2",
package_info.package_name
)));
}
if !root_package_dir.exists() {
std::fs::create_dir_all(root_package_dir.as_path())?;
Expand Down Expand Up @@ -570,9 +583,14 @@ fn dump_and_compile_from_package_metadata(
.insert(package_info.clone(), built_package);
} else {
if !compilation_cache.failed_packages_v1.contains(&package_info) {
compilation_cache.failed_packages_v1.insert(package_info);
compilation_cache
.failed_packages_v1
.insert(package_info.clone());
}
return Err(anyhow::Error::msg("compilation failed at v1"));
return Err(anyhow::Error::msg(format!(
"compilation failed for the package:{} when using compiler v1",
package_info.package_name
)));
}
if execution_mode.is_some_and(|mode| mode.is_v2_or_compare()) {
let package_v2 =
Expand All @@ -584,10 +602,15 @@ fn dump_and_compile_from_package_metadata(
&mut compilation_cache.compiled_package_cache_v2,
);
} else {
if !compilation_cache.failed_packages_v1.contains(&package_info) {
compilation_cache.failed_packages_v1.insert(package_info);
if !compilation_cache.failed_packages_v2.contains(&package_info) {
compilation_cache
.failed_packages_v2
.insert(package_info.clone());
}
return Err(anyhow::Error::msg("compilation failed at v2"));
return Err(anyhow::Error::msg(format!(
"compilation failed for the package:{} when using compiler v2",
package_info.package_name
)));
}
}
}
Expand Down
29 changes: 25 additions & 4 deletions aptos-move/aptos-e2e-comparison-testing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

use anyhow::Result;
use aptos_comparison_testing::{
prepare_aptos_packages, DataCollection, Execution, ExecutionMode, OnlineExecutor, APTOS_COMMONS,
prepare_aptos_packages, DataCollection, Execution, ExecutionMode, OnlineExecutor,
APTOS_COMMONS, DISABLE_SPEC_CHECK,
};
use aptos_rest_client::Client;
use clap::{Parser, Subcommand};
use move_command_line_common::env::OVERRIDE_EXP_CACHE;
use move_compiler_v2::Experiment;
use move_core_types::account_address::AccountAddress;
use std::path::PathBuf;
use std::{env, path::PathBuf};
use url::Url;

const BATCH_SIZE: u64 = 500;
Expand Down Expand Up @@ -58,6 +61,9 @@ pub enum Cmd {
/// Used when execution_only is true
#[clap(long)]
execution_mode: Option<ExecutionMode>,
/// Packages to be skipped for reference safety check
#[clap(long)]
skip_ref_packages: Option<String>,
},
/// Execution of txns
Execute {
Expand All @@ -66,6 +72,9 @@ pub enum Cmd {
/// Whether to execute against V1, V2 alone or both compilers for comparison
#[clap(long)]
execution_mode: Option<ExecutionMode>,
/// Packages to be skipped for reference safety check
#[clap(long)]
skip_ref_packages: Option<String>,
},
}

Expand All @@ -86,7 +95,15 @@ pub struct Argument {
#[tokio::main]
async fn main() -> Result<()> {
let args = Argument::parse();

env::set_var(
OVERRIDE_EXP_CACHE,
format!(
"{},{}",
Experiment::SPEC_CHECK,
Experiment::REFERENCE_SAFETY
),
);
env::set_var("MOVE_COMPILER_EXP", DISABLE_SPEC_CHECK);
match args.cmd {
Cmd::Dump {
endpoint,
Expand Down Expand Up @@ -129,6 +146,7 @@ async fn main() -> Result<()> {
skip_failed_txns,
skip_publish_txns,
execution_mode,
skip_ref_packages,
} => {
let batch_size = BATCH_SIZE;
let output = if let Some(path) = output_path {
Expand All @@ -148,20 +166,23 @@ async fn main() -> Result<()> {
skip_publish_txns,
execution_mode.unwrap_or_default(),
endpoint,
skip_ref_packages,
)?;
online.execute(args.begin_version, args.limit).await?;
},
Cmd::Execute {
input_path,
execution_mode,
skip_ref_packages,
} => {
let input = if let Some(path) = input_path {
path
} else {
PathBuf::from(".")
};
prepare_aptos_packages(input.join(APTOS_COMMONS)).await;
let executor = Execution::new(input, execution_mode.unwrap_or_default());
let executor =
Execution::new(input, execution_mode.unwrap_or_default(), skip_ref_packages);
executor
.execute_txns(args.begin_version, args.limit)
.await?;
Expand Down
Loading

0 comments on commit 8d829ed

Please sign in to comment.