From 15f546991370ee00f555725e8331da45497cf56d Mon Sep 17 00:00:00 2001 From: amosStarkware <88497213+amosStarkware@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:41:09 +0200 Subject: [PATCH] chore: delete SerializeNode (#64) --- .../filled_tree/node_serde.rs | 17 +++-------------- .../node_data/leaf_serde.rs | 12 ++++-------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs b/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs index 80429aa8..585f6ac1 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs @@ -21,24 +21,13 @@ pub(crate) const STORAGE_LEAF_SIZE: usize = SERIALIZE_HASH_BYTES; // TODO(Aviv, 17/4/2024): add CompiledClassLeaf size. // TODO(Aviv, 17/4/2024): add StateTreeLeaf size. -// TODO(Amos, 1/5/2024): Delete SerializeNode, as it's no longer needed. -/// Enum to describe the serialized node. -#[allow(dead_code)] -pub(crate) enum SerializeNode { - Binary(Vec), - Edge(Vec), - CompiledClassLeaf(Vec), - StorageLeaf(Vec), - StateTreeLeaf(Vec), -} - impl FilledNode { /// This method serializes the filled node into a byte vector, where: /// - For binary nodes: Concatenates left and right hashes. /// - For edge nodes: Concatenates bottom hash, path, and path length. /// - For leaf nodes: use leaf.serialize() method. #[allow(dead_code)] - pub(crate) fn serialize(&self) -> FilledTreeResult { + pub(crate) fn serialize(&self) -> FilledTreeResult { match &self.data { NodeData::Binary(BinaryData { left_hash, @@ -50,7 +39,7 @@ impl FilledNode { // Concatenate left and right hashes. let serialized = [left, right].concat(); - Ok(SerializeNode::Binary(serialized)) + Ok(StorageValue(serialized)) } NodeData::Edge(EdgeData { @@ -64,7 +53,7 @@ impl FilledNode { // Concatenate bottom hash, path, and path length. let serialized = [bottom.to_vec(), path.to_vec(), length.to_vec()].concat(); - Ok(SerializeNode::Edge(serialized)) + Ok(StorageValue(serialized)) } NodeData::Leaf(leaf_data) => leaf_data.serialize(), diff --git a/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs b/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs index 22e8c0ff..9031792e 100644 --- a/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs +++ b/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; use crate::patricia_merkle_tree::errors::FilledTreeError; -use crate::patricia_merkle_tree::filled_tree::node_serde::SerializeNode; /// Temporary struct to serialize the leaf CompiledClass. /// Required to comply to existing storage layout. @@ -10,6 +9,7 @@ pub(crate) struct LeafCompiledClassToSerialize { pub(crate) compiled_class_hash: Felt, } use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::storage::storage_trait::StorageValue; use crate::types::Felt; impl LeafData { @@ -18,11 +18,9 @@ impl LeafData { /// - For storage values: serializes the value into a 32-byte vector. /// - For compiled class hashes or state tree tuples: creates a json string /// describing the leaf and cast it into a byte vector. - pub(crate) fn serialize(&self) -> Result { + pub(crate) fn serialize(&self) -> Result { match &self { - LeafData::StorageValue(value) => { - Ok(SerializeNode::StorageLeaf(value.as_bytes().to_vec())) - } + LeafData::StorageValue(value) => Ok(StorageValue(value.as_bytes().to_vec())), LeafData::CompiledClassHash(class_hash) => { // Create a temporary object to serialize the leaf into a JSON. @@ -34,9 +32,7 @@ impl LeafData { let json = serde_json::to_string(&temp_object_to_json)?; // Serialize the json into a byte vector. - Ok(SerializeNode::CompiledClassLeaf( - json.into_bytes().to_owned(), - )) + Ok(StorageValue(json.into_bytes().to_owned())) } LeafData::StateTreeTuple { .. } => {