Skip to content

Commit 86f7afa

Browse files
starknet_committer: siblings from updated skeleton
1 parent b1c945d commit 86f7afa

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

crates/starknet_committer/src/block_committer/commit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ pub trait CommitBlockTrait: Send {
9595
)?;
9696
info!("Updated skeleton forest created successfully.");
9797

98+
// Flush siblings to cache.
99+
let _siblings = updated_forest.siblings();
100+
98101
// Compute the new hashes.
99102
let filled_forest = FilledForest::create::<TreeHashFunctionImpl>(
100103
updated_forest,

crates/starknet_committer/src/forest/updated_skeleton_forest.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::collections::HashMap;
22

33
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
4+
use starknet_api::hash::HashOutput;
45
use starknet_patricia::patricia_merkle_tree::node_data::leaf::{LeafModifications, SkeletonLeaf};
56
use starknet_patricia::patricia_merkle_tree::types::NodeIndex;
7+
use starknet_patricia::patricia_merkle_tree::updated_skeleton_tree::node::UpdatedSkeletonNode;
68
use starknet_patricia::patricia_merkle_tree::updated_skeleton_tree::tree::{
79
UpdatedSkeletonTree,
810
UpdatedSkeletonTreeImpl,
@@ -96,4 +98,35 @@ impl UpdatedSkeletonForest {
9698
SkeletonLeaf::NonZero
9799
}
98100
}
101+
102+
pub(crate) fn siblings(&self) -> Siblings {
103+
Siblings {
104+
classes_trie: Self::filter_siblings(&self.classes_trie),
105+
contracts_trie: Self::filter_siblings(&self.contracts_trie),
106+
storage_tries: self
107+
.storage_tries
108+
.iter()
109+
.map(|(address, trie)| (*address, Self::filter_siblings(trie)))
110+
.collect(),
111+
}
112+
}
113+
114+
fn filter_siblings(skeleton_tree: &UpdatedSkeletonTreeImpl) -> HashMap<NodeIndex, HashOutput> {
115+
skeleton_tree
116+
.get_nodes()
117+
.filter_map(|(index, node)| match node {
118+
UpdatedSkeletonNode::UnmodifiedSubTree(hash) => Some((index, hash)),
119+
_ => None,
120+
})
121+
.collect()
122+
}
123+
}
124+
125+
pub(crate) struct Siblings {
126+
#[allow(dead_code)]
127+
pub(crate) classes_trie: HashMap<NodeIndex, HashOutput>,
128+
#[allow(dead_code)]
129+
pub(crate) contracts_trie: HashMap<NodeIndex, HashOutput>,
130+
#[allow(dead_code)]
131+
pub(crate) storage_tries: HashMap<ContractAddress, HashMap<NodeIndex, HashOutput>>,
99132
}

0 commit comments

Comments
 (0)