Skip to content

Commit

Permalink
added missing_docs warning to storage crate
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed Oct 3, 2024
1 parent a1a2f05 commit b6d2063
Show file tree
Hide file tree
Showing 57 changed files with 479 additions and 26 deletions.
2 changes: 1 addition & 1 deletion execution_engine/src/runtime/mint_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
.read_addressable_entity_by_account_hash(account_hash)
.map_err(|err| {
error!(%err, "error reading addressable entity by account hash");
ProviderError::AddressableEntityByAccountHash(account_hash)
ProviderError::AccountHash(account_hash)
})
}

Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/runtime_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ where
) -> Result<Contract, ExecError> {
self.tracking_copy
.borrow_mut()
.get_legacy_contract(legacy_contract)
.get_contract(legacy_contract)
.map_err(Into::into)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ where
let req = TrieRequest::new(state_hash, None);
self.data_access_layer()
.trie(req)
.into_legacy()
.into_raw()
.unwrap()
.map(|bytes| bytesrepr::deserialize(bytes.into_inner().into()).unwrap())
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/binary_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ where
BinaryResponse::new_error(ErrorCode::FunctionDisabled, protocol_version)
} else {
let req = TrieRequest::new(trie_key, None);
match effect_builder.get_trie(req).await.into_legacy() {
match effect_builder.get_trie(req).await.into_raw() {
Ok(result) => BinaryResponse::from_value(
GetTrieFullResult::new(result.map(TrieRaw::into_inner)),
protocol_version,
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/contract_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl ContractRuntime {
let req = TrieRequest::new(trie_key, Some(chunk_index));
let maybe_raw = data_access_layer
.trie(req)
.into_legacy()
.into_raw()
.map_err(ContractRuntimeError::FailedToRetrieveTrieById)?;
let ret = match maybe_raw {
Some(raw) => Some(TrieOrChunk::new(raw.into(), chunk_index)?),
Expand Down
11 changes: 11 additions & 0 deletions storage/src/block_store/block_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ use super::error::BlockStoreError;

/// A block store that supports read/write operations consistently.
pub trait BlockStoreProvider {
/// Reader alias.
type Reader<'a>: BlockStoreTransaction
where
Self: 'a;
/// ReaderWriter alias.
type ReaderWriter<'a>: BlockStoreTransaction
where
Self: 'a;

/// Check out read only handle.
fn checkout_ro(&self) -> Result<Self::Reader<'_>, BlockStoreError>;
/// Check out read write handle.
fn checkout_rw(&mut self) -> Result<Self::ReaderWriter<'_>, BlockStoreError>;
}

/// Block store transaction.
pub trait BlockStoreTransaction {
/// Commit changes to the block store.
fn commit(self) -> Result<(), BlockStoreError>;
Expand All @@ -21,12 +26,18 @@ pub trait BlockStoreTransaction {
fn rollback(self);
}

/// Data reader definition.
pub trait DataReader<K, T> {
/// Read item at key.
fn read(&self, key: K) -> Result<Option<T>, BlockStoreError>;
/// Returns true if item exists at key, else false.
fn exists(&self, key: K) -> Result<bool, BlockStoreError>;
}

/// Data write definition.
pub trait DataWriter<K, T> {
/// Write item to store and return key.
fn write(&mut self, data: &T) -> Result<K, BlockStoreError>;
/// Delete item at key from store.
fn delete(&mut self, key: K) -> Result<(), BlockStoreError>;
}
1 change: 1 addition & 0 deletions storage/src/block_store/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use casper_types::{BlockHash, EraId, TransactionHash};
use std::fmt::Debug;
use thiserror::Error;

/// Block store error.
#[derive(Debug, Error)]
pub enum BlockStoreError {
/// Found a duplicate block entry of the specified height.
Expand Down
2 changes: 2 additions & 0 deletions storage/src/block_store/lmdb/indexed_lmdb_block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use casper_types::{
BlockSignatures, Digest, EraId, ProtocolVersion, Transaction, TransactionHash, Transfer,
};

/// Indexed lmdb block store.
#[derive(DataSize, Debug)]
pub struct IndexedLmdbBlockStore {
/// Block store
Expand Down Expand Up @@ -124,6 +125,7 @@ impl IndexedLmdbBlockStore {
Ok(())
}

/// Ctor.
pub fn new(
block_store: LmdbBlockStore,
hard_reset_to_start_of_era: Option<EraId>,
Expand Down
3 changes: 3 additions & 0 deletions storage/src/block_store/lmdb/lmdb_block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const OS_FLAGS: EnvironmentFlags = EnvironmentFlags::WRITE_MAP;
#[cfg(target_os = "macos")]
const OS_FLAGS: EnvironmentFlags = EnvironmentFlags::empty();

/// Lmdb block store.
#[derive(DataSize, Debug)]
pub struct LmdbBlockStore {
/// Storage location.
Expand Down Expand Up @@ -82,6 +83,7 @@ pub struct LmdbBlockStore {
}

impl LmdbBlockStore {
/// Ctor.
pub fn new(root_path: &Path, total_size: usize) -> Result<Self, BlockStoreError> {
// Create the environment and databases.
let env = new_environment(total_size, root_path)?;
Expand Down Expand Up @@ -127,6 +129,7 @@ impl LmdbBlockStore {
})
}

/// Write finality signatures.
pub fn write_finality_signatures(
&self,
txn: &mut RwTransaction,
Expand Down
2 changes: 2 additions & 0 deletions storage/src/block_store/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod block_provider;
mod error;
/// Block store lmdb logic.
pub mod lmdb;
/// Block store types.
pub mod types;

pub use block_provider::{BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter};
Expand Down
11 changes: 11 additions & 0 deletions storage/src/block_store/types/approvals_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct ApprovalsHashes {
}

impl ApprovalsHashes {
/// Ctor.
pub fn new(
block_hash: BlockHash,
approvals_hashes: Vec<ApprovalsHash>,
Expand All @@ -51,6 +52,7 @@ impl ApprovalsHashes {
}
}

/// Verify block.
pub fn verify(&self, block: &Block) -> Result<(), ApprovalsHashesValidationError> {
if *self.merkle_proof_approvals.key() != Key::ChecksumRegistry {
return Err(ApprovalsHashesValidationError::InvalidKeyType);
Expand Down Expand Up @@ -92,6 +94,7 @@ impl ApprovalsHashes {
Ok(())
}

/// Deploy ids.
pub(crate) fn deploy_ids(
&self,
v1_block: &BlockV1,
Expand All @@ -106,6 +109,7 @@ impl ApprovalsHashes {
.collect())
}

/// Transaction ids.
pub fn transaction_ids(
&self,
v2_block: &BlockV2,
Expand All @@ -119,10 +123,12 @@ impl ApprovalsHashes {
.collect()
}

/// Block hash.
pub fn block_hash(&self) -> &BlockHash {
&self.block_hash
}

/// Approvals hashes.
pub fn approvals_hashes(&self) -> Vec<ApprovalsHash> {
self.approvals_hashes.clone()
}
Expand Down Expand Up @@ -197,7 +203,9 @@ pub enum ApprovalsHashesValidationError {
/// The state root hash implied by the Merkle proof doesn't match that in the block.
#[error("state root hash implied by the Merkle proof doesn't match that in the block")]
StateRootHashMismatch {
/// Proof state root hash.
proof_state_root_hash: Digest,
/// Block state root hash.
block_state_root_hash: Digest,
},

Expand All @@ -212,10 +220,13 @@ pub enum ApprovalsHashesValidationError {
/// The approvals checksum provided doesn't match one calculated from the approvals.
#[error("provided approvals checksum doesn't match one calculated from the approvals")]
ApprovalsChecksumMismatch {
/// Computed approvals checksum.
computed_approvals_checksum: Digest,
/// Value in proof.
value_in_proof: Digest,
},

/// Variant mismatch.
#[error("mismatch in variants: {0:?}")]
#[data_size(skip)]
VariantMismatch(Box<dyn Debug + Send + Sync>),
Expand Down
4 changes: 4 additions & 0 deletions storage/src/block_store/types/block_hash_height_and_era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ use rand::Rng;
use casper_types::testing::TestRng;
use casper_types::{BlockHash, BlockHashAndHeight, EraId};

/// Aggregates block identifying information.
#[derive(Clone, Copy, Debug, DataSize)]
pub struct BlockHashHeightAndEra {
/// Block hash.
pub block_hash: BlockHash,
/// Block height.
pub block_height: u64,
/// EraId
pub era_id: EraId,
}

Expand Down
23 changes: 23 additions & 0 deletions storage/src/block_store/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,62 @@ pub(crate) use approvals_hashes::LegacyApprovalsHashes;
pub(crate) use deploy_metadata_v1::DeployMetadataV1;
pub(in crate::block_store) use transfers::Transfers;

/// Exeuction results.
pub type ExecutionResults = HashMap<TransactionHash, ExecutionResult>;

/// Transaction finalized approvals.
pub struct TransactionFinalizedApprovals {
/// Transaction hash.
pub transaction_hash: TransactionHash,
/// Finalized approvals.
pub finalized_approvals: BTreeSet<Approval>,
}

/// Block execution results.
pub struct BlockExecutionResults {
/// Block info.
pub block_info: BlockHashHeightAndEra,
/// Execution results.
pub exec_results: ExecutionResults,
}

/// Block transfers.
pub struct BlockTransfers {
/// Block hash.
pub block_hash: BlockHash,
/// Transfers.
pub transfers: Vec<Transfer>,
}

/// State store.
pub struct StateStore {
/// Key.
pub key: Cow<'static, [u8]>,
/// Value.
pub value: Vec<u8>,
}

/// State store key.
pub struct StateStoreKey(pub(super) Cow<'static, [u8]>);

impl StateStoreKey {
/// Ctor.
pub fn new(key: Cow<'static, [u8]>) -> Self {
StateStoreKey(key)
}
}

/// Block tip anchor.
pub struct Tip;

/// Latest switch block anchor.
pub struct LatestSwitchBlock;

/// Block height.
pub type BlockHeight = u64;

/// Switch block header alias.
pub type SwitchBlockHeader = BlockHeader;

/// Switch block alias.
pub type SwitchBlock = Block;
25 changes: 24 additions & 1 deletion storage/src/data_access_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,44 @@ use casper_types::{execution::Effects, Digest, EraId};
use crate::tracking_copy::TrackingCopy;

mod addressable_entity;
/// Auction provider.
pub mod auction;
/// Balance provider.
pub mod balance;
mod balance_hold;
/// Bids provider.
pub mod bids;
mod block_global;
/// Block rewards provider.
pub mod block_rewards;
mod entry_points;
/// Era validators provider.
pub mod era_validators;
mod execution_results_checksum;
mod fee;
mod flush;
/// Forced undelegate provider.
pub mod forced_undelegate;
mod genesis;
/// Handle fee provider.
pub mod handle_fee;
mod handle_refund;
mod key_prefix;
/// Mint provider.
pub mod mint;
/// Prefixed values provider.
pub mod prefixed_values;
mod protocol_upgrade;
/// Prune provider.
pub mod prune;
/// Query provider.
pub mod query;
mod round_seigniorage;
mod seigniorage_recipients;
/// Step provider.
pub mod step;
mod system_entity_registry;
/// Tagged values provider.
pub mod tagged_values;
mod total_supply;
mod trie;
Expand Down Expand Up @@ -75,37 +88,47 @@ pub use system_entity_registry::{
pub use total_supply::{TotalSupplyRequest, TotalSupplyResult};
pub use trie::{PutTrieRequest, PutTrieResult, TrieElement, TrieRequest, TrieResult};

/// Block placeholder.
pub struct Block {
_era_id: EraId,
}

/// Block provider definition.
pub trait BlockProvider {
/// Block provider error type.
type Error;

/// Read block by height.
fn read_block_by_height(&self, _height: usize) -> Result<Option<Block>, Self::Error> {
// TODO: We need to implement this
todo!()
}
}

/// Anchor struct for block store functionality.
#[derive(Default, Copy, Clone)]
pub struct BlockStore(());

impl BlockStore {
/// Ctor.
pub fn new() -> Self {
BlockStore(())
}
}

// We're currently putting it here, but in future it needs to move to its own crate.
/// Data access layer.
#[derive(Copy, Clone)]
pub struct DataAccessLayer<S> {
/// Block store instance.
pub block_store: BlockStore,
/// Memoized state.
pub state: S,
/// Max query depth.
pub max_query_depth: u64,
}

impl<S> DataAccessLayer<S> {
/// Returns reference to current state of the data access layer.
pub fn state(&self) -> &S {
&self.state
}
Expand Down
1 change: 1 addition & 0 deletions storage/src/data_access_layer/addressable_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum AddressableEntityResult {
/// An addressable entity.
entity: AddressableEntity,
},
/// Failure.
Failure(TrackingCopyError),
}

Expand Down
Loading

0 comments on commit b6d2063

Please sign in to comment.