-
Notifications
You must be signed in to change notification settings - Fork 74
starknet_committer: add patricia paths forest reader/writer traits #13995
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
crates/starknet_committer/src/db/forest_trait_witnesses.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use async_trait::async_trait; | ||
| use starknet_api::block::BlockNumber; | ||
| use starknet_api::hash::HashOutput; | ||
| use starknet_patricia::patricia_merkle_tree::traversal::TraversalResult; | ||
| use starknet_patricia::patricia_merkle_tree::types::NodeIndex; | ||
| use starknet_patricia_storage::errors::SerializationResult; | ||
| use starknet_patricia_storage::storage_trait::{DbHashMap, DbValue}; | ||
|
|
||
| use super::{ | ||
| EmptyInitialReadContext, | ||
| ForestMetadataType, | ||
| ForestReader, | ||
| ForestWriterWithMetadata, | ||
| StorageInitializer, | ||
| }; | ||
| use crate::forest::deleted_nodes::DeletedNodes; | ||
| use crate::forest::filled_forest::FilledForest; | ||
| use crate::forest::forest_errors::ForestResult; | ||
| use crate::patricia_merkle_tree::tree::SortedLeafIndices; | ||
| use crate::patricia_merkle_tree::types::StarknetForestProofs; | ||
|
|
||
| /// The information required to write Patricia proofs to the database. | ||
| pub struct PatriciaProofsWrite { | ||
| pub block_number: BlockNumber, | ||
| pub keys_digest: [u8; 32], | ||
| pub witnesses: StarknetForestProofs, | ||
| } | ||
|
|
||
| /// Patricia proofs DB operation, which can be either delete or write. | ||
| /// Expected by [ForestWriterWithMetadataAndWitnesses::write_with_metadata_and_witnesses], which | ||
| /// accumulates all DB operations to guarantee atomicity. | ||
| pub enum PatriciaProofsUpdate { | ||
| Write(PatriciaProofsWrite), | ||
| Delete(BlockNumber), | ||
| } | ||
|
|
||
| /// Reads committed OS-input witness payload (structured [`StarknetForestProofs`]) for a block | ||
| /// height. | ||
| #[async_trait] | ||
| pub trait ForestReaderWithWitnesses: | ||
| ForestReader<InitialReadContext: EmptyInitialReadContext> + Send | ||
| { | ||
| async fn read_witnesses( | ||
| &mut self, | ||
| height: BlockNumber, | ||
| ) -> ForestResult<Option<StarknetForestProofs>>; | ||
|
|
||
| /// Fetches Patricia witness paths for OS input, optionally staging serialized trie node KVs on | ||
| /// an in-memory overlay so reads match post-commit state before the forest is persisted. | ||
| async fn fetch_patricia_witnesses( | ||
| &mut self, | ||
| classes_trie_root_hash: HashOutput, | ||
| contracts_trie_root_hash: HashOutput, | ||
| class_sorted_leaf_indices: SortedLeafIndices<'_>, | ||
| contract_sorted_leaf_indices: SortedLeafIndices<'_>, | ||
| contract_storage_sorted_leaf_indices: &HashMap<NodeIndex, SortedLeafIndices<'_>>, | ||
| staged_serialized_forest: Option<DbHashMap>, | ||
| ) -> TraversalResult<StarknetForestProofs>; | ||
| } | ||
|
|
||
| /// Writes forest + metadata + deleted nodes, and applies [`PatriciaProofsUpdate`] in the same | ||
| /// batch. | ||
| #[async_trait] | ||
| pub trait ForestWriterWithMetadataAndWitnesses: ForestWriterWithMetadata + Send { | ||
| async fn write_with_metadata_and_witnesses( | ||
| &mut self, | ||
| filled_forest: &FilledForest, | ||
| metadata: HashMap<ForestMetadataType, DbValue>, | ||
| deleted_nodes: DeletedNodes, | ||
| patricia_proofs_update: PatriciaProofsUpdate, | ||
| ) -> SerializationResult<usize>; | ||
| } | ||
|
|
||
| /// Forest storage with empty [`ForestReader::InitialReadContext`] plus OS-input witness read/write. | ||
| pub trait ForestStorageWithWitnesses: | ||
| ForestReaderWithWitnesses + ForestWriterWithMetadataAndWitnesses + StorageInitializer | ||
| { | ||
| } | ||
|
|
||
| impl<T> ForestStorageWithWitnesses for T where | ||
| T: ForestReaderWithWitnesses + ForestWriterWithMetadataAndWitnesses + StorageInitializer | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.