-
Notifications
You must be signed in to change notification settings - Fork 65
starknet_committer,starknet_patricia: layout-dependent FilledTree serialization #10988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
starknet_committer,starknet_patricia: layout-dependent FilledTree serialization #10988
Conversation
af9d87d to
fb3bd7a
Compare
4f377b7 to
81e3b32
Compare
3473676 to
9f2ba58
Compare
81e3b32 to
3c052e3
Compare
9f2ba58 to
3d47fa4
Compare
3c052e3 to
3653d2e
Compare
yoavGrs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yoavGrs reviewed 9 files and all commit messages, made 2 comments, and resolved 5 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArielElp and @nimrod-starkware).
crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node.rs line 22 at r6 (raw file):
/// While the same underlying type as `FactDbFilledNode`, this alias is not used in the context of /// the DB-represnentation of the node. pub type HashFilledNode<L> = FilledNode<L, HashOutput>;
Consider
Suggestion:
/// A node in an updated trie, where all the hashes were commputed. Used in the `FilledTree` trait.
///
/// While the same underlying type as `FactDbFilledNode`, this alias is not used in the context of
/// the DB-represnentation of the node.
pub type HashFilledNode<L> = FilledNode<L, HashOutput>;
pub type FactDbFilledNode<L> = HashFilledNode<L>;a6d209a to
921a6ab
Compare
2072f41 to
6e88a70
Compare
nimrod-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nimrod-starkware made 2 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArielElp).
crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node.rs line 18 at r6 (raw file):
pub type FactDbFilledNode<L> = FilledNode<L, HashOutput>; /// A node in an updated trie, where all the hashes were commputed. Used in the `FilledTree` trait.
In our terminology updated can be updated skeleton and can confuse.
Suggestion:
/// A node in a filled trie, where all the hashes were commputed. Used in the `FilledTree` trait.crates/starknet_committer/src/db/external_test_utils.rs line 43 at r6 (raw file):
sorted_leaf_indices, &config, &leaf_modifications.iter().map(|(k, v)| (*k, v.clone().into())).collect(),
works?
Suggestion:
&leaf_modifications.into_iter().map(|(k, v)| (k, v.into())).collect(),6e88a70 to
b85aed7
Compare
921a6ab to
3cfa249
Compare
b85aed7 to
1227dc3
Compare
ArielElp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArielElp made 2 comments.
Reviewable status: 8 of 9 files reviewed, 3 unresolved discussions (waiting on @nimrod-starkware and @yoavGrs).
crates/starknet_committer/src/db/external_test_utils.rs line 43 at r6 (raw file):
Previously, nimrod-starkware wrote…
works?
Here yes but it consumes leaf_modifications which is needed later.
crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node.rs line 18 at r6 (raw file):
Previously, nimrod-starkware wrote…
In our terminology updated can be updated skeleton and can confuse.
Done.
nimrod-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nimrod-starkware made 1 comment and resolved 2 discussions.
Reviewable status: 8 of 9 files reviewed, 1 unresolved discussion (waiting on @ArielElp and @yoavGrs).
ArielElp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArielElp resolved 1 discussion.
Reviewable status: 8 of 9 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @yoavGrs).
1558fa6 to
e91d422
Compare
3cfa249 to
a3bd7c3
Compare
dorimedini-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware reviewed 9 files and all commit messages, and made 6 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArielElp).
crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/tree.rs line 21 at r8 (raw file):
use crate::patricia_merkle_tree::updated_skeleton_tree::node::UpdatedSkeletonNode; use crate::patricia_merkle_tree::updated_skeleton_tree::tree::UpdatedSkeletonTree; #[cfg(test)]
revert line deletion
Suggestion:
use crate::patricia_merkle_tree::updated_skeleton_tree::tree::UpdatedSkeletonTree;
#[cfg(test)]crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/tree.rs line 57 at r8 (raw file):
pub struct FilledTreeImpl<L> where L: Leaf,
why this diff?
Code quote:
pub struct FilledTreeImpl<L>
where
L: Leaf,crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/tree.rs line 390 at r8 (raw file):
}) .collect::<Result<_, _>>() }
I don't like the cloning here
in a separate PR, can you check if serialize can be consuming?
if you add a get_all_nodes_owned method?
intuitively I'd say after serializing a trie you won't want to keep using the trie
Suggestion:
fn serialize<Layout: NodeLayoutFor<L>>(
self,
key_context: &<Layout::DbLeaf as HasStaticPrefix>::KeyContext,
) -> SerializationResult<DbHashMap> {
// This function iterates over each node in the tree, using the node's `db_key` as the
// hashmap key and the result of the node's `serialize` method as the value.
self.get_all_nodes_owned()
.into_iter()
.map(|(index, node)| {
let (db_key, node_db_object) =
Layout::get_db_object(index, key_context, node);
let db_value = node_db_object.serialize()?;
Ok((db_key, db_value))
})
.collect::<Result<_, _>>()
}crates/starknet_committer/src/db/forest_trait.rs line 134 at r8 (raw file):
<Layout as NodeLayoutFor<ContractState>>::DbLeaf: HasStaticPrefix<KeyContext = EmptyKeyContext>, <Layout as NodeLayoutFor<CompiledClassHash>>::DbLeaf: HasStaticPrefix<KeyContext = EmptyKeyContext>,
these trait bounds can (and should) be defined on the trait definition of Layout, right? this bound is always needed for every layout?
Code quote:
Layout: NodeLayoutFor<StarknetStorageValue>
+ NodeLayoutFor<ContractState>
+ NodeLayoutFor<CompiledClassHash>,
<Layout as NodeLayoutFor<StarknetStorageValue>>::DbLeaf:
HasStaticPrefix<KeyContext = ContractAddress>,
<Layout as NodeLayoutFor<ContractState>>::DbLeaf: HasStaticPrefix<KeyContext = EmptyKeyContext>,
<Layout as NodeLayoutFor<CompiledClassHash>>::DbLeaf:
HasStaticPrefix<KeyContext = EmptyKeyContext>,crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node.rs line 22 at r8 (raw file):
/// While the same underlying type as `FactDbFilledNode`, this alias is not used in the context of /// the DB-representation of the node. pub type HashFilledNode<L> = FilledNode<L, HashOutput>;
compiler won't block you from sending a HashFilledNode<L> to a FactDbFilledNode<L> API or vice-versa, right?
since that's the case, I think instead of another name for the same type, we just need a better name (more general?)
Code quote:
/// A node in a filled tree, where all the hashes were computed. Used in the `FilledTree` trait.
///
/// While the same underlying type as `FactDbFilledNode`, this alias is not used in the context of
/// the DB-representation of the node.
pub type HashFilledNode<L> = FilledNode<L, HashOutput>;crates/starknet_committer_and_os_cli/benches/main.rs line 52 at r8 (raw file):
runtime.block_on(tree_computation_flow::< StarknetStorageValue, FactsNodeLayout,
maybe add a TODO to make this benchmark generic...?
we want to be able to benchmark both layouts (we will use both in production).
I'm imagining something like fn single_tree_flow_benchmark<Layout>(..)
Code quote:
FactsNodeLayout,
dorimedini-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware made 1 comment and resolved 1 discussion.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArielElp).
crates/starknet_committer/src/db/forest_trait.rs line 134 at r8 (raw file):
Previously, dorimedini-starkware wrote…
these trait bounds can (and should) be defined on the trait definition of
Layout, right? this bound is always needed for every layout?
ah... next PR, I see
e91d422 to
660cdd6
Compare
ArielElp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArielElp made 2 comments.
Reviewable status: 8 of 9 files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs).
crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/node.rs line 22 at r8 (raw file):
Previously, dorimedini-starkware wrote…
compiler won't block you from sending a
HashFilledNode<L>to aFactDbFilledNode<L>API or vice-versa, right?
since that's the case, I think instead of another name for the same type, we just need a better name (more general?)
It won't, alias only helps you understand which type should be used where, but it doesn't stop you from using the "wrong" one.
If it helps, this PR https://reviewable.io/reviews/starkware-libs/sequencer/11644#- (last in the stack, after tests) uses a new wrapper of FilledNode for the DB type (not for naming reasons, only due to orphan rules, but this also helps your cause).
crates/starknet_patricia/src/patricia_merkle_tree/filled_tree/tree.rs line 21 at r8 (raw file):
Previously, dorimedini-starkware wrote…
revert line deletion
Done.
dorimedini-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorimedini-starkware reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @ArielElp).
a3bd7c3 to
27f9a13
Compare
660cdd6 to
0386f73
Compare
0386f73 to
2b9093b
Compare
27f9a13 to
2787ec6
Compare
f7663a9

No description provided.