diff --git a/aptos-move/aptos-debugger/src/aptos_debugger.rs b/aptos-move/aptos-debugger/src/aptos_debugger.rs index 9e9f93c62adf1..9b68c3de2772d 100644 --- a/aptos-move/aptos-debugger/src/aptos_debugger.rs +++ b/aptos-move/aptos-debugger/src/aptos_debugger.rs @@ -2,16 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, format_err, Result}; -use aptos_block_executor::{ - code_cache_global_manager::ModuleCacheManager, txn_commit_hook::NoOpTransactionCommitHook, -}; +use aptos_crypto::HashValue; use aptos_gas_profiling::{GasProfiler, TransactionGasLog}; use aptos_rest_client::Client; use aptos_types::{ account_address::AccountAddress, - block_executor::config::{ - BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig, - }, + block_executor::config::BlockExecutorConfigFromOnchain, contract_event::ContractEvent, state_store::TStateView, transaction::{ @@ -25,9 +21,7 @@ use aptos_validator_interface::{ AptosValidatorInterface, DBDebuggerInterface, DebuggerStateView, RestDebuggerInterface, }; use aptos_vm::{ - block_executor::{AptosTransactionOutput, BlockAptosVM}, - data_cache::AsMoveResolver, - AptosVM, + aptos_vm::AptosVMBlockExecutor, data_cache::AsMoveResolver, AptosVM, VMBlockExecutor, }; use aptos_vm_environment::environment::AptosEnvironment; use aptos_vm_logging::log_schema::AdapterLogSchema; @@ -56,10 +50,13 @@ impl AptosDebugger { pub fn execute_transactions_at_version( &self, + executor: &AptosVMBlockExecutor, version: Version, txns: Vec, repeat_execution_times: u64, concurrency_levels: &[usize], + parent: Option<&HashValue>, + current: Option, ) -> Result> { let sig_verified_txns: Vec = txns.into_iter().map(|x| x.into()).collect::>(); @@ -72,9 +69,16 @@ impl AptosDebugger { for concurrency_level in concurrency_levels { for i in 0..repeat_execution_times { let start_time = Instant::now(); - let cur_result = - execute_block_no_limit(&sig_verified_txns, &state_view, *concurrency_level) - .map_err(|err| format_err!("Unexpected VM Error: {:?}", err))?; + let cur_result = executor + .execute_block( + &sig_verified_txns, + &state_view, + BlockExecutorConfigFromOnchain::new_no_block_limit(), + parent, + current, + ) + .map(BlockOutput::into_transaction_outputs_forced) + .map_err(|err| format_err!("Unexpected VM Error: {:?}", err))?; println!( "[{} txns from {}] Finished execution round {}/{} with concurrency_level={} in {}ms", @@ -168,6 +172,17 @@ impl AptosDebugger { .get_committed_transactions(begin, limit) .await?; + // warm-up + self.execute_transactions_by_block( + begin, + txns.clone(), + repeat_execution_times, + concurrency_levels, + ) + .await?; + + println!("Starting real execution!"); + if use_same_block_boundaries { // when going block by block, no need to worry about epoch boundaries // as new epoch is always a new block. @@ -230,16 +245,20 @@ impl AptosDebugger { async fn execute_transactions_until_epoch_end( &self, + executor: &AptosVMBlockExecutor, begin: Version, txns: Vec, repeat_execution_times: u64, concurrency_levels: &[usize], ) -> Result> { let results = self.execute_transactions_at_version( + executor, begin, txns, repeat_execution_times, concurrency_levels, + None, + None, )?; let mut ret = vec![]; let mut is_reconfig = false; @@ -272,8 +291,10 @@ impl AptosDebugger { begin, limit ); + let executor = AptosVMBlockExecutor::new(); let mut epoch_result = self .execute_transactions_until_epoch_end( + &executor, begin, txns.clone(), repeat_execution_times, @@ -301,14 +322,20 @@ impl AptosDebugger { let mut ret = vec![]; let mut cur = vec![]; let mut cur_version = begin; + + let hash = HashValue::zero(); + let executor = AptosVMBlockExecutor::new(); for txn in txns { if txn.is_block_start() && !cur.is_empty() { let to_execute = std::mem::take(&mut cur); let results = self.execute_transactions_at_version( + &executor, cur_version, to_execute, repeat_execution_times, concurrency_levels, + Some(&hash), + Some(hash), )?; cur_version += results.len() as u64; ret.extend(results); @@ -317,10 +344,13 @@ impl AptosDebugger { } if !cur.is_empty() { let results = self.execute_transactions_at_version( + &executor, cur_version, cur, repeat_execution_times, concurrency_levels, + Some(&hash), + Some(hash), )?; ret.extend(results); } @@ -424,23 +454,3 @@ fn is_reconfiguration(vm_output: &TransactionOutput) -> bool { .iter() .any(ContractEvent::is_new_epoch_event) } - -fn execute_block_no_limit( - sig_verified_txns: &[SignatureVerifiedTransaction], - state_view: &DebuggerStateView, - concurrency_level: usize, -) -> Result, VMStatus> { - BlockAptosVM::execute_block::<_, NoOpTransactionCommitHook>( - sig_verified_txns, - state_view, - &ModuleCacheManager::new(), - BlockExecutorConfig { - local: BlockExecutorLocalConfig::default_with_concurrency_level(concurrency_level), - onchain: BlockExecutorConfigFromOnchain::new_no_block_limit(), - }, - None, - None, - None, - ) - .map(BlockOutput::into_transaction_outputs_forced) -} diff --git a/aptos-move/aptos-debugger/src/execute_pending_block.rs b/aptos-move/aptos-debugger/src/execute_pending_block.rs index 7235dff6e9b01..b85f3382c3c2f 100644 --- a/aptos-move/aptos-debugger/src/execute_pending_block.rs +++ b/aptos-move/aptos-debugger/src/execute_pending_block.rs @@ -6,6 +6,7 @@ use anyhow::Result; use aptos_crypto::HashValue; use aptos_logger::info; use aptos_rest_client::Client; +use aptos_vm::{aptos_vm::AptosVMBlockExecutor, VMBlockExecutor}; use clap::Parser; use std::path::PathBuf; use url::Url; @@ -84,11 +85,15 @@ impl Command { user_txns }; + let executor = AptosVMBlockExecutor::new(); let txn_outputs = debugger.execute_transactions_at_version( + &executor, self.begin_version, block, self.repeat_execution_times.unwrap_or(1), &self.opts.concurrency_level, + None, + None, )?; println!("{txn_outputs:#?}"); diff --git a/aptos-move/aptos-vm/src/aptos_vm.rs b/aptos-move/aptos-vm/src/aptos_vm.rs index d50b5c5371047..03fb371b1601e 100644 --- a/aptos-move/aptos-vm/src/aptos_vm.rs +++ b/aptos-move/aptos-vm/src/aptos_vm.rs @@ -126,6 +126,7 @@ use std::{ cmp::{max, min}, collections::{BTreeMap, BTreeSet}, marker::Sync, + str::FromStr, sync::Arc, }; @@ -2815,6 +2816,9 @@ impl VMBlockExecutor for AptosVMBlockExecutor { ); let count = transactions.len(); + let concurrency_level = + usize::from_str(&std::env::var("CONCURRENCY_LEVEL").unwrap()).unwrap(); + let ret = BlockAptosVM::execute_block::< _, NoOpTransactionCommitHook, @@ -2824,7 +2828,7 @@ impl VMBlockExecutor for AptosVMBlockExecutor { &self.module_cache_manager, BlockExecutorConfig { local: BlockExecutorLocalConfig { - concurrency_level: AptosVM::get_concurrency_level(), + concurrency_level, allow_fallback: true, discard_failed_blocks: AptosVM::get_discard_failed_blocks(), module_cache_config: BlockExecutorModuleCacheLocalConfig::default(),