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,
move the execute_block_sharded method to the separate
ShardedVMExecutor trait.
  • Loading branch information
mzabaluev committed May 3, 2024
1 parent 838ed3b commit 6aa5f7e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
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"]
18 changes: 13 additions & 5 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ 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,
};
#[cfg(feature = "sharded")]
use crate::{
sharded_block_executor::{executor_client::ExecutorClient, ShardedBlockExecutor},
ShardedVMExecutor,
};
use anyhow::anyhow;
use aptos_block_executor::txn_commit_hook::NoOpTransactionCommitHook;
use aptos_crypto::HashValue;
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 @@ -2310,7 +2315,10 @@ impl VMExecutor for AptosVM {
}
ret
}
}

#[cfg(feature = "sharded")]
impl ShardedVMExecutor for AptosVM {
fn execute_block_sharded<S: StateView + Sync + Send + 'static, C: ExecutorClient<S>>(
sharded_block_executor: &ShardedBlockExecutor<S, C>,
transactions: PartitionedTransactions,
Expand Down
15 changes: 11 additions & 4 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 Down Expand Up @@ -173,7 +177,10 @@ pub trait VMExecutor: Send + Sync {
)
.map(BlockOutput::into_transaction_outputs_forced)
}
}

#[cfg(feature = "sharded")]
pub trait ShardedVMExecutor {
/// 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 6aa5f7e

Please sign in to comment.