Skip to content

Commit

Permalink
aptos-vm: feature gate for sharded execution
Browse files Browse the repository at this point in the history
Put sharded block execution code and its associated rayon dependency
behind the "sharded" feature.
To avoid conditionally defined methods in the VMExecutor trait,
factor out the SerialVMExecutor trait that is a supertrait of
VMExecutor, gate VMExecutor with the "sharded" feature, and move the
non-sharded methods to the unconditional supertrait.
  • Loading branch information
mzabaluev committed May 7, 2024
1 parent 838ed3b commit c11a9a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use aptos_types::{
Script as TransactionScript, Transaction, TransactionOutput, TransactionStatus,
},
};
use aptos_vm::{data_cache::AsMoveResolver, AptosVM, VMExecutor};
use aptos_vm::{data_cache::AsMoveResolver, AptosVM, SerialVMExecutor};
use aptos_vm_genesis::GENESIS_KEYPAIR;
use clap::Parser;
use move_binary_format::file_format::{CompiledModule, CompiledScript};
Expand Down
5 changes: 3 additions & 2 deletions aptos-move/aptos-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ num_cpus = { workspace = true }
once_cell = { workspace = true }
ouroboros = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
rayon = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
smallvec = { workspace = true }
Expand All @@ -74,7 +74,8 @@ proptest = { workspace = true }
rand_core = { workspace = true }

[features]
default = []
default = ["sharded"]
sharded = ["rayon"]
fuzzing = ["move-core-types/fuzzing", "move-binary-format/fuzzing", "move-vm-types/fuzzing", "aptos-framework/fuzzing", "aptos-types/fuzzing"]
failpoints = ["fail/failpoints", "move-vm-runtime/failpoints"]
testing = ["move-unit-test", "aptos-framework/testing"]
22 changes: 15 additions & 7 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ use crate::{
},
AptosMoveResolver, MoveVmExt, SessionExt, SessionId,
},
sharded_block_executor::{executor_client::ExecutorClient, ShardedBlockExecutor},
system_module_names::*,
transaction_metadata::TransactionMetadata,
transaction_validation, verifier,
verifier::randomness::has_randomness_attribute,
VMExecutor, VMValidator,
SerialVMExecutor, VMValidator,
};
#[cfg(feature = "sharded")]
use crate::{
sharded_block_executor::{executor_client::ExecutorClient, ShardedBlockExecutor},
VMExecutor,
};
use anyhow::anyhow;
use aptos_block_executor::txn_commit_hook::NoOpTransactionCommitHook;
Expand All @@ -42,9 +46,8 @@ use aptos_types::state_store::StateViewId;
use aptos_types::{
account_config,
account_config::{new_block_event_key, AccountResource},
block_executor::{
config::{BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig},
partitioner::PartitionedTransactions,
block_executor::config::{
BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig,
},
block_metadata::BlockMetadata,
block_metadata_ext::{BlockMetadataExt, BlockMetadataWithRandomness},
Expand All @@ -56,7 +59,7 @@ use aptos_types::{
TimedFeatureOverride, TimedFeatures, TimedFeaturesBuilder,
},
randomness::Randomness,
state_store::{StateView, TStateView},
state_store::StateView,
transaction::{
authenticator::AnySignature, signature_verified_transaction::SignatureVerifiedTransaction,
BlockOutput, EntryFunction, ExecutionError, ExecutionStatus, ModuleBundle, Multisig,
Expand All @@ -66,6 +69,8 @@ use aptos_types::{
},
vm_status::{AbortLocation, StatusCode, VMStatus},
};
#[cfg(feature = "sharded")]
use aptos_types::{block_executor::partitioner::PartitionedTransactions, state_store::TStateView};
use aptos_utils::{aptos_try, return_on_failure};
use aptos_vm_logging::{log_schema::AdapterLogSchema, speculative_error, speculative_log};
use aptos_vm_types::{
Expand Down Expand Up @@ -2263,7 +2268,7 @@ impl AptosVM {
}

// Executor external API
impl VMExecutor for AptosVM {
impl SerialVMExecutor for AptosVM {
/// Execute a block of `transactions`. The output vector will have the exact same length as the
/// input vector. The discarded transactions will be marked as `TransactionStatus::Discard` and
/// have an empty `WriteSet`. Also `state_view` is immutable, and does not have interior
Expand Down Expand Up @@ -2310,7 +2315,10 @@ impl VMExecutor for AptosVM {
}
ret
}
}

#[cfg(feature = "sharded")]
impl VMExecutor for AptosVM {
fn execute_block_sharded<S: StateView + Sync + Send + 'static, C: ExecutorClient<S>>(
sharded_block_executor: &ShardedBlockExecutor<S, C>,
transactions: PartitionedTransactions,
Expand Down
21 changes: 15 additions & 6 deletions aptos-move/aptos-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub mod gas;
mod keyless_validation;
pub mod move_vm_ext;
pub mod natives;
#[cfg(feature = "sharded")]
pub mod sharded_block_executor;
pub mod system_module_names;
pub mod testing;
Expand All @@ -121,19 +122,22 @@ pub mod validator_txns;
pub mod verifier;

pub use crate::aptos_vm::{AptosSimulationVM, AptosVM};
#[cfg(feature = "sharded")]
use crate::sharded_block_executor::{executor_client::ExecutorClient, ShardedBlockExecutor};
#[cfg(feature = "sharded")]
use aptos_types::block_executor::partitioner::PartitionedTransactions;
use aptos_types::{
block_executor::{
config::BlockExecutorConfigFromOnchain, partitioner::PartitionedTransactions,
},
block_executor::config::BlockExecutorConfigFromOnchain,
state_store::StateView,
transaction::{
signature_verified_transaction::SignatureVerifiedTransaction, BlockOutput,
SignedTransaction, TransactionOutput, VMValidatorResult,
},
vm_status::VMStatus,
};
use std::{marker::Sync, sync::Arc};
use std::marker::Sync;
#[cfg(feature = "sharded")]
use std::sync::Arc;
pub use verifier::view_function::determine_is_view;

/// This trait describes the VM's validation interfaces.
Expand All @@ -146,8 +150,9 @@ pub trait VMValidator {
) -> VMValidatorResult;
}

/// This trait describes the VM's execution interface.
pub trait VMExecutor: Send + Sync {
/// This trait describes the VM's execution interface, without the sharded
/// execution method which is only available when the `sharded` feature is enabled.
pub trait SerialVMExecutor: Send + Sync {
// NOTE: At the moment there are no persistent caches that live past the end of a block (that's
// why execute_block doesn't take &self.)
// There are some cache invalidation issues around transactions publishing code that need to be
Expand All @@ -173,7 +178,11 @@ pub trait VMExecutor: Send + Sync {
)
.map(BlockOutput::into_transaction_outputs_forced)
}
}

/// This trait augments `SerialVMExecutor` with sharded execution capabilities.
#[cfg(feature = "sharded")]
pub trait VMExecutor: SerialVMExecutor {
/// Executes a block of transactions using a sharded block executor and returns the results.
fn execute_block_sharded<S: StateView + Sync + Send + 'static, E: ExecutorClient<S>>(
sharded_block_executor: &ShardedBlockExecutor<S, E>,
Expand Down

0 comments on commit c11a9a2

Please sign in to comment.