diff --git a/crates/committer/src/hash/types.rs b/crates/committer/src/hash/types.rs index 5b9ebeeb..95315659 100644 --- a/crates/committer/src/hash/types.rs +++ b/crates/committer/src/hash/types.rs @@ -6,6 +6,7 @@ use crate::types::Felt; pub(crate) struct HashInputPair(pub Felt, pub Felt); #[allow(dead_code)] +#[derive(Clone, Copy)] pub(crate) struct HashOutput(pub Felt); #[allow(dead_code)] diff --git a/crates/committer/src/patricia_merkle_tree/errors.rs b/crates/committer/src/patricia_merkle_tree/errors.rs index f276d5a3..49c6aba4 100644 --- a/crates/committer/src/patricia_merkle_tree/errors.rs +++ b/crates/committer/src/patricia_merkle_tree/errors.rs @@ -5,5 +5,6 @@ pub(crate) enum CurrentSkeletonTreeError {} #[derive(Debug)] pub(crate) enum UpdatedSkeletonTreeError {} -#[derive(Debug)] -pub(crate) enum FilledTreeError {} +pub(crate) enum FilledTreeError { + MissingRoot, +} diff --git a/crates/committer/src/patricia_merkle_tree/filled_node.rs b/crates/committer/src/patricia_merkle_tree/filled_node.rs index 6cd72000..e82d2693 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_node.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_node.rs @@ -9,7 +9,7 @@ pub(crate) struct Nonce(pub Felt); #[allow(dead_code)] /// A node in a Patricia-Merkle tree which was modified during an update. pub(crate) struct FilledNode { - hash: HashOutput, + pub(crate) hash: HashOutput, data: NodeData, } diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree.rs b/crates/committer/src/patricia_merkle_tree/filled_tree.rs index 612b5ddd..7e0c04c2 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree.rs @@ -2,10 +2,10 @@ use std::collections::HashMap; use std::collections::HashSet; use std::sync::Mutex; +use crate::hash::types::HashOutput; use crate::patricia_merkle_tree::errors::FilledTreeError; use crate::patricia_merkle_tree::filled_node::FilledNode; -use crate::patricia_merkle_tree::types::LeafDataTrait; -use crate::patricia_merkle_tree::types::NodeIndex; +use crate::patricia_merkle_tree::types::{LeafDataTrait, NodeIndex}; use crate::storage::storage_trait::Storage; /// Consider a Patricia-Merkle Tree which has been updated with new leaves. @@ -29,4 +29,11 @@ impl FilledTreeImpl { fn get_all_nodes(&self) -> &HashMap>> { &self.tree_map } + + fn get_root_hash(&self) -> Result { + match self.tree_map.get(&NodeIndex::root_index()) { + Some(root_node) => Ok(root_node.lock().expect("Lock poisned.").hash), + None => Err(FilledTreeError::MissingRoot), + } + } } diff --git a/crates/committer/src/patricia_merkle_tree/types.rs b/crates/committer/src/patricia_merkle_tree/types.rs index aebfa03c..7ec32b64 100644 --- a/crates/committer/src/patricia_merkle_tree/types.rs +++ b/crates/committer/src/patricia_merkle_tree/types.rs @@ -15,7 +15,7 @@ pub(crate) trait TreeHashFunction { } #[allow(dead_code)] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct NodeIndex(pub Felt); #[allow(dead_code)]