-
Notifications
You must be signed in to change notification settings - Fork 4
feat(ds): implementing rv-825 #549
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| use crate::merkle_layer::hash; | ||
| use crate::merkle_layer::node::MavlNode; | ||
| use octez_riscv_data::hash::DIGEST_SIZE; | ||
| use std::collections::HashMap; | ||
| use std::sync::Arc; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| enum CommitOperationType { | ||
| Insert, | ||
| Remove, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| struct CommitOperation { | ||
| operation_type: CommitOperationType, | ||
| data: Option<Vec<u8>>, | ||
| } | ||
|
|
||
| impl CommitOperation { | ||
| fn insert_operation(data: Vec<u8>) -> Self { | ||
| Self { | ||
| operation_type: CommitOperationType::Insert, | ||
| data: Some(data), | ||
| } | ||
| } | ||
|
|
||
| fn remove_operation() -> Self { | ||
| Self { | ||
| operation_type: CommitOperationType::Remove, | ||
| data: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default)] | ||
| pub(crate) struct CommitOperationCollection { | ||
| collection: HashMap<[u8; DIGEST_SIZE], CommitOperation>, | ||
| } | ||
|
|
||
| impl CommitOperationCollection { | ||
| pub(crate) fn add_new_node_to_commit(&mut self, node: &Arc<MavlNode>) { | ||
| let node_hash: [u8; 32] = *hash(node).as_bytes(); | ||
| let serialized_node = node.encode_to_vec(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably not needed at this stage. |
||
| self.collection.insert( | ||
| node_hash, | ||
| CommitOperation::insert_operation(serialized_node), | ||
| ); | ||
| } | ||
|
|
||
| pub(crate) fn remove_node_from_commit(&mut self, node: &Arc<MavlNode>) { | ||
| let node_hash: [u8; 32] = *hash(node).as_bytes(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also should not hash here, but just store the key. But we should also take ownership of the data of the node, so here we probably want to serialise the data or just own the node by owning its |
||
| self.collection | ||
| .insert(node_hash, CommitOperation::remove_operation()); | ||
| } | ||
| } | ||
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.
I guess this is a bit too expensive to calculate here. We should store the key rather.