diff --git a/crates/starknet_committer_and_os_cli/src/committer_cli/tests/python_tests.rs b/crates/starknet_committer_and_os_cli/src/committer_cli/tests/python_tests.rs index a7760d472d3..e1c869d3eab 100644 --- a/crates/starknet_committer_and_os_cli/src/committer_cli/tests/python_tests.rs +++ b/crates/starknet_committer_and_os_cli/src/committer_cli/tests/python_tests.rs @@ -30,8 +30,9 @@ use starknet_patricia::patricia_merkle_tree::node_data::inner_node::{ NodeData, PathToBottom, }; +use starknet_patricia::patricia_merkle_tree::node_data::leaf::Leaf; use starknet_patricia::patricia_merkle_tree::types::SubTreeHeight; -use starknet_patricia_storage::db_object::{DBObject, EmptyKeyContext}; +use starknet_patricia_storage::db_object::{DBObject, EmptyKeyContext, HasStaticPrefix}; use starknet_patricia_storage::errors::{DeserializationError, SerializationError}; use starknet_patricia_storage::map_storage::MapStorage; use starknet_patricia_storage::storage_trait::{DbKey, DbValue, Storage}; @@ -426,6 +427,14 @@ fn xor_hash(x: &[u8], y: &[u8]) -> Vec { x.iter().zip(y.iter()).map(|(a, b)| a ^ b).collect() } +fn db_key( + node: &FactDbFilledNode, + key_context: &::KeyContext, +) -> DbKey { + let suffix = node.hash.0.to_bytes_be(); + node.get_db_key(key_context, &suffix) +} + /// Creates and serializes storage keys for different node types. /// /// This function generates and serializes storage keys for various node types, including binary @@ -445,17 +454,17 @@ pub(crate) fn test_node_db_key() -> String { data: NodeData::Binary(BinaryData { left_data: hash, right_data: hash }), hash, }; - let binary_node_key = binary_node.db_key(&dummy_contract_address).0; + let binary_node_key = db_key(&binary_node, &dummy_contract_address).0; let edge_node: FactDbFilledNode = FactDbFilledNode { data: NodeData::Edge(EdgeData { bottom_data: hash, path_to_bottom: Default::default() }), hash, }; - let edge_node_key = edge_node.db_key(&dummy_contract_address).0; + let edge_node_key = db_key(&edge_node, &dummy_contract_address).0; let storage_leaf = FactDbFilledNode { data: NodeData::Leaf(StarknetStorageValue(zero)), hash }; - let storage_leaf_key = storage_leaf.db_key(&dummy_contract_address).0; + let storage_leaf_key = db_key(&storage_leaf, &dummy_contract_address).0; let state_tree_leaf = FactDbFilledNode { data: NodeData::Leaf(ContractState { @@ -465,11 +474,11 @@ pub(crate) fn test_node_db_key() -> String { }), hash, }; - let state_tree_leaf_key = state_tree_leaf.db_key(&EmptyKeyContext).0; + let state_tree_leaf_key = db_key(&state_tree_leaf, &EmptyKeyContext).0; let compiled_class_leaf = FactDbFilledNode { data: NodeData::Leaf(CompiledClassHash(zero)), hash }; - let compiled_class_leaf_key = compiled_class_leaf.db_key(&EmptyKeyContext).0; + let compiled_class_leaf_key = db_key(&compiled_class_leaf, &EmptyKeyContext).0; // Store keys in a HashMap. let mut map: HashMap> = HashMap::new(); @@ -544,7 +553,7 @@ async fn test_storage_node(data: HashMap) -> CommitterPythonTest // Store the binary node in the storage. rust_fact_storage .set( - binary_rust.db_key(&dummy_contract_address), + db_key(&binary_rust, &dummy_contract_address), binary_rust.serialize().map_err(|error| { PythonTestError::SpecificError(CommitterSpecificTestError::Serialization(error)) })?, @@ -578,7 +587,7 @@ async fn test_storage_node(data: HashMap) -> CommitterPythonTest // Store the edge node in the storage. rust_fact_storage .set( - edge_rust.db_key(&dummy_contract_address), + db_key(&edge_rust, &dummy_contract_address), edge_rust.serialize().map_err(|error| { PythonTestError::SpecificError(CommitterSpecificTestError::Serialization(error)) })?, @@ -601,7 +610,7 @@ async fn test_storage_node(data: HashMap) -> CommitterPythonTest // Store the storage leaf node in the storage. rust_fact_storage .set( - storage_leaf_rust.db_key(&dummy_contract_address), + db_key(&storage_leaf_rust, &dummy_contract_address), storage_leaf_rust.serialize().map_err(|error| { PythonTestError::SpecificError(CommitterSpecificTestError::Serialization(error)) })?, @@ -633,7 +642,7 @@ async fn test_storage_node(data: HashMap) -> CommitterPythonTest // Store the contract state leaf node in the storage. rust_fact_storage .set( - contract_state_leaf_rust.db_key(&EmptyKeyContext), + db_key(&contract_state_leaf_rust, &EmptyKeyContext), contract_state_leaf_rust.serialize().map_err(|error| { PythonTestError::SpecificError(CommitterSpecificTestError::Serialization(error)) })?, @@ -657,7 +666,7 @@ async fn test_storage_node(data: HashMap) -> CommitterPythonTest // Store the compiled class leaf node in the storage. rust_fact_storage .set( - compiled_class_leaf_rust.db_key(&EmptyKeyContext), + db_key(&compiled_class_leaf_rust, &EmptyKeyContext), compiled_class_leaf_rust.serialize().map_err(|error| { PythonTestError::SpecificError(CommitterSpecificTestError::Serialization(error)) })?, diff --git a/crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node_serde.rs b/crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node_serde.rs index 8035a7c8055..0697a9bba92 100644 --- a/crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node_serde.rs +++ b/crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node_serde.rs @@ -7,7 +7,7 @@ use starknet_patricia_storage::db_object::{ HasStaticPrefix, }; use starknet_patricia_storage::errors::{DeserializationError, SerializationResult}; -use starknet_patricia_storage::storage_trait::{DbKey, DbKeyPrefix, DbValue}; +use starknet_patricia_storage::storage_trait::{DbKeyPrefix, DbValue}; use starknet_types_core::felt::Felt; use crate::patricia_merkle_tree::filled_tree::node::{FactDbFilledNode, FilledNode}; @@ -44,18 +44,6 @@ impl From for DbKeyPrefix { } } -// TODO(Ariel, 14/12/2025): generalize this to both layouts (e.g. via a new trait). ATM db_key is -// only used in the filled tree serialize function, which assumes facts layout. -impl FactDbFilledNode { - pub fn suffix(&self) -> [u8; SERIALIZE_HASH_BYTES] { - self.hash.0.to_bytes_be() - } - - pub fn db_key(&self, key_context: &::KeyContext) -> DbKey { - self.get_db_key(key_context, &self.suffix()) - } -} - impl HasDynamicPrefix for FilledNode { // Inherit the KeyContext from the HasStaticPrefix implementation of the leaf. type KeyContext = ::KeyContext;