Skip to content

Commit

Permalink
move the error file and fix the lib interface
Browse files Browse the repository at this point in the history
save progress

save_progress

save state_store progress

fix jellyfishmerkel tree crate

api

other craters

temp 2

concensus

temp

db
  • Loading branch information
areshand committed Jan 12, 2024
1 parent fc65fec commit d6cc15a
Show file tree
Hide file tree
Showing 127 changed files with 944 additions and 622 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rust-analyzer.rustfmt.extraArgs": [
"+nightly"
]
],
"rust-analyzer.showUnlinkedFileNotification": false
}
2 changes: 2 additions & 0 deletions Cargo.lock

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

26 changes: 16 additions & 10 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Context {
}

pub fn latest_state_view(&self) -> Result<DbStateView> {
self.db.latest_state_checkpoint_view()
Ok(self.db.latest_state_checkpoint_view()?)
}

pub fn latest_state_view_poem<E: InternalError>(
Expand Down Expand Up @@ -151,7 +151,7 @@ impl Context {
}

pub fn state_view_at_version(&self, version: Version) -> Result<DbStateView> {
self.db.state_view_at_version(Some(version))
Ok(self.db.state_view_at_version(Some(version))?)
}

pub fn chain_id(&self) -> ChainId {
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Context {
}

pub fn get_latest_ledger_info_with_signatures(&self) -> Result<LedgerInfoWithSignatures> {
self.db.get_latest_ledger_info()
Ok(self.db.get_latest_ledger_info()?)
}

pub fn get_state_value(&self, state_key: &StateKey, version: u64) -> Result<Option<Vec<u8>>> {
Expand Down Expand Up @@ -348,9 +348,14 @@ impl Context {
None,
version,
)?;

let kvs = iter
.by_ref()
.take(MAX_REQUEST_LIMIT as usize)
.map(|res| match res {
Ok((k, v)) => Ok((k, v)),
Err(res) => Err(anyhow::Error::from(res)),
})
.collect::<Result<_>>()?;
if iter.next().transpose()?.is_some() {
bail!("Too many state items under account ({:?}).", address);
Expand Down Expand Up @@ -396,7 +401,7 @@ impl Context {
Some(Err(format_err!( "storage prefix scan return inconsistent key ({:?})", k )))
}
},
Err(e) => Some(Err(e)),
Err(e) => Some(Err(e.into())),
})
.take(limit as usize + 1);
let kvs = resource_iter
Expand Down Expand Up @@ -483,7 +488,7 @@ impl Context {
Some(Err(format_err!( "storage prefix scan return inconsistent key ({:?})", k )))
}
},
Err(e) => Some(Err(e)),
Err(e) => Some(Err(e.into())),
})
.take(limit as usize + 1);
let kvs = module_iter
Expand Down Expand Up @@ -802,7 +807,7 @@ impl Context {
}

pub fn get_accumulator_root_hash(&self, version: u64) -> Result<HashValue> {
self.db.get_accumulator_root_hash(version)
Ok(self.db.get_accumulator_root_hash(version)?)
}

fn convert_into_transaction_on_chain_data(
Expand All @@ -826,15 +831,16 @@ impl Context {
ledger_version: u64,
) -> Result<Vec<EventWithVersion>> {
if let Some(start) = start {
self.db.get_events(
Ok(self.db.get_events(
event_key,
start,
Order::Ascending,
limit as u64,
ledger_version,
)
)?)
} else {
self.db
Ok(self
.db
.get_events(
event_key,
u64::MAX,
Expand All @@ -845,7 +851,7 @@ impl Context {
.map(|mut result| {
result.reverse();
result
})
})?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-aggregator/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where
&self,
state_key: &Self::Identifier,
) -> anyhow::Result<Option<StateValue>> {
self.get_state_value(state_key)
self.get_state_value(state_key).map_err(Into::into)
}
}

Expand Down
7 changes: 4 additions & 3 deletions aptos-move/aptos-validator-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use aptos_types::{
on_chain_config::ValidatorSet,
state_store::{
state_key::StateKey, state_storage_usage::StateStorageUsage, state_value::StateValue,
TStateView,
Result as StateViewResult, TStateView,
},
transaction::{Transaction, TransactionInfo, Version},
};
Expand Down Expand Up @@ -256,11 +256,12 @@ impl DebuggerStateView {
impl TStateView for DebuggerStateView {
type Key = StateKey;

fn get_state_value(&self, state_key: &StateKey) -> Result<Option<StateValue>> {
fn get_state_value(&self, state_key: &StateKey) -> StateViewResult<Option<StateValue>> {
self.get_state_value_internal(state_key, self.version)
.map_err(Into::into)
}

fn get_usage(&self) -> Result<StateStorageUsage> {
fn get_usage(&self) -> StateViewResult<StateStorageUsage> {
unimplemented!()
}
}
52 changes: 32 additions & 20 deletions aptos-move/aptos-validator-interface/src/storage_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use aptos_config::config::{
};
use aptos_db::AptosDB;
use aptos_framework::natives::code::PackageMetadata;
use aptos_storage_interface::{DbReader, MAX_REQUEST_LIMIT};
use aptos_storage_interface::{AptosDbError, DbReader, MAX_REQUEST_LIMIT};
use aptos_types::{
account_address::AccountAddress,
account_state::AccountState,
Expand All @@ -23,16 +23,19 @@ pub struct DBDebuggerInterface(Arc<dyn DbReader>);

impl DBDebuggerInterface {
pub fn open<P: AsRef<Path> + Clone>(db_root_path: P) -> Result<Self> {
Ok(Self(Arc::new(AptosDB::open(
StorageDirPaths::from_path(db_root_path),
true,
NO_OP_STORAGE_PRUNER_CONFIG,
RocksdbConfigs::default(),
false, /* indexer */
BUFFERED_STATE_TARGET_ITEMS,
DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD,
false, /* indexer async v2 */
)?)))
Ok(Self(Arc::new(
AptosDB::open(
StorageDirPaths::from_path(db_root_path),
true,
NO_OP_STORAGE_PRUNER_CONFIG,
RocksdbConfigs::default(),
false, /* indexer */
BUFFERED_STATE_TARGET_ITEMS,
DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD,
false, /* indexer async v2 */
)
.map_err(anyhow::Error::from)?,
)))
}
}

Expand All @@ -50,7 +53,8 @@ impl AptosValidatorInterface for DBDebuggerInterface {
let kvs = iter
.by_ref()
.take(MAX_REQUEST_LIMIT as usize)
.collect::<Result<_>>()?;
.collect::<Result<_, AptosDbError>>()
.map_err(Into::<anyhow::Error>::into)?;
if iter.next().is_some() {
bail!(
"Too many state items under state key prefix {:?}.",
Expand All @@ -65,7 +69,9 @@ impl AptosValidatorInterface for DBDebuggerInterface {
state_key: &StateKey,
version: Version,
) -> Result<Option<StateValue>> {
self.0.get_state_value_by_version(state_key, version)
self.0
.get_state_value_by_version(state_key, version)
.map_err(Into::into)
}

async fn get_committed_transactions(
Expand All @@ -75,8 +81,12 @@ impl AptosValidatorInterface for DBDebuggerInterface {
) -> Result<(Vec<Transaction>, Vec<TransactionInfo>)> {
let txn_iter = self.0.get_transaction_iterator(start, limit)?;
let txn_info_iter = self.0.get_transaction_info_iterator(start, limit)?;
let txns = txn_iter.collect::<Result<Vec<_>>>()?;
let txn_infos = txn_info_iter.collect::<Result<Vec<_>>>()?;
let txns = txn_iter
.map(|res| res.map_err(Into::into))
.collect::<Result<Vec<_>>>()?;
let txn_infos = txn_info_iter
.map(|res| res.map_err(Into::into))
.collect::<Result<Vec<_>>>()?;
ensure!(txns.len() == txn_infos.len());
Ok((txns, txn_infos))
}
Expand All @@ -101,7 +111,7 @@ impl AptosValidatorInterface for DBDebuggerInterface {
}

async fn get_latest_version(&self) -> Result<Version> {
self.0.get_latest_version()
self.0.get_latest_version().map_err(Into::into)
}

async fn get_version_by_account_sequence(
Expand All @@ -110,9 +120,11 @@ impl AptosValidatorInterface for DBDebuggerInterface {
seq: u64,
) -> Result<Option<Version>> {
let ledger_version = self.get_latest_version().await?;
Ok(self
.0
.get_account_transaction(account, seq, false, ledger_version)?
.map(|info| info.version))
self.0
.get_account_transaction(account, seq, false, ledger_version)
.map_or_else(
|e| Err(anyhow::Error::from(e)),
|tp| Ok(tp.map(|e| e.version)),
)
}
}
11 changes: 6 additions & 5 deletions aptos-move/aptos-vm-types/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use aptos_aggregator::{
};
use aptos_types::{
state_store::{
errors::StateviewError,
state_key::StateKey,
state_storage_usage::StateStorageUsage,
state_value::{StateValue, StateValueMetadata},
Expand Down Expand Up @@ -166,7 +167,7 @@ pub trait TModuleView {
pub trait StateStorageView {
fn id(&self) -> StateViewId;

fn get_usage(&self) -> anyhow::Result<StateStorageUsage>;
fn get_usage(&self) -> Result<StateStorageUsage, StateviewError>;
}

/// A fine-grained view of the state during execution.
Expand Down Expand Up @@ -237,7 +238,7 @@ where
state_key: &Self::Key,
_maybe_layout: Option<&Self::Layout>,
) -> anyhow::Result<Option<StateValue>> {
self.get_state_value(state_key)
self.get_state_value(state_key).map_err(Into::into)
}
}

Expand All @@ -248,7 +249,7 @@ where
type Key = StateKey;

fn get_module_state_value(&self, state_key: &Self::Key) -> anyhow::Result<Option<StateValue>> {
self.get_state_value(state_key)
self.get_state_value(state_key).map_err(Into::into)
}
}

Expand All @@ -260,8 +261,8 @@ where
self.id()
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
self.get_usage()
fn get_usage(&self) -> Result<StateStorageUsage, StateviewError> {
self.get_usage().map_err(Into::into)
}
}

Expand Down
10 changes: 7 additions & 3 deletions aptos-move/aptos-vm-types/src/resource_group_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ mod tests {
use super::*;
use crate::tests::utils::{mock_tag_0, mock_tag_1, mock_tag_2};
use aptos_types::state_store::{
state_storage_usage::StateStorageUsage, state_value::StateValue, TStateView,
errors::StateviewError, state_storage_usage::StateStorageUsage, state_value::StateValue,
TStateView,
};
use claims::{assert_gt, assert_none, assert_ok_eq, assert_some, assert_some_eq};
use std::cmp::max;
Expand Down Expand Up @@ -329,14 +330,17 @@ mod tests {
impl TStateView for MockStateView {
type Key = StateKey;

fn get_state_value(&self, state_key: &Self::Key) -> anyhow::Result<Option<StateValue>> {
fn get_state_value(
&self,
state_key: &Self::Key,
) -> Result<Option<StateValue>, StateviewError> {
Ok(self
.group
.get(state_key)
.map(|entry| StateValue::new_legacy(entry.blob.clone().into())))
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
fn get_usage(&self) -> Result<StateStorageUsage, StateviewError> {
unimplemented!();
}
}
Expand Down
3 changes: 2 additions & 1 deletion aptos-move/aptos-vm/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use aptos_types::{
aggregator::PanicError,
on_chain_config::{ConfigStorage, Features, OnChainConfig},
state_store::{
errors::StateviewError,
state_key::StateKey,
state_storage_usage::StateStorageUsage,
state_value::{StateValue, StateValueMetadata},
Expand Down Expand Up @@ -370,7 +371,7 @@ impl<'e, E: ExecutorView> StateStorageView for StorageAdapter<'e, E> {
self.executor_view.id()
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
fn get_usage(&self) -> Result<StateStorageUsage, StateviewError> {
self.executor_view.get_usage()
}
}
Expand Down
7 changes: 5 additions & 2 deletions aptos-move/aptos-vm/src/move_vm_ext/respawned_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use aptos_gas_algebra::Fee;
use aptos_types::{
aggregator::PanicError,
state_store::{
errors::StateviewError,
state_key::StateKey,
state_storage_usage::StateStorageUsage,
state_value::{StateValue, StateValueMetadata},
Expand Down Expand Up @@ -451,8 +452,10 @@ impl<'r> StateStorageView for ExecutorViewWithChangeSet<'r> {
self.base_executor_view.id()
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
anyhow::bail!("Unexpected access to get_usage()")
fn get_usage(&self) -> Result<StateStorageUsage, StateviewError> {
Err(StateviewError::Other(
"Unexpected access to get_usage()".to_string(),
))
}
}

Expand Down
10 changes: 7 additions & 3 deletions aptos-move/aptos-vm/src/move_vm_ext/write_op_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ mod tests {
use aptos_types::{
account_address::AccountAddress,
state_store::{
state_storage_usage::StateStorageUsage, state_value::StateValue, TStateView,
errors::StateviewError, state_storage_usage::StateStorageUsage,
state_value::StateValue, TStateView,
},
};
use aptos_vm_types::resource_group_adapter::{group_size_as_sum, GroupSizeKind};
Expand Down Expand Up @@ -423,11 +424,14 @@ mod tests {
impl TStateView for MockStateView {
type Key = StateKey;

fn get_state_value(&self, state_key: &Self::Key) -> anyhow::Result<Option<StateValue>> {
fn get_state_value(
&self,
state_key: &Self::Key,
) -> Result<Option<StateValue>, StateviewError> {
Ok(self.data.get(state_key).cloned())
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
fn get_usage(&self) -> Result<StateStorageUsage, StateviewError> {
unimplemented!();
}
}
Expand Down
Loading

0 comments on commit d6cc15a

Please sign in to comment.