Skip to content

refactor: remove unnecessary allow dead code #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/committer/src/block_committer/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::patricia_merkle_tree::updated_skeleton_tree::skeleton_forest::{
use crate::patricia_merkle_tree::updated_skeleton_tree::tree::UpdatedSkeletonTreeImpl;
use crate::storage::map_storage::MapStorage;

#[allow(dead_code)]
type BlockCommitmentResult<T> = Result<T, BlockCommitmentError<LeafDataImpl>>;

#[allow(dead_code)]
Expand Down
1 change: 0 additions & 1 deletion crates/committer/src/block_committer/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use thiserror::Error;

use crate::{forest_errors::ForestError, patricia_merkle_tree::node_data::leaf::LeafData};

#[allow(dead_code)]
#[derive(Debug, Error)]
pub(crate) enum BlockCommitmentError<L: LeafData> {
#[error(transparent)]
Expand Down
4 changes: 0 additions & 4 deletions crates/committer/src/block_committer/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ pub struct ContractAddress(pub Felt);
// TODO(Nimrod, 1/6/2024): Swap to starknet-types-core types once implemented.
pub struct StarknetStorageKey(pub Felt);

#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
pub struct StarknetStorageValue(pub Felt);

#[allow(dead_code)]
#[derive(Debug, Default, Eq, PartialEq)]
pub struct StateDiff {
pub address_to_class_hash: HashMap<ContractAddress, ClassHash>,
Expand All @@ -33,7 +31,6 @@ pub struct StateDiff {
HashMap<ContractAddress, HashMap<StarknetStorageKey, StarknetStorageValue>>,
}

#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
pub struct Input {
pub storage: HashMap<StorageKey, StorageValue>,
Expand All @@ -46,7 +43,6 @@ pub struct Input {
pub classes_trie_root_hash: HashOutput,
}

#[allow(dead_code)]
impl StateDiff {
pub(crate) fn accessed_addresses(&self) -> HashSet<&ContractAddress> {
HashSet::from_iter(
Expand Down
6 changes: 5 additions & 1 deletion crates/committer/src/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ impl std::ops::Mul for Felt {
}
}

#[allow(dead_code)]
impl Felt {
pub const ZERO: Felt = Felt(StarknetTypesFelt::ZERO);
#[allow(dead_code)]
pub(crate) const ONE: Felt = Felt(StarknetTypesFelt::ONE);
#[allow(dead_code)]
pub(crate) const TWO: Felt = Felt(StarknetTypesFelt::TWO);
#[allow(dead_code)]
pub(crate) const THREE: Felt = Felt(StarknetTypesFelt::THREE);
pub const MAX: Felt = Felt(StarknetTypesFelt::MAX);

Expand All @@ -84,10 +86,12 @@ impl Felt {
}

/// Raises `self` to the power of `exponent`.
#[allow(dead_code)]
pub(crate) fn pow(&self, exponent: impl Into<u128>) -> Self {
Self(self.0.pow(exponent.into()))
}

#[allow(dead_code)]
pub(crate) fn bits(&self) -> u8 {
self.0
.bits()
Expand Down
2 changes: 1 addition & 1 deletion crates/committer/src/hash/hash_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::felt::Felt;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct HashOutput(pub Felt);

#[allow(dead_code)]
impl HashOutput {
#[allow(dead_code)]
pub(crate) const ZERO: HashOutput = HashOutput(Felt::ZERO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ use std::collections::HashMap;
use tokio::task::JoinSet;

pub trait FilledForest<L: LeafData> {
#[allow(dead_code)]
/// Serialize each tree and store it.
fn write_to_storage(&self, storage: &mut impl Storage);
#[allow(dead_code)]

fn get_compiled_class_root_hash(&self) -> FilledTreeResult<HashOutput, L>;
#[allow(dead_code)]

fn get_contract_root_hash(&self) -> FilledTreeResult<HashOutput, L>;
}

Expand All @@ -33,7 +32,6 @@ pub struct FilledForestImpl {
}

impl FilledForest<LeafDataImpl> for FilledForestImpl {
#[allow(dead_code)]
fn write_to_storage(&self, storage: &mut impl Storage) {
// Serialize all trees to one hash map.
let new_db_objects = self
Expand All @@ -58,7 +56,6 @@ impl FilledForest<LeafDataImpl> for FilledForestImpl {
}

impl FilledForestImpl {
#[allow(dead_code)]
pub(crate) async fn create<
T: UpdatedSkeletonTree + 'static,
TH: TreeHashFunction<LeafDataImpl> + 'static,
Expand Down
2 changes: 0 additions & 2 deletions crates/committer/src/patricia_merkle_tree/filled_tree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ pub struct ClassHash(pub Felt);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Nonce(pub Felt);

#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CompiledClassHash(pub Felt);

#[allow(dead_code)]
#[derive(Clone, Debug, PartialEq, Eq)]
/// A node in a Patricia-Merkle tree which was modified during an update.
pub struct FilledNode<L: LeafData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub(crate) struct LeafCompiledClassToSerialize {
type FilledNodeSerializationResult = Result<StorageValue, SerializationError>;
type FilledNodeDeserializationResult = Result<FilledNode<LeafDataImpl>, DeserializationError>;

#[allow(dead_code)]
impl<L: LeafData> FilledNode<L> {
pub fn suffix(&self) -> [u8; SERIALIZE_HASH_BYTES] {
self.hash.0.to_bytes_be()
Expand Down
4 changes: 0 additions & 4 deletions crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub(crate) type FilledTreeResult<T, L> = Result<T, FilledTreeError<L>>;
/// data and hashes.
pub(crate) trait FilledTree<L: LeafData>: Sized {
/// Computes and returns the filled tree.
#[allow(dead_code)]
async fn create<TH: TreeHashFunction<LeafDataImpl> + 'static>(
updated_skeleton: impl UpdatedSkeletonTree + 'static,
leaf_modifications: LeafModifications<LeafDataImpl>,
Expand All @@ -40,10 +39,8 @@ pub(crate) trait FilledTree<L: LeafData>: Sized {
/// Serializes the current state of the tree into a hashmap,
/// where each key-value pair corresponds
/// to a storage key and its serialized storage value.
#[allow(dead_code)]
fn serialize(&self) -> HashMap<StorageKey, StorageValue>;

#[allow(dead_code)]
fn get_root_hash(&self) -> FilledTreeResult<HashOutput, L>;
}

Expand All @@ -64,7 +61,6 @@ impl FilledTreeImpl {
filled_tree_map
}

#[allow(dead_code)]
pub(crate) fn get_all_nodes(&self) -> &HashMap<NodeIndex, FilledNode<LeafDataImpl>> {
&self.tree_map
}
Expand Down
3 changes: 0 additions & 3 deletions crates/committer/src/patricia_merkle_tree/node_data/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ pub trait LeafData: Clone + Sync + Send + DBObject {
) -> impl Future<Output = LeafResult<Self>>;
}

#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ContractState {
pub nonce: Nonce,
pub storage_root_hash: HashOutput,
pub class_hash: ClassHash,
}

#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(any(test, feature = "testing"), derive(EnumDiscriminants))]
#[cfg_attr(any(test, feature = "testing"), strum_discriminants(derive(EnumIter)))]
Expand Down Expand Up @@ -67,7 +65,6 @@ impl LeafData for LeafDataImpl {
}
}

#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SkeletonLeaf {
Zero,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl<'a> SubTree<'a> {
}
}

#[allow(dead_code)]
impl OriginalSkeletonTreeImpl {
/// Fetches the Patricia witnesses, required to build the original skeleton tree from storage.
/// Given a list of subtrees, traverses towards their leaves and fetches all non-empty and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use thiserror::Error;

use crate::storage::errors::{DeserializationError, StorageError};

#[allow(dead_code)]
#[derive(Debug, Error)]
pub(crate) enum OriginalSkeletonTreeError {
#[error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::node_data::inner_node::PathToBottom;

#[allow(dead_code)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
/// A node in the structure of a Patricia-Merkle tree, before the update.
pub(crate) enum OriginalSkeletonNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ pub(crate) trait OriginalSkeletonForest {

#[derive(Debug, Eq, PartialEq)]
pub(crate) struct OriginalSkeletonForestImpl<T: OriginalSkeletonTree> {
#[allow(dead_code)]
pub(crate) classes_trie: T,
#[allow(dead_code)]
pub(crate) contracts_trie: T,
#[allow(dead_code)]
pub(crate) storage_tries: HashMap<ContractAddress, T>,
}

Expand Down
1 change: 0 additions & 1 deletion crates/committer/src/patricia_merkle_tree/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub(crate) fn random() -> ThreadRng {
/// Generates a random U256 number between low and high (exclusive).
/// Panics if low > high.
#[cfg(any(feature = "testing", test))]
#[allow(dead_code)]
pub fn get_random_u256<R: Rng>(rng: &mut R, low: U256, high: U256) -> U256 {
assert!(low < high);
let high_of_low = low.high();
Expand Down
2 changes: 0 additions & 2 deletions crates/committer/src/patricia_merkle_tree/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl NodeIndex {
/// [NodeIndex] constant that represents the root index.
pub const ROOT: Self = Self(U256::ONE);

#[allow(dead_code)]
/// [NodeIndex] constant that represents the first leaf index.
// TODO(Tzahi, 15/6/2024): Support height < 128 bits.
pub const FIRST_LEAF: Self = Self(U256::from_words(1_u128 << (Self::BITS - 1 - 128), 0));
Expand Down Expand Up @@ -90,7 +89,6 @@ impl NodeIndex {
Self::BITS - self.leading_zeros()
}

#[allow(dead_code)]
/// Get the LCA (Lowest Common Ancestor) of the two nodes.
pub(crate) fn get_lca(&self, other: &NodeIndex) -> NodeIndex {
if self == other {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl UpdatedSkeletonTreeImpl {
if leaf_indices.is_empty() {
match original_node {
OriginalSkeletonNode::Binary => unreachable!(
"Index {root_index:?} is an original Binary node without leaf modifications -
"Index {root_index:?} is an original Binary node without leaf modifications -
it should be a Sibling instead."
),
OriginalSkeletonNode::Edge(_)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::node_data::inner_node::PathToBottom;

#[allow(dead_code)]
/// A node in the structure of a Patricia-Merkle tree, after the update.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum UpdatedSkeletonNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonT
use crate::patricia_merkle_tree::types::{NodeIndex, TreeHeight};
use crate::patricia_merkle_tree::updated_skeleton_tree::tree::UpdatedSkeletonTree;

#[allow(dead_code)]
pub(crate) struct UpdatedSkeletonForestImpl<T: UpdatedSkeletonTree> {
#[allow(dead_code)]
pub(crate) classes_trie: T,
#[allow(dead_code)]
pub(crate) contracts_trie: T,
#[allow(dead_code)]
pub(crate) storage_tries: HashMap<ContractAddress, T>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ pub(crate) trait UpdatedSkeletonTree: Sized + Send + Sync {
) -> UpdatedSkeletonTreeResult<Self>;

/// Does the skeleton represents an empty-tree (i.e. all leaves are empty).
#[allow(dead_code)]
fn is_empty(&self) -> bool;

/// Returns an iterator over all (node index, node) pairs in the tree.
#[allow(dead_code)]
fn get_nodes(&self) -> impl Iterator<Item = (NodeIndex, UpdatedSkeletonNode)>;

/// Returns the node with the given index.
#[allow(dead_code)]
fn get_node(&self, index: NodeIndex) -> UpdatedSkeletonTreeResult<&UpdatedSkeletonNode>;
}

Expand Down
1 change: 0 additions & 1 deletion crates/committer/src/storage/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub enum SerializationError {
SerializeError(#[from] serde_json::Error),
}

#[allow(dead_code)]
#[derive(thiserror::Error, Debug)]
pub enum DeserializationError {
#[error("There is a key duplicate at {0} mapping.")]
Expand Down
6 changes: 0 additions & 6 deletions crates/committer/src/storage/storage_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use serde::{Serialize, Serializer};
use crate::felt::Felt;
use std::collections::HashMap;

#[allow(dead_code)]
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct StorageKey(pub Vec<u8>);

#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct StorageValue(pub Vec<u8>);

Expand All @@ -17,20 +15,16 @@ pub trait Storage: From<HashMap<StorageKey, StorageValue>> {

/// Sets value in storage. If key already exists, its value is overwritten and the old value is
/// returned.
#[allow(dead_code)]
fn set(&mut self, key: StorageKey, value: StorageValue) -> Option<StorageValue>;

/// Returns values from storage in same order of given keys. Value is None for keys that do not
/// exist.
#[allow(dead_code)]
fn mget(&self, keys: &[StorageKey]) -> Vec<Option<&StorageValue>>;

/// Sets values in storage.
#[allow(dead_code)]
fn mset(&mut self, key_to_value: HashMap<StorageKey, StorageValue>);

/// Deletes value from storage and returns its value if it exists. Returns None if not.
#[allow(dead_code)]
fn delete(&mut self, key: &StorageKey) -> Option<StorageValue>;
}

Expand Down
6 changes: 0 additions & 6 deletions crates/committer_cli/src/parse_input/raw_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use serde::Deserialize;
type RawFelt = [u8; 32];

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Input to the committer.
pub(crate) struct RawInput {
/// Storage. Will be casted to HashMap<vec<u8>, Vec<u8>> to simulate DB access.
Expand All @@ -15,30 +14,26 @@ pub(crate) struct RawInput {
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Fact storage entry.
pub(crate) struct RawStorageEntry {
pub key: Vec<u8>,
pub value: Vec<u8>,
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub(crate) struct RawFeltMapEntry {
pub key: RawFelt,
pub value: RawFelt,
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Represents storage updates. Later will be casted to HashMap<Felt, HashMap<Felt,Felt>> entry.
pub(crate) struct RawStorageUpdates {
pub address: RawFelt,
pub storage_updates: Vec<RawFeltMapEntry>,
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Represents current state leaf at the contract state tree. Later will be casted to
/// HashMap<Felt, (nonce, class_hash, storage_root_hash)> entry.
pub(crate) struct RawContractStateLeaf {
Expand All @@ -49,7 +44,6 @@ pub(crate) struct RawContractStateLeaf {
}

#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Represents state diff.
pub(crate) struct RawStateDiff {
/// Will be casted to HashMap<Felt, Felt>.
Expand Down
1 change: 0 additions & 1 deletion crates/committer_cli/src/parse_input/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod read_test;

type DeserializationResult<T> = Result<T, DeserializationError>;

#[allow(dead_code)]
pub(crate) fn parse_input(input: String) -> DeserializationResult<Input> {
serde_json::from_str::<RawInput>(&input)?.try_into()
}
Loading