diff --git a/Cargo.lock b/Cargo.lock index 509cf4daf2c5a7..46555435c51194 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4340,7 +4340,6 @@ dependencies = [ "aptos-crypto", "aptos-crypto-derive", "aptos-dkg", - "aptos-experimental-runtimes", "aptos-infallible", "aptos-proptest-helpers", "arbitrary", @@ -4352,7 +4351,6 @@ dependencies = [ "ark-relations", "ark-serialize", "ark-std", - "arr_macro", "async-trait", "base64 0.13.1", "bcs 0.1.4", diff --git a/api/src/context.rs b/api/src/context.rs index 1a77f5d5ee1f48..e1c6095d193076 100644 --- a/api/src/context.rs +++ b/api/src/context.rs @@ -22,7 +22,9 @@ use aptos_gas_schedule::{AptosGasParameters, FromOnChainGasSchedule}; use aptos_logger::{error, info, Schema}; use aptos_mempool::{MempoolClientRequest, MempoolClientSender, SubmissionStatus}; use aptos_storage_interface::{ - state_view::{DbStateView, DbStateViewAtVersion, LatestDbStateCheckpointView}, + state_store::state_view::db_state_view::{ + DbStateView, DbStateViewAtVersion, LatestDbStateCheckpointView, + }, AptosDbError, DbReader, Order, MAX_REQUEST_LIMIT, }; use aptos_types::{ diff --git a/api/test-context/src/test_context.rs b/api/test-context/src/test_context.rs index e8f36acdf997f3..99ff148314c0ce 100644 --- a/api/test-context/src/test_context.rs +++ b/api/test-context/src/test_context.rs @@ -31,7 +31,9 @@ use aptos_sdk::{ transaction::SignedTransaction, AccountKey, LocalAccount, }, }; -use aptos_storage_interface::{state_view::DbStateView, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::DbStateView, DbReaderWriter, +}; use aptos_temppath::TempPath; use aptos_types::{ account_address::{create_multisig_account_address, AccountAddress}, diff --git a/aptos-move/aptos-e2e-comparison-testing/src/data_state_view.rs b/aptos-move/aptos-e2e-comparison-testing/src/data_state_view.rs index be1938618686f2..47a5a2de72b93f 100644 --- a/aptos-move/aptos-e2e-comparison-testing/src/data_state_view.rs +++ b/aptos-move/aptos-e2e-comparison-testing/src/data_state_view.rs @@ -5,7 +5,7 @@ use aptos_language_e2e_tests::data_store::FakeDataStore; use aptos_types::{ state_store::{ state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, - Result as StateViewResult, TStateView, + StateViewResult, TStateView, }, transaction::Version, }; diff --git a/aptos-move/aptos-release-builder/src/simulate.rs b/aptos-move/aptos-release-builder/src/simulate.rs index 76456c74801c97..a20a8699ca2607 100644 --- a/aptos-move/aptos-release-builder/src/simulate.rs +++ b/aptos-move/aptos-release-builder/src/simulate.rs @@ -36,9 +36,8 @@ use aptos_types::{ account_config::ChainIdResource, on_chain_config::{ApprovedExecutionHashes, Features, GasScheduleV2, OnChainConfig}, state_store::{ - in_memory_state_view::InMemoryStateView, state_key::StateKey, - state_storage_usage::StateStorageUsage, state_value::StateValue, - Result as StateStoreResult, StateView, TStateView, + state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, + StateView, StateViewResult as StateStoreResult, TStateView, }, transaction::{ExecutionStatus, Script, TransactionArgument, TransactionStatus}, write_set::{TransactionWrite, WriteSet}, @@ -306,10 +305,6 @@ where fn get_usage(&self) -> StateStoreResult { Ok(StateStorageUsage::Untracked) } - - fn as_in_memory_state_view(&self) -> InMemoryStateView { - panic!("not supported") - } } /*************************************************************************************************** diff --git a/aptos-move/aptos-validator-interface/src/lib.rs b/aptos-move/aptos-validator-interface/src/lib.rs index 9414fb2298476b..ba700ab1a4c36c 100644 --- a/aptos-move/aptos-validator-interface/src/lib.rs +++ b/aptos-move/aptos-validator-interface/src/lib.rs @@ -12,7 +12,7 @@ use aptos_types::{ account_address::AccountAddress, state_store::{ state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, - Result as StateViewResult, StateViewId, TStateView, + StateViewId, StateViewResult, TStateView, }, transaction::{Transaction, TransactionInfo, Version}, }; diff --git a/aptos-move/aptos-vm-types/src/resolver.rs b/aptos-move/aptos-vm-types/src/resolver.rs index e71673588eace0..99e72df4c8140f 100644 --- a/aptos-move/aptos-vm-types/src/resolver.rs +++ b/aptos-move/aptos-vm-types/src/resolver.rs @@ -5,7 +5,7 @@ use aptos_aggregator::resolver::{TAggregatorV1View, TDelayedFieldView}; use aptos_types::{ serde_helper::bcs_utils::size_u32_as_uleb128, state_store::{ - errors::StateviewError, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::{StateValue, StateValueMetadata}, @@ -181,9 +181,9 @@ pub trait StateStorageView { fn id(&self) -> StateViewId; /// Reads the state value from the DB. Used to enforce read-before-write for module writes. - fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateviewError>; + fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateViewError>; - fn get_usage(&self) -> Result; + fn get_usage(&self) -> Result; } /// A fine-grained view of the state during execution. @@ -289,12 +289,12 @@ where self.id() } - fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateviewError> { + fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateViewError> { self.get_state_value(state_key)?; Ok(()) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { self.get_usage().map_err(Into::into) } } diff --git a/aptos-move/aptos-vm-types/src/resource_group_adapter.rs b/aptos-move/aptos-vm-types/src/resource_group_adapter.rs index 87293388dca286..2c2109d4b2fc53 100644 --- a/aptos-move/aptos-vm-types/src/resource_group_adapter.rs +++ b/aptos-move/aptos-vm-types/src/resource_group_adapter.rs @@ -377,7 +377,7 @@ mod tests { use super::*; use crate::tests::utils::{mock_tag_0, mock_tag_1, mock_tag_2}; use aptos_types::state_store::{ - errors::StateviewError, state_storage_usage::StateStorageUsage, state_value::StateValue, + errors::StateViewError, state_storage_usage::StateStorageUsage, state_value::StateValue, TStateView, }; use claims::{assert_gt, assert_none, assert_ok_eq, assert_some, assert_some_eq}; @@ -443,14 +443,14 @@ mod tests { fn get_state_value( &self, state_key: &Self::Key, - ) -> Result, StateviewError> { + ) -> Result, StateViewError> { Ok(self .group .get(state_key) .map(|entry| StateValue::new_legacy(entry.blob.clone().into()))) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { unimplemented!(); } } diff --git a/aptos-move/aptos-vm/src/data_cache.rs b/aptos-move/aptos-vm/src/data_cache.rs index d2ae08b06194d2..11da1abc1a9eed 100644 --- a/aptos-move/aptos-vm/src/data_cache.rs +++ b/aptos-move/aptos-vm/src/data_cache.rs @@ -17,7 +17,7 @@ use aptos_types::{ error::{PanicError, PanicOr}, on_chain_config::{ConfigStorage, Features, OnChainConfig}, state_store::{ - errors::StateviewError, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::{StateValue, StateValueMetadata}, @@ -318,11 +318,11 @@ impl<'e, E: ExecutorView> StateStorageView for StorageAdapter<'e, E> { self.executor_view.id() } - fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateviewError> { + fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateViewError> { self.executor_view.read_state_value(state_key) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { self.executor_view.get_usage() } } diff --git a/aptos-move/aptos-vm/src/move_vm_ext/session/view_with_change_set.rs b/aptos-move/aptos-vm/src/move_vm_ext/session/view_with_change_set.rs index e1ccb6f506d911..a6309ce35af704 100644 --- a/aptos-move/aptos-vm/src/move_vm_ext/session/view_with_change_set.rs +++ b/aptos-move/aptos-vm/src/move_vm_ext/session/view_with_change_set.rs @@ -11,7 +11,7 @@ use aptos_aggregator::{ use aptos_types::{ error::{code_invariant_error, expect_ok, PanicError, PanicOr}, state_store::{ - errors::StateviewError, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::{StateValue, StateValueMetadata}, @@ -324,12 +324,12 @@ impl<'r> StateStorageView for ExecutorViewWithChangeSet<'r> { self.base_executor_view.id() } - fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateviewError> { + fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateViewError> { self.base_executor_view.read_state_value(state_key) } - fn get_usage(&self) -> Result { - Err(StateviewError::Other( + fn get_usage(&self) -> Result { + Err(StateViewError::Other( "Unexpected access to get_usage()".to_string(), )) } diff --git a/aptos-move/aptos-vm/src/sharded_block_executor/aggr_overridden_state_view.rs b/aptos-move/aptos-vm/src/sharded_block_executor/aggr_overridden_state_view.rs index 7872c1495d51b2..6676421d4294c0 100644 --- a/aptos-move/aptos-vm/src/sharded_block_executor/aggr_overridden_state_view.rs +++ b/aptos-move/aptos-vm/src/sharded_block_executor/aggr_overridden_state_view.rs @@ -3,13 +3,13 @@ use aptos_types::{ state_store::{ - errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, StateView, TStateView, }, write_set::TOTAL_SUPPLY_STATE_KEY, }; -type Result = std::result::Result; +type Result = std::result::Result; pub const TOTAL_SUPPLY_AGGR_BASE_VAL: u128 = u128::MAX >> 1; #[derive(Clone)] diff --git a/aptos-move/aptos-vm/src/sharded_block_executor/cross_shard_state_view.rs b/aptos-move/aptos-vm/src/sharded_block_executor/cross_shard_state_view.rs index dfc7e6342641aa..2381d6ea63057b 100644 --- a/aptos-move/aptos-vm/src/sharded_block_executor/cross_shard_state_view.rs +++ b/aptos-move/aptos-vm/src/sharded_block_executor/cross_shard_state_view.rs @@ -6,7 +6,7 @@ use aptos_logger::trace; use aptos_types::{ block_executor::partitioner::TransactionWithDependencies, state_store::{ - errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, StateView, TStateView, }, transaction::analyzed_transaction::AnalyzedTransaction, @@ -74,14 +74,14 @@ impl<'a, S: StateView + Sync + Send> CrossShardStateView<'a, S> { impl<'a, S: StateView + Sync + Send> TStateView for CrossShardStateView<'a, S> { type Key = StateKey; - fn get_state_value(&self, state_key: &StateKey) -> Result, StateviewError> { + fn get_state_value(&self, state_key: &StateKey) -> Result, StateViewError> { if let Some(value) = self.cross_shard_data.get(state_key) { return Ok(value.get_value()); } self.base_view.get_state_value(state_key) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { Ok(StateStorageUsage::new_untracked()) } } @@ -90,19 +90,27 @@ impl<'a, S: StateView + Sync + Send> TStateView for CrossShardStateView<'a, S> { mod tests { use crate::sharded_block_executor::cross_shard_state_view::CrossShardStateView; use aptos_types::state_store::{ - in_memory_state_view::InMemoryStateView, state_key::StateKey, state_value::StateValue, - TStateView, - }; - use once_cell::sync::Lazy; - use std::{ - collections::{HashMap, HashSet}, - sync::Arc, - thread, - time::Duration, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + state_value::StateValue, TStateView, }; + use std::{collections::HashSet, sync::Arc, thread, time::Duration}; + + struct EmptyView; - pub static EMPTY_VIEW: Lazy> = - Lazy::new(|| Arc::new(InMemoryStateView::new(HashMap::new()))); + impl TStateView for EmptyView { + type Key = StateKey; + + fn get_state_value( + &self, + _state_key: &StateKey, + ) -> Result, StateViewError> { + Ok(None) + } + + fn get_usage(&self) -> Result { + unreachable!() + } + } #[test] fn test_cross_shard_state_view_get_state_value() { @@ -114,7 +122,7 @@ mod tests { let mut state_keys = HashSet::new(); state_keys.insert(state_key.clone()); - let cross_shard_state_view = Arc::new(CrossShardStateView::new(state_keys, &EMPTY_VIEW)); + let cross_shard_state_view = Arc::new(CrossShardStateView::new(state_keys, &EmptyView)); let cross_shard_state_view_clone = cross_shard_state_view.clone(); let wait_thread = thread::spawn(move || { diff --git a/aptos-move/block-executor/src/proptest_types/types.rs b/aptos-move/block-executor/src/proptest_types/types.rs index ec416785fd80aa..d594f134c28291 100644 --- a/aptos-move/block-executor/src/proptest_types/types.rs +++ b/aptos-move/block-executor/src/proptest_types/types.rs @@ -17,7 +17,7 @@ use aptos_types::{ fee_statement::FeeStatement, on_chain_config::CurrentTimeMicroseconds, state_store::{ - errors::StateviewError, + errors::StateViewError, state_storage_usage::StateStorageUsage, state_value::{StateValue, StateValueMetadata}, StateViewId, TStateView, @@ -73,7 +73,7 @@ where type Key = K; // Contains mock storage value with STORAGE_AGGREGATOR_VALUE. - fn get_state_value(&self, _: &K) -> Result, StateviewError> { + fn get_state_value(&self, _: &K) -> Result, StateViewError> { Ok(Some(StateValue::new_legacy( serialize(&STORAGE_AGGREGATOR_VALUE).into(), ))) @@ -83,7 +83,7 @@ where StateViewId::Miscellaneous } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { unreachable!("Not used in tests"); } } @@ -99,7 +99,7 @@ where type Key = K; // Contains mock storage value with a non-empty group (w. value at RESERVED_TAG). - fn get_state_value(&self, key: &K) -> Result, StateviewError> { + fn get_state_value(&self, key: &K) -> Result, StateViewError> { if self.group_keys.contains(key) { let group: BTreeMap = BTreeMap::from([(RESERVED_TAG, vec![0].into())]); @@ -117,7 +117,7 @@ where StateViewId::Miscellaneous } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { unreachable!("Not used in tests"); } } diff --git a/aptos-move/block-executor/src/view.rs b/aptos-move/block-executor/src/view.rs index 660faf6142104b..7f4b3f3daa0537 100644 --- a/aptos-move/block-executor/src/view.rs +++ b/aptos-move/block-executor/src/view.rs @@ -37,7 +37,7 @@ use aptos_types::{ error::{code_invariant_error, expect_ok, PanicError, PanicOr}, executable::{Executable, ModulePath}, state_store::{ - errors::StateviewError, + errors::StateViewError, state_storage_usage::StateStorageUsage, state_value::{StateValue, StateValueMetadata}, StateViewId, TStateView, @@ -1628,12 +1628,12 @@ impl<'a, T: Transaction, S: TStateView, X: Executable> StateStorag self.base_view.id() } - fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateviewError> { + fn read_state_value(&self, state_key: &Self::Key) -> Result<(), StateViewError> { self.base_view.get_state_value(state_key)?; Ok(()) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { self.base_view.get_usage() } } diff --git a/aptos-move/e2e-tests/src/data_store.rs b/aptos-move/e2e-tests/src/data_store.rs index de1825b76203a6..1d1e81f4aab1ee 100644 --- a/aptos-move/e2e-tests/src/data_store.rs +++ b/aptos-move/e2e-tests/src/data_store.rs @@ -10,8 +10,8 @@ use aptos_types::{ chain_id::ChainId, on_chain_config::{Features, OnChainConfig}, state_store::{ - errors::StateviewError, in_memory_state_view::InMemoryStateView, state_key::StateKey, - state_storage_usage::StateStorageUsage, state_value::StateValue, TStateView, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + state_value::StateValue, TStateView, }, transaction::ChangeSet, write_set::{TransactionWrite, WriteSet}, @@ -143,21 +143,17 @@ impl FakeDataStore { impl TStateView for FakeDataStore { type Key = StateKey; - fn get_state_value(&self, state_key: &StateKey) -> Result, StateviewError> { + fn get_state_value(&self, state_key: &StateKey) -> Result, StateViewError> { Ok(self.state_data.get(state_key).cloned()) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> Result { let mut usage = StateStorageUsage::new_untracked(); for (k, v) in self.state_data.iter() { usage.add_item(k.size() + v.size()) } Ok(usage) } - - fn as_in_memory_state_view(&self) -> InMemoryStateView { - InMemoryStateView::new(self.state_data.clone()) - } } #[cfg(test)] diff --git a/aptos-move/vm-genesis/src/genesis_context.rs b/aptos-move/vm-genesis/src/genesis_context.rs index 3a0640c8f7cae9..e54b2c319bc7fb 100644 --- a/aptos-move/vm-genesis/src/genesis_context.rs +++ b/aptos-move/vm-genesis/src/genesis_context.rs @@ -7,7 +7,7 @@ use aptos_types::{ executable::ModulePath, state_store::{ - errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, TStateView, }, write_set::WriteOp, @@ -18,7 +18,7 @@ use claims::assert_some; use move_core_types::language_storage::ModuleId; use std::collections::{BTreeMap, HashMap}; -type Result = std::result::Result; +type Result = std::result::Result; // `StateView` has no data given we are creating the genesis pub(crate) struct GenesisStateView { diff --git a/aptos-node/src/utils.rs b/aptos-node/src/utils.rs index 03b7dcea752967..5a72eb60e988d4 100644 --- a/aptos-node/src/utils.rs +++ b/aptos-node/src/utils.rs @@ -3,7 +3,9 @@ use anyhow::anyhow; use aptos_config::config::{NodeConfig, DEFAULT_EXECUTION_CONCURRENCY_LEVEL}; -use aptos_storage_interface::{state_view::LatestDbStateCheckpointView, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::LatestDbStateCheckpointView, DbReaderWriter, +}; use aptos_types::{ account_config::ChainIdResource, chain_id::ChainId, on_chain_config::OnChainConfig, }; diff --git a/execution/executor-benchmark/src/db_access.rs b/execution/executor-benchmark/src/db_access.rs index 98eebae63b4ca3..388b5011c87731 100644 --- a/execution/executor-benchmark/src/db_access.rs +++ b/execution/executor-benchmark/src/db_access.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::Result; -use aptos_storage_interface::state_view::DbStateView; +use aptos_storage_interface::state_store::state_view::db_state_view::DbStateView; use aptos_types::{ account_address::AccountAddress, state_store::{state_key::StateKey, StateView}, diff --git a/execution/executor-benchmark/src/db_reliable_submitter.rs b/execution/executor-benchmark/src/db_reliable_submitter.rs index d95b8f37e70fa6..70bd730b9107a6 100644 --- a/execution/executor-benchmark/src/db_reliable_submitter.rs +++ b/execution/executor-benchmark/src/db_reliable_submitter.rs @@ -4,7 +4,9 @@ use crate::db_access::{CoinStore, DbAccessUtil}; use anyhow::{Context, Result}; -use aptos_storage_interface::{state_view::LatestDbStateCheckpointView, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::LatestDbStateCheckpointView, DbReaderWriter, +}; use aptos_transaction_generator_lib::{CounterState, ReliableTransactionSubmitter}; use aptos_types::{ account_address::AccountAddress, diff --git a/execution/executor-benchmark/src/lib.rs b/execution/executor-benchmark/src/lib.rs index ef9b88e284c162..fe29d202ef4c0c 100644 --- a/execution/executor-benchmark/src/lib.rs +++ b/execution/executor-benchmark/src/lib.rs @@ -38,7 +38,9 @@ use aptos_jellyfish_merkle::metrics::{ use aptos_logger::{info, warn}; use aptos_metrics_core::Histogram; use aptos_sdk::types::LocalAccount; -use aptos_storage_interface::{state_view::LatestDbStateCheckpointView, DbReader, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::LatestDbStateCheckpointView, DbReader, DbReaderWriter, +}; use aptos_transaction_generator_lib::{ create_txn_generator_creator, AlwaysApproveRootAccountHandle, TransactionGeneratorCreator, TransactionType::{self, CoinTransfer}, diff --git a/execution/executor-benchmark/src/transaction_generator.rs b/execution/executor-benchmark/src/transaction_generator.rs index 4703fa1a905b04..b7fc225dcd79e7 100644 --- a/execution/executor-benchmark/src/transaction_generator.rs +++ b/execution/executor-benchmark/src/transaction_generator.rs @@ -12,7 +12,9 @@ use aptos_sdk::{ transaction_builder::{aptos_stdlib, TransactionFactory}, types::LocalAccount, }; -use aptos_storage_interface::{state_view::LatestDbStateCheckpointView, DbReader, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::LatestDbStateCheckpointView, DbReader, DbReaderWriter, +}; use aptos_types::{ account_address::AccountAddress, account_config::{aptos_test_root_address, AccountResource}, diff --git a/execution/executor-service/src/local_executor_helper.rs b/execution/executor-service/src/local_executor_helper.rs index 4e128086db777c..ff49ac4a68f56c 100644 --- a/execution/executor-service/src/local_executor_helper.rs +++ b/execution/executor-service/src/local_executor_helper.rs @@ -3,7 +3,7 @@ use aptos_infallible::Mutex; use aptos_logger::info; -use aptos_storage_interface::cached_state_view::CachedStateView; +use aptos_storage_interface::state_store::state_view::cached_state_view::CachedStateView; use aptos_vm::{ sharded_block_executor::{local_executor_shard::LocalExecutorClient, ShardedBlockExecutor}, AptosVM, diff --git a/execution/executor-service/src/remote_executor_client.rs b/execution/executor-service/src/remote_executor_client.rs index 30ff095107a919..b14e5c3f66a4b6 100644 --- a/execution/executor-service/src/remote_executor_client.rs +++ b/execution/executor-service/src/remote_executor_client.rs @@ -7,7 +7,7 @@ use crate::{ }; use aptos_logger::{info, trace}; use aptos_secure_net::network_controller::{Message, NetworkController}; -use aptos_storage_interface::cached_state_view::CachedStateView; +use aptos_storage_interface::state_store::state_view::cached_state_view::CachedStateView; use aptos_types::{ block_executor::{ config::BlockExecutorConfigFromOnchain, partitioner::PartitionedTransactions, diff --git a/execution/executor-service/src/remote_state_view.rs b/execution/executor-service/src/remote_state_view.rs index 2cb929c5f84333..e4d7c3232439a8 100644 --- a/execution/executor-service/src/remote_state_view.rs +++ b/execution/executor-service/src/remote_state_view.rs @@ -17,7 +17,8 @@ use aptos_logger::trace; use aptos_types::{ block_executor::partitioner::ShardId, state_store::{ - state_storage_usage::StateStorageUsage, state_value::StateValue, Result, TStateView, + state_storage_usage::StateStorageUsage, state_value::StateValue, StateViewResult, + TStateView, }, }; use dashmap::DashMap; @@ -53,7 +54,7 @@ impl RemoteStateView { .or_insert(RemoteStateValue::waiting()); } - pub fn get_state_value(&self, state_key: &StateKey) -> Result> { + pub fn get_state_value(&self, state_key: &StateKey) -> StateViewResult> { if let Some(value) = self.state_values.get(state_key) { let value_clone = value.clone(); // It is possible that the value is not ready yet and the get_value call blocks. In that @@ -182,7 +183,7 @@ impl RemoteStateViewClient { impl TStateView for RemoteStateViewClient { type Key = StateKey; - fn get_state_value(&self, state_key: &StateKey) -> Result> { + fn get_state_value(&self, state_key: &StateKey) -> StateViewResult> { let state_view_reader = self.state_view.read().unwrap(); if state_view_reader.has_state_key(state_key) { // If the key is already in the cache then we return it. @@ -202,7 +203,7 @@ impl TStateView for RemoteStateViewClient { state_view_reader.get_state_value(state_key) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> StateViewResult { unimplemented!("get_usage is not implemented for RemoteStateView") } } diff --git a/execution/executor-test-helpers/src/integration_test_impl.rs b/execution/executor-test-helpers/src/integration_test_impl.rs index 7b0b08ba157be9..60464ffe5a0173 100644 --- a/execution/executor-test-helpers/src/integration_test_impl.rs +++ b/execution/executor-test-helpers/src/integration_test_impl.rs @@ -16,7 +16,7 @@ use aptos_sdk::{ types::{AccountKey, LocalAccount}, }; use aptos_storage_interface::{ - state_view::{DbStateViewAtVersion, VerifiedStateViewAtVersion}, + state_store::state_view::db_state_view::{DbStateViewAtVersion, VerifiedStateViewAtVersion}, DbReaderWriter, }; use aptos_types::{ diff --git a/execution/executor-types/src/error.rs b/execution/executor-types/src/error.rs index 0e3367d0ec3ca4..355ecb8930108d 100644 --- a/execution/executor-types/src/error.rs +++ b/execution/executor-types/src/error.rs @@ -4,7 +4,7 @@ use aptos_crypto::HashValue; use aptos_storage_interface::AptosDbError; -use aptos_types::{state_store::errors::StateviewError, transaction::Version}; +use aptos_types::{state_store::errors::StateViewError, transaction::Version}; use serde::{Deserialize, Serialize}; use std::fmt::Display; use thiserror::Error; @@ -59,8 +59,8 @@ impl From for ExecutorError { } } -impl From for ExecutorError { - fn from(error: StateviewError) -> Self { +impl From for ExecutorError { + fn from(error: StateViewError) -> Self { Self::InternalError { error: format!("{}", error), } diff --git a/execution/executor-types/src/execution_output.rs b/execution/executor-types/src/execution_output.rs index d4c04f09f27ace..0708274f60c982 100644 --- a/execution/executor-types/src/execution_output.rs +++ b/execution/executor-types/src/execution_output.rs @@ -9,7 +9,9 @@ use crate::{ transactions_with_output::{TransactionsToKeep, TransactionsWithOutput}, }; use aptos_drop_helper::DropHelper; -use aptos_storage_interface::{cached_state_view::StateCache, state_delta::StateDelta}; +use aptos_storage_interface::state_store::{ + state_delta::StateDelta, state_view::cached_state_view::StateCache, +}; use aptos_types::{ contract_event::ContractEvent, epoch_state::EpochState, diff --git a/execution/executor-types/src/state_checkpoint_output.rs b/execution/executor-types/src/state_checkpoint_output.rs index 0851b3341a3fa5..61f5bb597a8d21 100644 --- a/execution/executor-types/src/state_checkpoint_output.rs +++ b/execution/executor-types/src/state_checkpoint_output.rs @@ -5,8 +5,9 @@ use aptos_crypto::HashValue; use aptos_drop_helper::DropHelper; -use aptos_storage_interface::state_delta::StateDelta; -use aptos_types::state_store::ShardedStateUpdates; +use aptos_storage_interface::state_store::{ + sharded_state_updates::ShardedStateUpdates, state_delta::StateDelta, +}; use derive_more::Deref; use std::sync::Arc; diff --git a/execution/executor-types/src/transactions_with_output.rs b/execution/executor-types/src/transactions_with_output.rs index cb6390e12a475c..f69bcef083453a 100644 --- a/execution/executor-types/src/transactions_with_output.rs +++ b/execution/executor-types/src/transactions_with_output.rs @@ -3,7 +3,7 @@ use crate::metrics::TIMER; use aptos_metrics_core::TimerHelper; -use aptos_storage_interface::sharded_state_update_refs::ShardedStateUpdateRefs; +use aptos_storage_interface::state_store::sharded_state_update_refs::ShardedStateUpdateRefs; use aptos_types::transaction::{Transaction, TransactionOutput}; use itertools::izip; use std::{ diff --git a/execution/executor/benches/data_collection.rs b/execution/executor/benches/data_collection.rs index 7adac11a278858..0a76e00bba9cfe 100644 --- a/execution/executor/benches/data_collection.rs +++ b/execution/executor/benches/data_collection.rs @@ -1,11 +1,12 @@ // Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 +use aptos_storage_interface::state_store::NUM_STATE_SHARDS; use aptos_types::{ account_address::AccountAddress, account_config::AccountResource, event::{EventHandle, EventKey}, - state_store::{state_key::StateKey, state_value::StateValue, NUM_STATE_SHARDS}, + state_store::{state_key::StateKey, state_value::StateValue}, transaction::Version, write_set::{WriteOp, WriteSet}, }; diff --git a/execution/executor/src/block_executor/mod.rs b/execution/executor/src/block_executor/mod.rs index f60548a94029a3..40c90751bcec71 100644 --- a/execution/executor/src/block_executor/mod.rs +++ b/execution/executor/src/block_executor/mod.rs @@ -27,7 +27,10 @@ use aptos_infallible::RwLock; use aptos_logger::prelude::*; use aptos_metrics_core::{IntGaugeHelper, TimerHelper}; use aptos_storage_interface::{ - async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, DbReaderWriter, + state_store::state_view::{ + async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, + }, + DbReaderWriter, }; use aptos_types::{ block_executor::{ diff --git a/execution/executor/src/chunk_executor/chunk_commit_queue.rs b/execution/executor/src/chunk_executor/chunk_commit_queue.rs index 1af1e28908f006..c5794399e75860 100644 --- a/execution/executor/src/chunk_executor/chunk_commit_queue.rs +++ b/execution/executor/src/chunk_executor/chunk_commit_queue.rs @@ -11,7 +11,7 @@ use crate::{ }, }; use anyhow::{anyhow, ensure, Result}; -use aptos_storage_interface::{state_delta::StateDelta, DbReader, ExecutedTrees}; +use aptos_storage_interface::{state_store::state_delta::StateDelta, DbReader, ExecutedTrees}; use aptos_types::{proof::accumulator::InMemoryTransactionAccumulator, transaction::Version}; use std::{collections::VecDeque, sync::Arc}; diff --git a/execution/executor/src/chunk_executor/mod.rs b/execution/executor/src/chunk_executor/mod.rs index ddb42725791f55..290e630757cf8f 100644 --- a/execution/executor/src/chunk_executor/mod.rs +++ b/execution/executor/src/chunk_executor/mod.rs @@ -24,8 +24,11 @@ use aptos_infallible::{Mutex, RwLock}; use aptos_logger::prelude::*; use aptos_metrics_core::{IntGaugeHelper, TimerHelper}; use aptos_storage_interface::{ - async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, - state_delta::StateDelta, DbReaderWriter, + state_store::{ + state_delta::StateDelta, + state_view::{async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView}, + }, + DbReaderWriter, }; use aptos_types::{ block_executor::{ diff --git a/execution/executor/src/chunk_executor/transaction_chunk.rs b/execution/executor/src/chunk_executor/transaction_chunk.rs index 89a3e39ffb285f..c1958bfb666474 100644 --- a/execution/executor/src/chunk_executor/transaction_chunk.rs +++ b/execution/executor/src/chunk_executor/transaction_chunk.rs @@ -9,7 +9,7 @@ use anyhow::Result; use aptos_executor_types::execution_output::ExecutionOutput; use aptos_experimental_runtimes::thread_manager::optimal_min_len; use aptos_metrics_core::TimerHelper; -use aptos_storage_interface::cached_state_view::CachedStateView; +use aptos_storage_interface::state_store::state_view::cached_state_view::CachedStateView; use aptos_types::{ block_executor::{ config::BlockExecutorConfigFromOnchain, diff --git a/execution/executor/src/db_bootstrapper/mod.rs b/execution/executor/src/db_bootstrapper/mod.rs index db0f85c28cb14f..76380637cb8340 100644 --- a/execution/executor/src/db_bootstrapper/mod.rs +++ b/execution/executor/src/db_bootstrapper/mod.rs @@ -12,8 +12,10 @@ use anyhow::{anyhow, ensure, format_err, Result}; use aptos_crypto::HashValue; use aptos_logger::prelude::*; use aptos_storage_interface::{ - async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, DbReaderWriter, - DbWriter, ExecutedTrees, + state_store::state_view::{ + async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, + }, + DbReaderWriter, DbWriter, ExecutedTrees, }; use aptos_types::{ account_config::CORE_CODE_ADDRESS, diff --git a/execution/executor/src/tests/mod.rs b/execution/executor/src/tests/mod.rs index 163cbfda435a73..0a599682eac873 100644 --- a/execution/executor/src/tests/mod.rs +++ b/execution/executor/src/tests/mod.rs @@ -13,7 +13,8 @@ use aptos_executor_types::{ BlockExecutorTrait, ChunkExecutorTrait, TransactionReplayer, VerifyExecutionMode, }; use aptos_storage_interface::{ - async_proof_fetcher::AsyncProofFetcher, DbReaderWriter, ExecutedTrees, Result, + state_store::state_view::async_proof_fetcher::AsyncProofFetcher, DbReaderWriter, ExecutedTrees, + Result, }; use aptos_types::{ account_address::AccountAddress, diff --git a/execution/executor/src/types/in_memory_state_calculator_v2.rs b/execution/executor/src/types/in_memory_state_calculator_v2.rs index b09700336fe8f2..95bb07bfcd1b5f 100644 --- a/execution/executor/src/types/in_memory_state_calculator_v2.rs +++ b/execution/executor/src/types/in_memory_state_calculator_v2.rs @@ -12,15 +12,15 @@ use aptos_executor_types::{ use aptos_logger::info; use aptos_metrics_core::TimerHelper; use aptos_scratchpad::FrozenSparseMerkleTree; -use aptos_storage_interface::{ - cached_state_view::{ShardedStateCache, StateCache}, +use aptos_storage_interface::state_store::{ sharded_state_update_refs::ShardedStateUpdateRefs, + sharded_state_updates::ShardedStateUpdates, state_delta::StateDelta, + state_view::cached_state_view::{ShardedStateCache, StateCache}, }; use aptos_types::{ state_store::{ state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, - ShardedStateUpdates, }, transaction::Version, write_set::WriteSet, diff --git a/execution/executor/src/types/partial_state_compute_result.rs b/execution/executor/src/types/partial_state_compute_result.rs index a3167de3f65c8b..2a62efdab6d0cb 100644 --- a/execution/executor/src/types/partial_state_compute_result.rs +++ b/execution/executor/src/types/partial_state_compute_result.rs @@ -7,7 +7,7 @@ use aptos_executor_types::{ execution_output::ExecutionOutput, state_checkpoint_output::StateCheckpointOutput, state_compute_result::StateComputeResult, LedgerUpdateOutput, }; -use aptos_storage_interface::state_delta::StateDelta; +use aptos_storage_interface::state_store::state_delta::StateDelta; use aptos_types::proof::accumulator::InMemoryTransactionAccumulator; use once_cell::sync::OnceCell; use std::sync::Arc; diff --git a/execution/executor/src/workflow/do_get_execution_output.rs b/execution/executor/src/workflow/do_get_execution_output.rs index a494598a530473..99be96683f624c 100644 --- a/execution/executor/src/workflow/do_get_execution_output.rs +++ b/execution/executor/src/workflow/do_get_execution_output.rs @@ -23,7 +23,9 @@ use aptos_executor_types::{ use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER; use aptos_logger::prelude::*; use aptos_metrics_core::TimerHelper; -use aptos_storage_interface::cached_state_view::{CachedStateView, StateCache}; +use aptos_storage_interface::state_store::state_view::cached_state_view::{ + CachedStateView, StateCache, +}; #[cfg(feature = "consensus-only-perf-test")] use aptos_types::transaction::ExecutionStatus; use aptos_types::{ @@ -486,21 +488,21 @@ impl<'a> TStateView for WriteSetStateView<'a> { fn get_state_value( &self, state_key: &Self::Key, - ) -> aptos_types::state_store::Result> { + ) -> aptos_types::state_store::StateViewResult> { Ok(self .write_set .get(state_key) .and_then(|write_op| write_op.as_state_value())) } - fn get_usage(&self) -> aptos_types::state_store::Result { + fn get_usage(&self) -> aptos_types::state_store::StateViewResult { unreachable!("Not supposed to be called on WriteSetStateView.") } } #[cfg(test)] mod tests { use super::Parser; - use aptos_storage_interface::cached_state_view::StateCache; + use aptos_storage_interface::state_store::state_view::cached_state_view::StateCache; use aptos_types::{ contract_event::ContractEvent, transaction::{ diff --git a/execution/executor/src/workflow/do_state_checkpoint.rs b/execution/executor/src/workflow/do_state_checkpoint.rs index a971ca2130a3a9..1d4cfae66ec3ae 100644 --- a/execution/executor/src/workflow/do_state_checkpoint.rs +++ b/execution/executor/src/workflow/do_state_checkpoint.rs @@ -7,7 +7,7 @@ use aptos_crypto::HashValue; use aptos_executor_types::{ execution_output::ExecutionOutput, state_checkpoint_output::StateCheckpointOutput, }; -use aptos_storage_interface::state_delta::StateDelta; +use aptos_storage_interface::state_store::state_delta::StateDelta; use std::sync::Arc; pub struct DoStateCheckpoint; diff --git a/execution/executor/tests/db_bootstrapper_test.rs b/execution/executor/tests/db_bootstrapper_test.rs index 6ec37d8c300485..96d6647bb898b9 100644 --- a/execution/executor/tests/db_bootstrapper_test.rs +++ b/execution/executor/tests/db_bootstrapper_test.rs @@ -15,7 +15,9 @@ use aptos_executor_test_helpers::{ bootstrap_genesis, gen_ledger_info_with_sigs, get_test_signed_transaction, }; use aptos_executor_types::BlockExecutorTrait; -use aptos_storage_interface::{state_view::LatestDbStateCheckpointView, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::LatestDbStateCheckpointView, DbReaderWriter, +}; use aptos_temppath::TempPath; use aptos_types::{ account_address::AccountAddress, diff --git a/execution/executor/tests/storage_integration_test.rs b/execution/executor/tests/storage_integration_test.rs index 33e077dc06b838..e0c77042d84231 100644 --- a/execution/executor/tests/storage_integration_test.rs +++ b/execution/executor/tests/storage_integration_test.rs @@ -11,7 +11,7 @@ use aptos_executor_test_helpers::{ }, }; use aptos_executor_types::BlockExecutorTrait; -use aptos_storage_interface::state_view::DbStateViewAtVersion; +use aptos_storage_interface::state_store::state_view::db_state_view::DbStateViewAtVersion; use aptos_types::{ account_config::{aptos_test_root_address, AccountResource, CORE_CODE_ADDRESS}, block_metadata::BlockMetadata, diff --git a/experimental/execution/ptx-executor/src/state_view.rs b/experimental/execution/ptx-executor/src/state_view.rs index 8cfaa248473d3c..3bd79345437686 100644 --- a/experimental/execution/ptx-executor/src/state_view.rs +++ b/experimental/execution/ptx-executor/src/state_view.rs @@ -5,8 +5,8 @@ use crate::common::HashMap; use aptos_types::state_store::{ - state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, Result, - StateView, TStateView, + state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, + StateView, StateViewResult, TStateView, }; pub struct OverlayedStateView<'view> { base_view: &'view dyn StateView, @@ -33,7 +33,7 @@ impl<'view> OverlayedStateView<'view> { impl<'view> TStateView for OverlayedStateView<'view> { type Key = StateKey; - fn get_state_value(&self, state_key: &Self::Key) -> Result> { + fn get_state_value(&self, state_key: &Self::Key) -> StateViewResult> { // TODO(ptx): reject non-module reads once block_metadata is analyzed for R/W set // TODO(ptx): remove base_view reads once module reads are dealt with self.overlay @@ -43,7 +43,7 @@ impl<'view> TStateView for OverlayedStateView<'view> { .unwrap_or_else(|| self.base_view.get_state_value(state_key)) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> StateViewResult { // TODO(aldenhu): maybe remove get_usage() from StateView unimplemented!() } diff --git a/mempool/src/shared_mempool/tasks.rs b/mempool/src/shared_mempool/tasks.rs index 71a8c6f392a56f..bf97397f9e1d53 100644 --- a/mempool/src/shared_mempool/tasks.rs +++ b/mempool/src/shared_mempool/tasks.rs @@ -28,7 +28,7 @@ use aptos_logger::prelude::*; use aptos_mempool_notifications::CommittedTransaction; use aptos_metrics_core::HistogramTimer; use aptos_network::application::interface::NetworkClientInterface; -use aptos_storage_interface::state_view::LatestDbStateCheckpointView; +use aptos_storage_interface::state_store::state_view::db_state_view::LatestDbStateCheckpointView; use aptos_types::{ account_address::AccountAddress, mempool_status::{MempoolStatus, MempoolStatusCode}, diff --git a/state-sync/inter-component/event-notifications/src/lib.rs b/state-sync/inter-component/event-notifications/src/lib.rs index 4ff95eaf18b8d3..965a43fedad10e 100644 --- a/state-sync/inter-component/event-notifications/src/lib.rs +++ b/state-sync/inter-component/event-notifications/src/lib.rs @@ -7,7 +7,9 @@ use anyhow::{anyhow, Result}; use aptos_channels::{aptos_channel, message_queues::QueueStyle}; use aptos_id_generator::{IdGenerator, U64IdGenerator}; use aptos_infallible::RwLock; -use aptos_storage_interface::{state_view::DbStateViewAtVersion, DbReader, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::DbStateViewAtVersion, DbReader, DbReaderWriter, +}; use aptos_types::{ contract_event::ContractEvent, event::EventKey, diff --git a/storage/aptosdb/src/backup/restore_utils.rs b/storage/aptosdb/src/backup/restore_utils.rs index 3dd23badae6c24..851c3d1489b6ba 100644 --- a/storage/aptosdb/src/backup/restore_utils.rs +++ b/storage/aptosdb/src/backup/restore_utils.rs @@ -18,7 +18,9 @@ use crate::{ }; use aptos_crypto::HashValue; use aptos_schemadb::{SchemaBatch, DB}; -use aptos_storage_interface::{db_ensure as ensure, state_delta::StateDelta, AptosDbError, Result}; +use aptos_storage_interface::{ + db_ensure as ensure, state_store::state_delta::StateDelta, AptosDbError, Result, +}; use aptos_types::{ contract_event::ContractEvent, ledger_info::LedgerInfoWithSignatures, diff --git a/storage/aptosdb/src/db/fake_aptosdb.rs b/storage/aptosdb/src/db/fake_aptosdb.rs index 423dcf8119e7f3..2f3477765addb2 100644 --- a/storage/aptosdb/src/db/fake_aptosdb.rs +++ b/storage/aptosdb/src/db/fake_aptosdb.rs @@ -16,7 +16,11 @@ use aptos_infallible::Mutex; use aptos_logger::debug; use aptos_scratchpad::SparseMerkleTree; use aptos_storage_interface::{ - cached_state_view::ShardedStateCache, db_ensure as ensure, state_delta::StateDelta, + db_ensure as ensure, + state_store::{ + sharded_state_updates::ShardedStateUpdates, state_delta::StateDelta, + state_view::cached_state_view::ShardedStateCache, + }, AptosDbError, DbReader, DbWriter, ExecutedTrees, MAX_REQUEST_LIMIT, }; use aptos_types::{ @@ -40,7 +44,7 @@ use aptos_types::{ state_key::{prefix::StateKeyPrefix, StateKey}, state_storage_usage::StateStorageUsage, state_value::{StateValue, StateValueChunkWithProof}, - table, ShardedStateUpdates, + table, }, transaction::{ Transaction, TransactionAuxiliaryData, TransactionInfo, TransactionListWithProof, @@ -971,7 +975,9 @@ mod tests { }; use anyhow::{anyhow, ensure, Result}; use aptos_crypto::{hash::CryptoHash, HashValue}; - use aptos_storage_interface::{cached_state_view::ShardedStateCache, DbReader, DbWriter}; + use aptos_storage_interface::{ + state_store::state_view::cached_state_view::ShardedStateCache, DbReader, DbWriter, + }; use aptos_temppath::TempPath; use aptos_types::{ account_address::AccountAddress, diff --git a/storage/aptosdb/src/db/include/aptosdb_internal.rs b/storage/aptosdb/src/db/include/aptosdb_internal.rs index d31b38778e1df1..48ff86fffecf09 100644 --- a/storage/aptosdb/src/db/include/aptosdb_internal.rs +++ b/storage/aptosdb/src/db/include/aptosdb_internal.rs @@ -129,7 +129,7 @@ impl AptosDB { ); if indexer.next_version() < ledger_next_version { - use aptos_storage_interface::state_view::DbStateViewAtVersion; + use aptos_storage_interface::state_store::state_view::db_state_view::DbStateViewAtVersion; let db: Arc = self.state_store.clone(); let state_view = db.state_view_at_version(Some(ledger_next_version - 1))?; diff --git a/storage/aptosdb/src/db/include/aptosdb_testonly.rs b/storage/aptosdb/src/db/include/aptosdb_testonly.rs index bb617af181f327..77288df003b012 100644 --- a/storage/aptosdb/src/db/include/aptosdb_testonly.rs +++ b/storage/aptosdb/src/db/include/aptosdb_testonly.rs @@ -1,14 +1,13 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -use aptos_config::config::{ BUFFERED_STATE_TARGET_ITEMS_FOR_TEST, DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD}; +use aptos_config::config::{BUFFERED_STATE_TARGET_ITEMS_FOR_TEST, DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD}; use std::default::Default; -use aptos_storage_interface::cached_state_view::ShardedStateCache; -use aptos_storage_interface::state_delta::StateDelta; -use aptos_types::state_store::{ShardedStateUpdates}; +use aptos_storage_interface::state_store::state_view::cached_state_view::ShardedStateCache; +use aptos_storage_interface::state_store::state_delta::StateDelta; use aptos_types::transaction::{TransactionStatus, TransactionToCommit}; use aptos_executor_types::transactions_with_output::TransactionsToKeep; -use aptos_storage_interface::sharded_state_update_refs::ShardedStateUpdateRefs; +use aptos_storage_interface::state_store::sharded_state_update_refs::ShardedStateUpdateRefs; impl AptosDB { /// This opens db in non-readonly mode, without the pruner. diff --git a/storage/aptosdb/src/db/mod.rs b/storage/aptosdb/src/db/mod.rs index 7289b035d75bae..04a5e9bc539a5c 100644 --- a/storage/aptosdb/src/db/mod.rs +++ b/storage/aptosdb/src/db/mod.rs @@ -40,8 +40,9 @@ use aptos_resource_viewer::AptosValueAnnotator; use aptos_schemadb::SchemaBatch; use aptos_scratchpad::SparseMerkleTree; use aptos_storage_interface::{ - db_ensure as ensure, db_other_bail as bail, AptosDbError, DbReader, DbWriter, ExecutedTrees, - Order, Result, StateSnapshotReceiver, MAX_REQUEST_LIMIT, + db_ensure as ensure, db_other_bail as bail, + state_store::sharded_state_updates::ShardedStateUpdates, AptosDbError, DbReader, DbWriter, + ExecutedTrees, Order, Result, StateSnapshotReceiver, MAX_REQUEST_LIMIT, }; use aptos_types::{ account_address::AccountAddress, diff --git a/storage/aptosdb/src/db/test_helper.rs b/storage/aptosdb/src/db/test_helper.rs index 3e79211014ec08..6de6bce71bb767 100644 --- a/storage/aptosdb/src/db/test_helper.rs +++ b/storage/aptosdb/src/db/test_helper.rs @@ -18,7 +18,7 @@ use aptos_executor_types::ProofReader; use aptos_jellyfish_merkle::node_type::{Node, NodeKey}; #[cfg(test)] use aptos_schemadb::SchemaBatch; -use aptos_storage_interface::{state_delta::StateDelta, DbReader, Order, Result}; +use aptos_storage_interface::{state_store::state_delta::StateDelta, DbReader, Order, Result}; use aptos_temppath::TempPath; #[cfg(test)] use aptos_types::state_store::state_storage_usage::StateStorageUsage; @@ -68,7 +68,8 @@ pub(crate) fn update_store( enable_sharding: bool, ) -> HashValue { use aptos_storage_interface::{ - jmt_update_refs, jmt_updates, sharded_state_update_refs::ShardedStateUpdateRefs, + jmt_update_refs, jmt_updates, + state_store::sharded_state_update_refs::ShardedStateUpdateRefs, }; let mut root_hash = *aptos_crypto::hash::SPARSE_MERKLE_PLACEHOLDER_HASH; diff --git a/storage/aptosdb/src/db_debugger/truncate/mod.rs b/storage/aptosdb/src/db_debugger/truncate/mod.rs index 160f91b3a11fcc..548bdf8961bd10 100644 --- a/storage/aptosdb/src/db_debugger/truncate/mod.rs +++ b/storage/aptosdb/src/db_debugger/truncate/mod.rs @@ -177,9 +177,8 @@ mod test { }, utils::truncation_helper::num_frozen_nodes_in_accumulator, }; - use aptos_storage_interface::DbReader; + use aptos_storage_interface::{state_store::NUM_STATE_SHARDS, DbReader}; use aptos_temppath::TempPath; - use aptos_types::state_store::NUM_STATE_SHARDS; use proptest::prelude::*; proptest! { diff --git a/storage/aptosdb/src/pruner/state_merkle_pruner/test.rs b/storage/aptosdb/src/pruner/state_merkle_pruner/test.rs index f65495bf78eb2d..ed5e8ffd2e5982 100644 --- a/storage/aptosdb/src/pruner/state_merkle_pruner/test.rs +++ b/storage/aptosdb/src/pruner/state_merkle_pruner/test.rs @@ -20,7 +20,9 @@ use aptos_config::config::{LedgerPrunerConfig, StateMerklePrunerConfig}; use aptos_crypto::{hash::CryptoHash, HashValue}; use aptos_schemadb::SchemaBatch; use aptos_storage_interface::{ - jmt_update_refs, jmt_updates, sharded_state_update_refs::ShardedStateUpdateRefs, DbReader, + jmt_update_refs, jmt_updates, + state_store::{sharded_state_update_refs::ShardedStateUpdateRefs, NUM_STATE_SHARDS}, + DbReader, }; use aptos_temppath::TempPath; use aptos_types::{ @@ -28,7 +30,6 @@ use aptos_types::{ state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::{StaleStateValueByKeyHashIndex, StaleStateValueIndex, StateValue}, - NUM_STATE_SHARDS, }, transaction::Version, }; diff --git a/storage/aptosdb/src/rocksdb_property_reporter.rs b/storage/aptosdb/src/rocksdb_property_reporter.rs index a719318224c2fb..9d5912b8c3e17e 100644 --- a/storage/aptosdb/src/rocksdb_property_reporter.rs +++ b/storage/aptosdb/src/rocksdb_property_reporter.rs @@ -23,7 +23,7 @@ use aptos_infallible::Mutex; use aptos_logger::prelude::*; use aptos_metrics_core::IntGaugeVec; use aptos_schemadb::DB; -use aptos_types::state_store::NUM_STATE_SHARDS; +use aptos_storage_interface::state_store::NUM_STATE_SHARDS; use once_cell::sync::Lazy; use std::{ collections::HashMap, diff --git a/storage/aptosdb/src/state_kv_db.rs b/storage/aptosdb/src/state_kv_db.rs index f0cb7a27c21741..27d28bf7f2696c 100644 --- a/storage/aptosdb/src/state_kv_db.rs +++ b/storage/aptosdb/src/state_kv_db.rs @@ -19,9 +19,9 @@ use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER; use aptos_logger::prelude::info; use aptos_rocksdb_options::gen_rocksdb_options; use aptos_schemadb::{ReadOptions, SchemaBatch, DB}; -use aptos_storage_interface::Result; +use aptos_storage_interface::{state_store::NUM_STATE_SHARDS, Result}; use aptos_types::{ - state_store::{state_key::StateKey, state_value::StateValue, NUM_STATE_SHARDS}, + state_store::{state_key::StateKey, state_value::StateValue}, transaction::Version, }; use arr_macro::arr; diff --git a/storage/aptosdb/src/state_merkle_db.rs b/storage/aptosdb/src/state_merkle_db.rs index e61e461aa3453d..7d7ad649d0431c 100644 --- a/storage/aptosdb/src/state_merkle_db.rs +++ b/storage/aptosdb/src/state_merkle_db.rs @@ -25,11 +25,13 @@ use aptos_rocksdb_options::gen_rocksdb_options; use aptos_schemadb::{SchemaBatch, DB}; #[cfg(test)] use aptos_scratchpad::get_state_shard_id; -use aptos_storage_interface::{db_ensure as ensure, AptosDbError, Result}; +use aptos_storage_interface::{ + db_ensure as ensure, state_store::NUM_STATE_SHARDS, AptosDbError, Result, +}; use aptos_types::{ nibble::{nibble_path::NibblePath, ROOT_NIBBLE_HEIGHT}, proof::{SparseMerkleProofExt, SparseMerkleRangeProof}, - state_store::{state_key::StateKey, NUM_STATE_SHARDS}, + state_store::state_key::StateKey, transaction::Version, }; use arr_macro::arr; diff --git a/storage/aptosdb/src/state_store/buffered_state.rs b/storage/aptosdb/src/state_store/buffered_state.rs index fa398701d166e8..89f1e305e6f51f 100644 --- a/storage/aptosdb/src/state_store/buffered_state.rs +++ b/storage/aptosdb/src/state_store/buffered_state.rs @@ -10,8 +10,12 @@ use crate::{ use aptos_logger::info; use aptos_metrics_core::TimerHelper; use aptos_scratchpad::SmtAncestors; -use aptos_storage_interface::{db_ensure as ensure, state_delta::StateDelta, AptosDbError, Result}; -use aptos_types::state_store::{state_value::StateValue, ShardedStateUpdates}; +use aptos_storage_interface::{ + db_ensure as ensure, + state_store::{sharded_state_updates::ShardedStateUpdates, state_delta::StateDelta}, + AptosDbError, Result, +}; +use aptos_types::state_store::state_value::StateValue; use std::{ sync::{ mpsc, diff --git a/storage/aptosdb/src/state_store/mod.rs b/storage/aptosdb/src/state_store/mod.rs index 4c68a0c0bc6b33..3f32b78f6d4829 100644 --- a/storage/aptosdb/src/state_store/mod.rs +++ b/storage/aptosdb/src/state_store/mod.rs @@ -51,11 +51,16 @@ use aptos_metrics_core::TimerHelper; use aptos_schemadb::SchemaBatch; use aptos_scratchpad::{SmtAncestors, SparseMerkleTree}; use aptos_storage_interface::{ - async_proof_fetcher::AsyncProofFetcher, - cached_state_view::{CachedStateView, ShardedStateCache}, db_ensure as ensure, db_other_bail as bail, - sharded_state_update_refs::ShardedStateUpdateRefs, - state_delta::StateDelta, + state_store::{ + sharded_state_update_refs::ShardedStateUpdateRefs, + state_delta::StateDelta, + state_view::{ + async_proof_fetcher::AsyncProofFetcher, + cached_state_view::{CachedStateView, ShardedStateCache}, + }, + NUM_STATE_SHARDS, + }, AptosDbError, DbReader, Result, StateSnapshotReceiver, }; use aptos_types::{ @@ -67,7 +72,7 @@ use aptos_types::{ StaleStateValueByKeyHashIndex, StaleStateValueIndex, StateValue, StateValueChunkWithProof, }, - StateViewId, NUM_STATE_SHARDS, + StateViewId, }, transaction::Version, write_set::WriteSet, diff --git a/storage/aptosdb/src/state_store/state_merkle_batch_committer.rs b/storage/aptosdb/src/state_store/state_merkle_batch_committer.rs index 3c9bce81f10b72..85e5c4dcbfcf39 100644 --- a/storage/aptosdb/src/state_store/state_merkle_batch_committer.rs +++ b/storage/aptosdb/src/state_store/state_merkle_batch_committer.rs @@ -16,7 +16,7 @@ use aptos_logger::{info, trace}; use aptos_metrics_core::TimerHelper; use aptos_schemadb::SchemaBatch; use aptos_scratchpad::SmtAncestors; -use aptos_storage_interface::state_delta::StateDelta; +use aptos_storage_interface::state_store::state_delta::StateDelta; use aptos_types::state_store::state_value::StateValue; use std::sync::{mpsc::Receiver, Arc}; diff --git a/storage/aptosdb/src/state_store/state_snapshot_committer.rs b/storage/aptosdb/src/state_store/state_snapshot_committer.rs index f0668ba250a943..b45c49fa784fd7 100644 --- a/storage/aptosdb/src/state_store/state_snapshot_committer.rs +++ b/storage/aptosdb/src/state_store/state_snapshot_committer.rs @@ -15,8 +15,12 @@ use crate::{ use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER; use aptos_logger::trace; use aptos_scratchpad::SmtAncestors; -use aptos_storage_interface::{jmt_update_refs, jmt_updates, state_delta::StateDelta, Result}; -use aptos_types::state_store::{state_value::StateValue, NUM_STATE_SHARDS}; +use aptos_storage_interface::{ + jmt_update_refs, jmt_updates, + state_store::{state_delta::StateDelta, NUM_STATE_SHARDS}, + Result, +}; +use aptos_types::state_store::state_value::StateValue; use rayon::prelude::*; use static_assertions::const_assert; use std::{ diff --git a/storage/aptosdb/src/utils/mod.rs b/storage/aptosdb/src/utils/mod.rs index 239521005712e8..ac8d76901ddb99 100644 --- a/storage/aptosdb/src/utils/mod.rs +++ b/storage/aptosdb/src/utils/mod.rs @@ -6,8 +6,8 @@ pub(crate) mod truncation_helper; use crate::schema::db_metadata::{DbMetadataKey, DbMetadataSchema}; use aptos_schemadb::{SchemaBatch, DB}; -use aptos_storage_interface::Result; -use aptos_types::{state_store::NUM_STATE_SHARDS, transaction::Version}; +use aptos_storage_interface::{state_store::NUM_STATE_SHARDS, Result}; +use aptos_types::transaction::Version; use arr_macro::arr; pub(crate) type ShardedStateKvSchemaBatch = [SchemaBatch; NUM_STATE_SHARDS]; diff --git a/storage/db-tool/src/replay_on_archive.rs b/storage/db-tool/src/replay_on_archive.rs index d4bd05161a90c1..74000e50941acf 100644 --- a/storage/db-tool/src/replay_on_archive.rs +++ b/storage/db-tool/src/replay_on_archive.rs @@ -11,7 +11,9 @@ use aptos_config::config::{ }; use aptos_db::{backup::backup_handler::BackupHandler, AptosDB}; use aptos_logger::{error, info}; -use aptos_storage_interface::{state_view::DbStateViewAtVersion, AptosDbError, DbReader}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::DbStateViewAtVersion, AptosDbError, DbReader, +}; use aptos_types::{ contract_event::ContractEvent, transaction::{ @@ -30,6 +32,7 @@ use std::{ sync::{atomic::AtomicU64, Arc}, time::Instant, }; + // Replay Verify controller is responsible for providing legit range with start and end versions. #[derive(Parser)] pub struct Opt { diff --git a/storage/indexer/src/db_v2.rs b/storage/indexer/src/db_v2.rs index 01ad40d096251c..fae7813789d5ab 100644 --- a/storage/indexer/src/db_v2.rs +++ b/storage/indexer/src/db_v2.rs @@ -13,7 +13,8 @@ use aptos_logger::info; use aptos_resource_viewer::{AnnotatedMoveValue, AptosValueAnnotator}; use aptos_schemadb::{SchemaBatch, DB}; use aptos_storage_interface::{ - db_other_bail as bail, state_view::DbStateViewAtVersion, AptosDbError, DbReader, Result, + db_other_bail as bail, state_store::state_view::db_state_view::DbStateViewAtVersion, + AptosDbError, DbReader, Result, }; use aptos_types::{ access_path::Path, diff --git a/storage/indexer/src/lib.rs b/storage/indexer/src/lib.rs index 7a041c5dbbacab..34331dd702c314 100644 --- a/storage/indexer/src/lib.rs +++ b/storage/indexer/src/lib.rs @@ -23,7 +23,8 @@ use aptos_resource_viewer::{AnnotatedMoveValue, AptosValueAnnotator}; use aptos_rocksdb_options::gen_rocksdb_options; use aptos_schemadb::{SchemaBatch, DB}; use aptos_storage_interface::{ - db_ensure, db_other_bail, state_view::DbStateViewAtVersion, AptosDbError, DbReader, Result, + db_ensure, db_other_bail, state_store::state_view::db_state_view::DbStateViewAtVersion, + AptosDbError, DbReader, Result, }; use aptos_types::{ access_path::Path, diff --git a/storage/storage-interface/src/chunk_to_commit.rs b/storage/storage-interface/src/chunk_to_commit.rs index 86b9755b7169ba..5148bfd23c7093 100644 --- a/storage/storage-interface/src/chunk_to_commit.rs +++ b/storage/storage-interface/src/chunk_to_commit.rs @@ -1,14 +1,11 @@ // Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -use crate::{ - cached_state_view::ShardedStateCache, sharded_state_update_refs::ShardedStateUpdateRefs, - state_delta::StateDelta, -}; -use aptos_types::{ - state_store::ShardedStateUpdates, - transaction::{Transaction, TransactionInfo, TransactionOutput, Version}, +use crate::state_store::{ + sharded_state_update_refs::ShardedStateUpdateRefs, sharded_state_updates::ShardedStateUpdates, + state_delta::StateDelta, state_view::cached_state_view::ShardedStateCache, }; +use aptos_types::transaction::{Transaction, TransactionInfo, TransactionOutput, Version}; #[derive(Clone)] pub struct ChunkToCommit<'a> { diff --git a/storage/storage-interface/src/errors.rs b/storage/storage-interface/src/errors.rs index 8e380126700fa1..7acb9e202024e6 100644 --- a/storage/storage-interface/src/errors.rs +++ b/storage/storage-interface/src/errors.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 //! This module defines error types used by `AptosDB`. -use aptos_types::state_store::errors::StateviewError; +use aptos_types::state_store::errors::StateViewError; use std::sync::mpsc::RecvError; use thiserror::Error; @@ -65,22 +65,22 @@ impl From for AptosDbError { } } -impl From for StateviewError { +impl From for StateViewError { fn from(error: AptosDbError) -> Self { match error { - AptosDbError::NotFound(msg) => StateviewError::NotFound(msg), - AptosDbError::Other(msg) => StateviewError::Other(msg), - _ => StateviewError::Other(format!("{}", error)), + AptosDbError::NotFound(msg) => StateViewError::NotFound(msg), + AptosDbError::Other(msg) => StateViewError::Other(msg), + _ => StateViewError::Other(format!("{}", error)), } } } -impl From for AptosDbError { - fn from(error: StateviewError) -> Self { +impl From for AptosDbError { + fn from(error: StateViewError) -> Self { match error { - StateviewError::NotFound(msg) => AptosDbError::NotFound(msg), - StateviewError::Other(msg) => AptosDbError::Other(msg), - StateviewError::BcsError(err) => AptosDbError::BcsError(err.to_string()), + StateViewError::NotFound(msg) => AptosDbError::NotFound(msg), + StateViewError::Other(msg) => AptosDbError::Other(msg), + StateViewError::BcsError(err) => AptosDbError::BcsError(err.to_string()), } } } diff --git a/storage/storage-interface/src/executed_trees.rs b/storage/storage-interface/src/executed_trees.rs index 58c6194fa8668e..9f3ad490c7f514 100644 --- a/storage/storage-interface/src/executed_trees.rs +++ b/storage/storage-interface/src/executed_trees.rs @@ -2,18 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, - state_delta::StateDelta, DbReader, + state_store::{ + state_delta::StateDelta, + state_view::{async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView}, + }, + DbReader, }; use aptos_crypto::HashValue; use aptos_types::{ proof::accumulator::{InMemoryAccumulator, InMemoryTransactionAccumulator}, - state_store::{errors::StateviewError, state_storage_usage::StateStorageUsage, StateViewId}, + state_store::{errors::StateViewError, state_storage_usage::StateStorageUsage, StateViewId}, transaction::Version, }; use std::sync::Arc; -type Result = std::result::Result; +type Result = std::result::Result; /// A wrapper of the in-memory state sparse merkle tree and the transaction accumulator that /// represent a specific state collectively. Usually it is a state after executing a block. diff --git a/storage/storage-interface/src/lib.rs b/storage/storage-interface/src/lib.rs index a22b9c4d9bfab6..ac92e5e39f663e 100644 --- a/storage/storage-interface/src/lib.rs +++ b/storage/storage-interface/src/lib.rs @@ -34,18 +34,14 @@ use serde::{Deserialize, Serialize}; use std::{collections::HashMap, sync::Arc}; use thiserror::Error; -pub mod async_proof_fetcher; pub mod block_info; -pub mod cached_state_view; pub mod chunk_to_commit; pub mod errors; mod executed_trees; mod metrics; #[cfg(any(test, feature = "fuzzing"))] pub mod mock; -pub mod sharded_state_update_refs; -pub mod state_delta; -pub mod state_view; +pub mod state_store; use crate::chunk_to_commit::ChunkToCommit; use aptos_scratchpad::SparseMerkleTree; diff --git a/storage/storage-interface/src/state_store/mod.rs b/storage/storage-interface/src/state_store/mod.rs new file mode 100644 index 00000000000000..e6e30c86540527 --- /dev/null +++ b/storage/storage-interface/src/state_store/mod.rs @@ -0,0 +1,9 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +pub mod sharded_state_update_refs; +pub mod sharded_state_updates; +pub mod state_delta; +pub mod state_view; + +pub const NUM_STATE_SHARDS: usize = 16; diff --git a/storage/storage-interface/src/sharded_state_update_refs.rs b/storage/storage-interface/src/state_store/sharded_state_update_refs.rs similarity index 93% rename from storage/storage-interface/src/sharded_state_update_refs.rs rename to storage/storage-interface/src/state_store/sharded_state_update_refs.rs index f15824f3417927..f98ba4732c28ef 100644 --- a/storage/storage-interface/src/sharded_state_update_refs.rs +++ b/storage/storage-interface/src/state_store/sharded_state_update_refs.rs @@ -1,10 +1,10 @@ // Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -use crate::metrics::TIMER; +use crate::{metrics::TIMER, state_store::NUM_STATE_SHARDS}; use aptos_metrics_core::TimerHelper; use aptos_types::{ - state_store::{state_key::StateKey, state_value::StateValue, NUM_STATE_SHARDS}, + state_store::{state_key::StateKey, state_value::StateValue}, write_set::WriteSet, }; use arr_macro::arr; diff --git a/storage/storage-interface/src/state_store/sharded_state_updates.rs b/storage/storage-interface/src/state_store/sharded_state_updates.rs new file mode 100644 index 00000000000000..e7459db931d84c --- /dev/null +++ b/storage/storage-interface/src/state_store/sharded_state_updates.rs @@ -0,0 +1,60 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER; +use aptos_types::state_store::{state_key::StateKey, state_value::StateValue}; +use arr_macro::arr; +use rayon::iter::{ + IndexedParallelIterator, IntoParallelIterator, IntoParallelRefIterator, + IntoParallelRefMutIterator, ParallelIterator, +}; +use std::collections::HashMap; + +#[derive(Clone, Debug)] +pub struct ShardedStateUpdates { + pub shards: [HashMap>; 16], +} + +impl ShardedStateUpdates { + pub fn new_empty() -> Self { + Self { + shards: arr![HashMap::new(); 16], + } + } + + pub fn all_shards_empty(&self) -> bool { + self.shards.iter().all(|shard| shard.is_empty()) + } + + pub fn total_len(&self) -> usize { + self.shards.iter().map(|shard| shard.len()).sum() + } + + pub fn merge(&mut self, other: Self) { + self.shards + .par_iter_mut() + .zip_eq(other.shards.into_par_iter()) + .for_each(|(l, r)| { + l.extend(r); + }) + } + + pub fn clone_merge(&mut self, other: &Self) { + THREAD_MANAGER.get_exe_cpu_pool().install(|| { + self.shards + .par_iter_mut() + .zip_eq(other.shards.par_iter()) + .for_each(|(l, r)| { + l.extend(r.clone()); + }) + }) + } + + pub fn insert( + &mut self, + key: StateKey, + value: Option, + ) -> Option> { + self.shards[key.get_shard_id() as usize].insert(key, value) + } +} diff --git a/storage/storage-interface/src/state_delta.rs b/storage/storage-interface/src/state_store/state_delta.rs similarity index 95% rename from storage/storage-interface/src/state_delta.rs rename to storage/storage-interface/src/state_store/state_delta.rs index bffeb6e03ef996..6e5e0a456f3c75 100644 --- a/storage/storage-interface/src/state_delta.rs +++ b/storage/storage-interface/src/state_store/state_delta.rs @@ -1,13 +1,12 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 +use crate::state_store::sharded_state_updates::ShardedStateUpdates; use aptos_crypto::HashValue; use aptos_drop_helper::DropHelper; use aptos_scratchpad::SparseMerkleTree; use aptos_types::{ - state_store::{ - state_storage_usage::StateStorageUsage, state_value::StateValue, ShardedStateUpdates, - }, + state_store::{state_storage_usage::StateStorageUsage, state_value::StateValue}, transaction::Version, }; diff --git a/storage/storage-interface/src/async_proof_fetcher.rs b/storage/storage-interface/src/state_store/state_view/async_proof_fetcher.rs similarity index 100% rename from storage/storage-interface/src/async_proof_fetcher.rs rename to storage/storage-interface/src/state_store/state_view/async_proof_fetcher.rs diff --git a/storage/storage-interface/src/cached_state_view.rs b/storage/storage-interface/src/state_store/state_view/cached_state_view.rs similarity index 97% rename from storage/storage-interface/src/cached_state_view.rs rename to storage/storage-interface/src/state_store/state_view/cached_state_view.rs index cf9571cf10c445..271f395e9dd7c3 100644 --- a/storage/storage-interface/src/cached_state_view.rs +++ b/storage/storage-interface/src/state_store/state_view/cached_state_view.rs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - async_proof_fetcher::AsyncProofFetcher, metrics::TIMER, state_view::DbStateView, DbReader, + metrics::TIMER, + state_store::state_view::{async_proof_fetcher::AsyncProofFetcher, db_state_view::DbStateView}, + DbReader, }; use aptos_crypto::{hash::CryptoHash, HashValue}; use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER; @@ -10,7 +12,7 @@ use aptos_scratchpad::{FrozenSparseMerkleTree, SparseMerkleTree, StateStoreStatu use aptos_types::{ proof::SparseMerkleProofExt, state_store::{ - errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, StateViewId, TStateView, }, transaction::Version, @@ -35,7 +37,7 @@ static IO_POOL: Lazy = Lazy::new(|| { .unwrap() }); -type Result = std::result::Result; +type Result = std::result::Result; type StateCacheShard = DashMap, Option)>; // Sharded by StateKey.get_shard_id(). The version in the value indicates there is an entry on that @@ -163,7 +165,7 @@ impl CachedStateView { let speculative_state = speculative_state.freeze(&base_smt); let snapshot = reader .get_state_snapshot_before(next_version) - .map_err(Into::::into)?; + .map_err(Into::::into)?; Ok(Self::new_impl( id, diff --git a/storage/storage-interface/src/state_view.rs b/storage/storage-interface/src/state_store/state_view/db_state_view.rs similarity index 80% rename from storage/storage-interface/src/state_view.rs rename to storage/storage-interface/src/state_store/state_view/db_state_view.rs index 194cb42b56a697..5756a00db15e48 100644 --- a/storage/storage-interface/src/state_view.rs +++ b/storage/storage-interface/src/state_store/state_view/db_state_view.rs @@ -1,5 +1,4 @@ -// Copyright © Aptos Foundation -// Parts of the project are originally copyright © Meta Platforms, Inc. +// Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 use crate::DbReader; @@ -7,15 +6,13 @@ use aptos_crypto::{hash::CryptoHash, HashValue}; use aptos_types::{ ledger_info::LedgerInfo, state_store::{ - errors::StateviewError, state_key::StateKey, state_storage_usage::StateStorageUsage, - state_value::StateValue, TStateView, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + state_value::StateValue, StateViewResult, TStateView, }, transaction::Version, }; use std::sync::Arc; -type Result = std::result::Result; - #[derive(Clone)] pub struct DbStateView { db: Arc, @@ -26,7 +23,7 @@ pub struct DbStateView { } impl DbStateView { - fn get(&self, key: &StateKey) -> Result> { + fn get(&self, key: &StateKey) -> StateViewResult> { if let Some(version) = self.version { if let Some(root_hash) = self.maybe_verify_against_state_root_hash { // DB doesn't support returning proofs for buffered state, so only optionally @@ -49,11 +46,11 @@ impl DbStateView { impl TStateView for DbStateView { type Key = StateKey; - fn get_state_value(&self, state_key: &StateKey) -> Result> { + fn get_state_value(&self, state_key: &StateKey) -> StateViewResult> { self.get(state_key).map_err(Into::into) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> StateViewResult { self.db .get_state_storage_usage(self.version) .map_err(Into::into) @@ -61,27 +58,27 @@ impl TStateView for DbStateView { } pub trait LatestDbStateCheckpointView { - fn latest_state_checkpoint_view(&self) -> Result; + fn latest_state_checkpoint_view(&self) -> StateViewResult; } impl LatestDbStateCheckpointView for Arc { - fn latest_state_checkpoint_view(&self) -> Result { + fn latest_state_checkpoint_view(&self) -> StateViewResult { Ok(DbStateView { db: self.clone(), version: self .get_latest_state_checkpoint_version() - .map_err(Into::::into)?, + .map_err(Into::::into)?, maybe_verify_against_state_root_hash: None, }) } } pub trait DbStateViewAtVersion { - fn state_view_at_version(&self, version: Option) -> Result; + fn state_view_at_version(&self, version: Option) -> StateViewResult; } impl DbStateViewAtVersion for Arc { - fn state_view_at_version(&self, version: Option) -> Result { + fn state_view_at_version(&self, version: Option) -> StateViewResult { Ok(DbStateView { db: self.clone(), version, @@ -95,7 +92,7 @@ pub trait VerifiedStateViewAtVersion { &self, version: Option, ledger_info: &LedgerInfo, - ) -> Result; + ) -> StateViewResult; } impl VerifiedStateViewAtVersion for Arc { @@ -103,7 +100,7 @@ impl VerifiedStateViewAtVersion for Arc { &self, version: Option, ledger_info: &LedgerInfo, - ) -> Result { + ) -> StateViewResult { let db = self.clone(); if let Some(version) = version { @@ -115,7 +112,7 @@ impl VerifiedStateViewAtVersion for Arc { .proof .transaction_info .state_checkpoint_hash() - .ok_or_else(|| StateviewError::NotFound("state_checkpoint_hash".to_string()))?; + .ok_or_else(|| StateViewError::NotFound("state_checkpoint_hash".to_string()))?; Ok(DbStateView { db, diff --git a/storage/storage-interface/src/state_store/state_view/mod.rs b/storage/storage-interface/src/state_store/state_view/mod.rs new file mode 100644 index 00000000000000..8600b7101ed504 --- /dev/null +++ b/storage/storage-interface/src/state_store/state_view/mod.rs @@ -0,0 +1,7 @@ +// Copyright © Aptos Foundation +// Parts of the project are originally copyright © Meta Platforms, Inc. +// SPDX-License-Identifier: Apache-2.0 + +pub mod async_proof_fetcher; +pub mod cached_state_view; +pub mod db_state_view; diff --git a/types/Cargo.toml b/types/Cargo.toml index 26e8db6d587718..5296eb1af3eabf 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -18,7 +18,6 @@ aptos-bitvec = { workspace = true } aptos-crypto = { workspace = true } aptos-crypto-derive = { workspace = true } aptos-dkg = { workspace = true } -aptos-experimental-runtimes = { workspace = true } aptos-infallible = { workspace = true } arbitrary = { workspace = true, features = ["derive"], optional = true } ark-bn254 = { workspace = true } @@ -28,7 +27,6 @@ ark-groth16 = { workspace = true } ark-relations = { workspace = true } ark-serialize = { workspace = true } ark-std = { workspace = true } -arr_macro = { workspace = true } base64 = { workspace = true } bcs = { workspace = true } bytes = { workspace = true } diff --git a/types/src/state_store/errors.rs b/types/src/state_store/errors.rs index 838d6005192440..c0240d67c70fe6 100644 --- a/types/src/state_store/errors.rs +++ b/types/src/state_store/errors.rs @@ -5,7 +5,7 @@ use thiserror::Error; #[derive(Debug, Error)] -pub enum StateviewError { +pub enum StateViewError { #[error("{0} not found.")] NotFound(String), /// Other non-classified error. @@ -15,7 +15,7 @@ pub enum StateviewError { BcsError(#[from] bcs::Error), } -impl From for StateviewError { +impl From for StateViewError { fn from(error: anyhow::Error) -> Self { Self::Other(format!("{}", error)) } diff --git a/types/src/state_store/in_memory_state_view.rs b/types/src/state_store/in_memory_state_view.rs deleted file mode 100644 index a87320868f5324..00000000000000 --- a/types/src/state_store/in_memory_state_view.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © Aptos Foundation -// Parts of the project are originally copyright © Meta Platforms, Inc. -// SPDX-License-Identifier: Apache-2.0 - -use crate::state_store::{ - state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue, Result, - TStateView, -}; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; - -// A State view backed by in-memory hashmap. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct InMemoryStateView { - state_data: HashMap, -} - -impl InMemoryStateView { - pub fn new(state_data: HashMap) -> Self { - Self { state_data } - } -} - -impl TStateView for InMemoryStateView { - type Key = StateKey; - - fn get_state_value(&self, state_key: &StateKey) -> Result> { - Ok(self.state_data.get(state_key).cloned()) - } - - fn get_usage(&self) -> Result { - Ok(StateStorageUsage::new_untracked()) - } - - fn as_in_memory_state_view(&self) -> InMemoryStateView { - self.clone() - } -} diff --git a/types/src/state_store/mod.rs b/types/src/state_store/mod.rs index e85552c84cb861..7456b439d62870 100644 --- a/types/src/state_store/mod.rs +++ b/types/src/state_store/mod.rs @@ -4,31 +4,25 @@ use crate::{ account_address::AccountAddress, state_store::{ - errors::StateviewError, in_memory_state_view::InMemoryStateView, state_key::StateKey, - state_storage_usage::StateStorageUsage, state_value::StateValue, + errors::StateViewError, state_key::StateKey, state_storage_usage::StateStorageUsage, + state_value::StateValue, }, transaction::Version, }; use aptos_crypto::HashValue; -use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER; -use arr_macro::arr; use bytes::Bytes; use move_core_types::move_resource::MoveResource; -use rayon::prelude::*; #[cfg(any(test, feature = "testing"))] use std::hash::Hash; use std::{collections::HashMap, ops::Deref}; pub mod errors; -pub mod in_memory_state_view; pub mod state_key; pub mod state_storage_usage; pub mod state_value; pub mod table; -pub const NUM_STATE_SHARDS: usize = 16; - -pub type Result = std::result::Result; +pub type StateViewResult = std::result::Result; /// A trait that defines a read-only snapshot of the global state. It is passed to the VM for /// transaction execution, during which the VM is guaranteed to read anything at the given state. @@ -41,20 +35,16 @@ pub trait TStateView { } /// Gets the state value bytes for a given state key. - fn get_state_value_bytes(&self, state_key: &Self::Key) -> Result> { + fn get_state_value_bytes(&self, state_key: &Self::Key) -> StateViewResult> { let val_opt = self.get_state_value(state_key)?; Ok(val_opt.map(|val| val.bytes().clone())) } /// Gets the state value for a given state key. - fn get_state_value(&self, state_key: &Self::Key) -> Result>; + fn get_state_value(&self, state_key: &Self::Key) -> StateViewResult>; /// Get state storage usage info at epoch ending. - fn get_usage(&self) -> Result; - - fn as_in_memory_state_view(&self) -> InMemoryStateView { - unreachable!("in-memory state view conversion not supported yet") - } + fn get_usage(&self) -> StateViewResult; } pub trait StateView: TStateView {} @@ -91,11 +81,11 @@ where self.deref().id() } - fn get_state_value(&self, state_key: &K) -> Result> { + fn get_state_value(&self, state_key: &K) -> StateViewResult> { self.deref().get_state_value(state_key) } - fn get_usage(&self) -> Result { + fn get_usage(&self) -> StateViewResult { self.deref().get_usage() } } @@ -123,69 +113,23 @@ impl MockStateView { impl TStateView for MockStateView { type Key = K; - fn get_state_value(&self, state_key: &Self::Key) -> Result, StateviewError> { + fn get_state_value( + &self, + state_key: &Self::Key, + ) -> StateViewResult, StateViewError> { Ok(self.data.get(state_key).cloned()) } - fn get_usage(&self) -> std::result::Result { + fn get_usage(&self) -> std::result::Result { unimplemented!("Irrelevant for tests"); } } -#[derive(Clone, Debug)] -pub struct ShardedStateUpdates { - pub shards: [HashMap>; 16], -} - -impl ShardedStateUpdates { - pub fn new_empty() -> Self { - Self { - shards: arr![HashMap::new(); 16], - } - } - - pub fn all_shards_empty(&self) -> bool { - self.shards.iter().all(|shard| shard.is_empty()) - } - - pub fn total_len(&self) -> usize { - self.shards.iter().map(|shard| shard.len()).sum() - } - - pub fn merge(&mut self, other: Self) { - self.shards - .par_iter_mut() - .zip_eq(other.shards.into_par_iter()) - .for_each(|(l, r)| { - l.extend(r); - }) - } - - pub fn clone_merge(&mut self, other: &Self) { - THREAD_MANAGER.get_exe_cpu_pool().install(|| { - self.shards - .par_iter_mut() - .zip_eq(other.shards.par_iter()) - .for_each(|(l, r)| { - l.extend(r.clone()); - }) - }) - } - - pub fn insert( - &mut self, - key: StateKey, - value: Option, - ) -> Option> { - self.shards[key.get_shard_id() as usize].insert(key, value) - } -} - pub trait MoveResourceExt: MoveResource { fn fetch_move_resource( state_view: &dyn StateView, address: &AccountAddress, - ) -> Result> { + ) -> StateViewResult> { let state_key = StateKey::resource_typed::(address)?; Ok(state_view .get_state_value_bytes(&state_key)? diff --git a/vm-validator/src/unit_tests/vm_validator_test.rs b/vm-validator/src/unit_tests/vm_validator_test.rs index 62990d9d093dd1..f4bc8b915354d3 100644 --- a/vm-validator/src/unit_tests/vm_validator_test.rs +++ b/vm-validator/src/unit_tests/vm_validator_test.rs @@ -7,7 +7,9 @@ use aptos_cached_packages::aptos_stdlib; use aptos_crypto::{ed25519::Ed25519PrivateKey, PrivateKey, Uniform}; use aptos_db::AptosDB; use aptos_gas_schedule::{InitialGasSchedule, TransactionGasParameters}; -use aptos_storage_interface::{state_view::LatestDbStateCheckpointView, DbReaderWriter}; +use aptos_storage_interface::{ + state_store::state_view::db_state_view::LatestDbStateCheckpointView, DbReaderWriter, +}; use aptos_types::{ account_address, account_config, chain_id::ChainId, diff --git a/vm-validator/src/vm_validator.rs b/vm-validator/src/vm_validator.rs index 6fff21434fe050..aa3c90e2e8ac3e 100644 --- a/vm-validator/src/vm_validator.rs +++ b/vm-validator/src/vm_validator.rs @@ -5,8 +5,10 @@ use anyhow::Result; use aptos_logger::info; use aptos_storage_interface::{ - cached_state_view::CachedDbStateView, - state_view::{DbStateView, LatestDbStateCheckpointView}, + state_store::state_view::{ + cached_state_view::CachedDbStateView, + db_state_view::{DbStateView, LatestDbStateCheckpointView}, + }, DbReader, }; use aptos_types::{