Skip to content

Commit 9bfb5dc

Browse files
committed
starknet_committer: abstract original tree creation
1 parent 2b2faca commit 9bfb5dc

File tree

11 files changed

+490
-435
lines changed

11 files changed

+490
-435
lines changed

crates/starknet_committer/src/db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod external_test_utils;
44
pub mod facts_db;
55
pub mod forest_trait;
66
pub mod index_db;
7+
pub mod trie_traversal;
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
use starknet_api::hash::HashOutput;
12
use starknet_patricia::patricia_merkle_tree::filled_tree::node::FilledNode;
23
use starknet_patricia::patricia_merkle_tree::node_data::leaf::Leaf;
4+
use starknet_patricia::patricia_merkle_tree::traversal::SubTreeTrait;
5+
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices};
6+
use starknet_patricia_storage::db_object::HasStaticPrefix;
37
use starknet_patricia_storage::errors::DeserializationError;
48
use starknet_patricia_storage::storage_trait::DbValue;
59

6-
pub trait NodeLayout<L: Leaf> {
10+
use crate::db::index_db::leaves::TrieType;
11+
12+
pub trait NodeLayout<'a, L: Leaf> {
713
type ChildData: Copy;
814
type DeserializationContext;
15+
type SubTree: SubTreeTrait<'a, NodeData = Self::ChildData, NodeContext = Self::DeserializationContext>;
916
fn deserialize_node(
1017
value: &DbValue,
1118
deserialize_context: &Self::DeserializationContext,
1219
) -> Result<FilledNode<L, Self::ChildData>, DeserializationError>;
20+
fn create_subtree(
21+
sorted_leaf_indices: SortedLeafIndices<'a>,
22+
root_index: NodeIndex,
23+
root_hash: HashOutput,
24+
) -> Self::SubTree;
25+
fn generate_key_context(trie_type: TrieType) -> <L as HasStaticPrefix>::KeyContext;
1326
}

crates/starknet_committer/src/db/external_test_utils.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ use starknet_patricia::patricia_merkle_tree::updated_skeleton_tree::tree::{
1515
UpdatedSkeletonTree,
1616
UpdatedSkeletonTreeImpl,
1717
};
18-
use starknet_patricia_storage::db_object::HasStaticPrefix;
18+
use starknet_patricia_storage::db_object::{EmptyKeyContext, HasStaticPrefix};
1919
use starknet_patricia_storage::map_storage::MapStorage;
2020

21-
use crate::db::facts_db::create_facts_tree::create_original_skeleton_tree;
21+
use crate::db::facts_db::db::FactsNodeLayout;
22+
use crate::db::trie_traversal::create_original_skeleton_tree;
2223

2324
pub async fn tree_computation_flow<L, TH>(
2425
leaf_modifications: LeafModifications<L>,
@@ -28,17 +29,17 @@ pub async fn tree_computation_flow<L, TH>(
2829
) -> FilledTreeImpl<L>
2930
where
3031
TH: TreeHashFunction<L> + 'static,
31-
L: Leaf + HasStaticPrefix<KeyContext = ()> + 'static,
32+
L: Leaf + HasStaticPrefix<KeyContext = EmptyKeyContext> + 'static,
3233
{
3334
let mut sorted_leaf_indices: Vec<NodeIndex> = leaf_modifications.keys().copied().collect();
3435
let sorted_leaf_indices = SortedLeafIndices::new(&mut sorted_leaf_indices);
35-
let mut original_skeleton = create_original_skeleton_tree(
36+
let mut original_skeleton = create_original_skeleton_tree::<L, FactsNodeLayout>(
3637
storage,
3738
root_hash,
3839
sorted_leaf_indices,
3940
&config,
4041
&leaf_modifications,
41-
&(),
42+
&EmptyKeyContext,
4243
)
4344
.await
4445
.expect("Failed to create the original skeleton tree");
@@ -66,7 +67,7 @@ where
6667
}
6768

6869
pub async fn single_tree_flow_test<
69-
L: Leaf + HasStaticPrefix<KeyContext = ()> + 'static,
70+
L: Leaf + HasStaticPrefix<KeyContext = EmptyKeyContext> + 'static,
7071
TH: TreeHashFunction<L> + 'static,
7172
>(
7273
leaf_modifications: LeafModifications<L>,
@@ -90,7 +91,7 @@ pub async fn single_tree_flow_test<
9091
let json_hash = &json!(hash_result.0.to_hex_string());
9192
result_map.insert("root_hash", json_hash);
9293
// Serlialize the storage modifications.
93-
let json_storage = &json!(filled_tree.serialize(&()));
94+
let json_storage = &json!(filled_tree.serialize(&EmptyKeyContext));
9495
result_map.insert("storage_changes", json_storage);
9596
serde_json::to_string(&result_map).expect("serialization failed")
9697
}

0 commit comments

Comments
 (0)