Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brian/exec window forge #15506

Draft
wants to merge 20 commits into
base: brian/exec-window-exec-optimize-3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

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

9 changes: 4 additions & 5 deletions aptos-move/aptos-debugger/src/aptos_debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

use anyhow::{bail, format_err, Result};
use aptos_block_executor::{
code_cache_global_manager::AptosModuleCacheManager,
txn_commit_hook::NoOpTransactionCommitHook,
txn_provider::{default::DefaultTxnProvider, TxnProvider},
code_cache_global_manager::AptosModuleCacheManager, txn_commit_hook::NoOpTransactionCommitHook,
};
use aptos_gas_profiling::{GasProfiler, TransactionGasLog};
use aptos_rest_client::Client;
Expand All @@ -22,6 +20,7 @@ use aptos_types::{
SignedTransaction, Transaction, TransactionInfo, TransactionOutput, TransactionPayload,
Version,
},
txn_provider::{default::DefaultTxnProvider, TxnProvider},
vm_status::VMStatus,
};
use aptos_validator_interface::{
Expand Down Expand Up @@ -430,14 +429,14 @@ fn is_reconfiguration(vm_output: &TransactionOutput) -> bool {
}

fn execute_block_no_limit(
txn_provider: &DefaultTxnProvider<SignatureVerifiedTransaction>,
txn_provider: &dyn TxnProvider<SignatureVerifiedTransaction>,
state_view: &DebuggerStateView,
concurrency_level: usize,
) -> Result<Vec<TransactionOutput>, VMStatus> {
BlockAptosVM::execute_block::<
_,
NoOpTransactionCommitHook<AptosTransactionOutput, VMStatus>,
DefaultTxnProvider<SignatureVerifiedTransaction>,
dyn TxnProvider<SignatureVerifiedTransaction>,
>(
txn_provider,
state_view,
Expand Down
1 change: 0 additions & 1 deletion aptos-move/aptos-e2e-comparison-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ default-run = "aptos-comparison-testing"

[dependencies]
anyhow = { workspace = true }
aptos-block-executor = { workspace = true }
aptos-framework = { workspace = true }
aptos-language-e2e-tests = { workspace = true }
aptos-rest-client = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
CompilationCache, DataManager, IndexWriter, PackageInfo, TxnIndex,
};
use anyhow::{format_err, Result};
use aptos_block_executor::txn_provider::default::DefaultTxnProvider;
use aptos_framework::natives::code::PackageMetadata;
use aptos_rest_client::Client;
use aptos_types::{
Expand All @@ -15,6 +14,7 @@ use aptos_types::{
signature_verified_transaction::SignatureVerifiedTransaction, Transaction,
TransactionOutput, Version,
},
txn_provider::default::DefaultTxnProvider,
write_set::TOTAL_SUPPLY_STATE_KEY,
};
use aptos_validator_interface::{AptosValidatorInterface, FilterCondition, RestDebuggerInterface};
Expand Down
37 changes: 31 additions & 6 deletions aptos-move/aptos-gas-meter/src/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::traits::GasAlgebra;
use aptos_gas_algebra::{Fee, FeePerGasUnit, Gas, GasExpression, NumBytes, NumModules, Octa};
use aptos_gas_schedule::{gas_feature_versions, VMGasParameters};
use aptos_logger::error;
use aptos_vm_types::storage::{
io_pricing::IoPricing, space_pricing::DiskSpacePricing, StorageGasParameters,
use aptos_vm_types::{
resolver::BlockSynchronizationView,
storage::{io_pricing::IoPricing, space_pricing::DiskSpacePricing, StorageGasParameters},
};
use move_binary_format::errors::{PartialVMError, PartialVMResult};
use move_core_types::{
Expand All @@ -18,7 +19,7 @@ use std::fmt::Debug;
/// Base gas algebra implementation that tracks the gas usage using its internal counters.
///
/// Abstract gas amounts are always evaluated to concrete values at the spot.
pub struct StandardGasAlgebra {
pub struct StandardGasAlgebra<'a> {
feature_version: u64,
vm_gas_params: VMGasParameters,
storage_gas_params: StorageGasParameters,
Expand All @@ -40,15 +41,18 @@ pub struct StandardGasAlgebra {

num_dependencies: NumModules,
total_dependency_size: NumBytes,

maybe_block_synchronization_view: Option<&'a dyn BlockSynchronizationView>,
}

impl StandardGasAlgebra {
impl<'a> StandardGasAlgebra<'a> {
pub fn new(
gas_feature_version: u64,
vm_gas_params: VMGasParameters,
storage_gas_params: StorageGasParameters,
is_approved_gov_script: bool,
balance: impl Into<Gas>,
maybe_block_synchronization_view: Option<&'a dyn BlockSynchronizationView>,
) -> Self {
let balance = balance.into().to_unit_with_params(&vm_gas_params.txn);

Expand Down Expand Up @@ -83,11 +87,12 @@ impl StandardGasAlgebra {
storage_fee_used: 0.into(),
num_dependencies: 0.into(),
total_dependency_size: 0.into(),
maybe_block_synchronization_view,
}
}
}

impl StandardGasAlgebra {
impl StandardGasAlgebra<'_> {
fn charge(&mut self, amount: InternalGas) -> (InternalGas, PartialVMResult<()>) {
match self.balance.checked_sub(amount) {
Some(new_balance) => {
Expand All @@ -106,7 +111,7 @@ impl StandardGasAlgebra {
}
}

impl GasAlgebra for StandardGasAlgebra {
impl GasAlgebra for StandardGasAlgebra<'_> {
fn feature_version(&self) -> u64 {
self.feature_version
}
Expand Down Expand Up @@ -165,6 +170,16 @@ impl GasAlgebra for StandardGasAlgebra {
&mut self,
abstract_amount: impl GasExpression<VMGasParameters, Unit = InternalGasUnit> + Debug,
) -> PartialVMResult<()> {
if self
.maybe_block_synchronization_view
.is_some_and(|view| view.early_abort_execution())
{
return Err(
PartialVMError::new(StatusCode::SPECULATIVE_EXECUTION_ABORT_ERROR)
.with_message("Interrupted from block synchronization view".to_string()),
);
}

let amount = abstract_amount.evaluate(self.feature_version, &self.vm_gas_params);

let (actual, res) = self.charge(amount);
Expand All @@ -187,6 +202,16 @@ impl GasAlgebra for StandardGasAlgebra {
&mut self,
abstract_amount: impl GasExpression<VMGasParameters, Unit = InternalGasUnit>,
) -> PartialVMResult<()> {
if self
.maybe_block_synchronization_view
.is_some_and(|view| view.early_abort_execution())
{
return Err(
PartialVMError::new(StatusCode::SPECULATIVE_EXECUTION_ABORT_ERROR)
.with_message("Interrupted from block synchronization view".to_string()),
);
}

let amount = abstract_amount.evaluate(self.feature_version, &self.vm_gas_params);

let (actual, res) = self.charge(amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
use crate::transactions;
use aptos_bitvec::BitVec;
use aptos_block_executor::{
code_cache_global_manager::AptosModuleCacheManager,
txn_commit_hook::NoOpTransactionCommitHook,
txn_provider::{default::DefaultTxnProvider, TxnProvider},
code_cache_global_manager::AptosModuleCacheManager, txn_commit_hook::NoOpTransactionCommitHook,
};
use aptos_block_partitioner::{
v2::config::PartitionerV2Config, BlockPartitioner, PartitionerConfig,
Expand All @@ -32,6 +30,7 @@ use aptos_types::{
},
ExecutionStatus, Transaction, TransactionOutput, TransactionStatus,
},
txn_provider::{default::DefaultTxnProvider, TxnProvider},
vm_status::VMStatus,
};
use aptos_vm::{
Expand Down Expand Up @@ -220,7 +219,7 @@ where
let output = BlockAptosVM::execute_block::<
_,
NoOpTransactionCommitHook<AptosTransactionOutput, VMStatus>,
DefaultTxnProvider<SignatureVerifiedTransaction>,
dyn TxnProvider<SignatureVerifiedTransaction>,
>(
txn_provider,
self.state_view.as_ref(),
Expand Down Expand Up @@ -271,7 +270,7 @@ where
let output = BlockAptosVM::execute_block::<
_,
NoOpTransactionCommitHook<AptosTransactionOutput, VMStatus>,
DefaultTxnProvider<SignatureVerifiedTransaction>,
dyn TxnProvider<SignatureVerifiedTransaction>,
>(
txn_provider,
self.state_view.as_ref(),
Expand Down
1 change: 0 additions & 1 deletion aptos-move/aptos-transactional-test-harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ rust-version = { workspace = true }
[dependencies]
anyhow = { workspace = true }
aptos-api-types = { workspace = true }
aptos-block-executor = { workspace = true }
aptos-cached-packages = { workspace = true }
aptos-crypto = { workspace = true }
aptos-framework = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use anyhow::{bail, format_err, Result};
use aptos_api_types::AsConverter;
use aptos_block_executor::txn_provider::default::DefaultTxnProvider;
use aptos_crypto::{
ed25519::{Ed25519PrivateKey, Ed25519PublicKey},
hash::HashValue,
Expand All @@ -15,15 +14,20 @@ use aptos_language_e2e_tests::data_store::{FakeDataStore, GENESIS_CHANGE_SET_HEA
use aptos_resource_viewer::{AnnotatedMoveValue, AptosValueAnnotator};
use aptos_types::{
account_config::{aptos_test_root_address, AccountResource, CoinStoreResource},
block_executor::{
config::BlockExecutorConfigFromOnchain, execution_state::TransactionSliceMetadata,
},
block_metadata::BlockMetadata,
chain_id::ChainId,
contract_event::ContractEvent,
on_chain_config::BlockGasLimitType,
state_store::{state_key::StateKey, table::TableHandle, TStateView},
transaction::{
signature_verified_transaction::into_signature_verified_block,
EntryFunction as TransactionEntryFunction, ExecutionStatus, RawTransaction,
Script as TransactionScript, Transaction, TransactionOutput, TransactionStatus,
},
txn_provider::default::DefaultTxnProvider,
AptosCoinType,
};
use aptos_vm::{aptos_vm::AptosVMBlockExecutor, VMBlockExecutor};
Expand Down Expand Up @@ -517,8 +521,19 @@ impl<'a> AptosTestAdapter<'a> {
let txn_block = vec![txn];
let sig_verified_block = into_signature_verified_block(txn_block);
let txn_provider = DefaultTxnProvider::new(sig_verified_block);
let mut outputs = AptosVMBlockExecutor::new()
.execute_block_no_limit(&txn_provider, &self.storage.clone())?;
let onchain_config = BlockExecutorConfigFromOnchain::new(
// TODO fetch values from state?
// Or should we just use execute_block_no_limit ?
BlockGasLimitType::Limit(30000),
);
let (mut outputs, _) = AptosVMBlockExecutor::new()
.execute_block(
&txn_provider,
&self.storage.clone(),
onchain_config,
TransactionSliceMetadata::unknown(),
)?
.into_inner();

assert_eq!(outputs.len(), 1);

Expand Down
3 changes: 1 addition & 2 deletions aptos-move/aptos-vm-profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ glob = { workspace = true }
once_cell = { workspace = true }
smallvec = { workspace = true }

aptos-block-executor = { workspace = true }
aptos-cached-packages = { workspace = true }
aptos-gas-schedule = { workspace = true }
aptos-language-e2e-tests = { workspace = true }
Expand All @@ -36,7 +35,7 @@ move-vm-types = { workspace = true }

[[bin]]
name = "main"
path = "src/main.rs"
path = "src/main.rs"

[[bin]]
name = "run-move"
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm-profiling/src/bins/run_aptos_p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use aptos_block_executor::txn_provider::default::DefaultTxnProvider;
use aptos_language_e2e_tests::{account::AccountData, data_store::FakeDataStore};
use aptos_types::{
transaction::{signature_verified_transaction::SignatureVerifiedTransaction, Transaction},
txn_provider::default::DefaultTxnProvider,
write_set::WriteSet,
};
use aptos_vm::{aptos_vm::AptosVMBlockExecutor, VMBlockExecutor};
Expand Down
24 changes: 22 additions & 2 deletions aptos-move/aptos-vm-types/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ use move_core_types::{language_storage::StructTag, value::MoveTypeLayout, vm_sta
use move_vm_types::delayed_values::delayed_field_id::DelayedFieldID;
use std::collections::{BTreeMap, HashMap};

/// Gives a global (from an executing txn perspective) view into the synchronization aspects of the
/// encompassing block execution. The goal is to improve the efficiency of overall block execution.
/// For example, if the block execution has halted due to gas limit (committing only a prefix),
/// ongoing speculative executions can return early. Similarly, if a read-write dependency is
/// preficted between txns, it can allow the dependent txn to wait and avoid costly re-executions.
pub trait BlockSynchronizationView {
fn early_abort_execution(&self) -> bool;
}

/// Allows to query resources from the state.
pub trait TResourceView {
type Key;
Expand Down Expand Up @@ -204,7 +213,8 @@ pub trait StateStorageView {
/// resolve AggregatorV2 via the state-view based default implementation, as it
/// doesn't provide a value exchange functionality).
pub trait TExecutorView<K, T, L, I, V>:
TResourceView<Key = K, Layout = L>
BlockSynchronizationView
+ TResourceView<Key = K, Layout = L>
+ TModuleView<Key = K>
+ TAggregatorV1View<Identifier = K>
+ TDelayedFieldView<Identifier = I, ResourceKey = K, ResourceGroupTag = T>
Expand All @@ -213,7 +223,8 @@ pub trait TExecutorView<K, T, L, I, V>:
}

impl<A, K, T, L, I, V> TExecutorView<K, T, L, I, V> for A where
A: TResourceView<Key = K, Layout = L>
A: BlockSynchronizationView
+ TResourceView<Key = K, Layout = L>
+ TModuleView<Key = K>
+ TAggregatorV1View<Identifier = K>
+ TDelayedFieldView<Identifier = I, ResourceKey = K, ResourceGroupTag = T>
Expand Down Expand Up @@ -299,6 +310,15 @@ where
}
}

impl<S> BlockSynchronizationView for S
where
S: StateView,
{
fn early_abort_execution(&self) -> bool {
false
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ResourceGroupSize {
Concrete(u64),
Expand Down
Loading
Loading