Skip to content

Commit

Permalink
fix: cleanup, clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cchudant committed Sep 28, 2024
1 parent 6c84019 commit b0ff3da
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 152 deletions.
13 changes: 4 additions & 9 deletions src/trie/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
path::Path,
tree::{MerkleTree, NodeKey},
};
use crate::{id::Id, key_value_db::KeyValueDB, BitSlice, BonsaiDatabase, BonsaiStorageError};
use crate::{id::Id, key_value_db::KeyValueDB, BitSlice, BonsaiDatabase, BonsaiStorageError, Vec};
use core::{fmt, marker::PhantomData};
use starknet_types_core::{felt::Felt, hash::StarkHash};

Expand Down Expand Up @@ -88,7 +88,7 @@ impl<'a, H: StarkHash + Send + Sync, DB: BonsaiDatabase, ID: Id> MerkleTreeItera
self.current_nodes_heights
.push((node_id, self.current_path.len()));

let node = self.tree.node_storage.get_node_mut::<DB>(node_id)?;
let node = self.tree.get_node_mut::<DB>(node_id)?;
let (node_handle, path_matches) = match node {
Node::Binary(binary_node) => {
log::trace!(
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<'a, H: StarkHash + Send + Sync, DB: BonsaiDatabase, ID: Id> MerkleTreeItera
.load_node_handle(self.db, node_handle, &self.current_path)?;

// update parent ref
match self.tree.node_storage.get_node_mut::<DB>(node_id)? {
match self.tree.get_node_mut::<DB>(node_id)? {
Node::Binary(binary_node) => {
*binary_node.get_child_mut(Direction::from(
*self
Expand Down Expand Up @@ -191,12 +191,7 @@ impl<'a, H: StarkHash + Send + Sync, DB: BonsaiDatabase, ID: Id> MerkleTreeItera
} else {
// Start from tree root.
self.current_path.clear();
let Some(node_id) = self.tree.node_storage.load_root_node(
&self.tree.death_row,
&self.tree.identifier,
self.db,
)?
else {
let Some(node_id) = self.tree.load_root_node(self.db)? else {
// empty tree, not found
self.leaf_hash = None;
return Ok(());
Expand Down
21 changes: 9 additions & 12 deletions src/trie/proof.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use core::marker::PhantomData;

use super::{
merkle_node::{hash_binary_node, hash_edge_node, Direction},
path::Path,
tree::MerkleTree,
};
use crate::{
format,
id::Id,
key_value_db::KeyValueDB,
trie::{
Expand All @@ -15,6 +14,7 @@ use crate::{
},
BitSlice, BitVec, BonsaiDatabase, BonsaiStorageError, HashMap, HashSet,
};
use core::marker::PhantomData;
use hashbrown::hash_set;
use starknet_types_core::{felt::Felt, hash::StarkHash};

Expand Down Expand Up @@ -153,7 +153,7 @@ impl<H: StarkHash + Send + Sync> MerkleTree<H> {
node_id: NodeKey,
_prev_height: usize,
) -> Result<(), BonsaiStorageError<DB::DatabaseError>> {
let proof_node = match tree.node_storage.get_node_mut::<DB>(node_id)? {
let proof_node = match tree.get_node_mut::<DB>(node_id)? {
Node::Binary(binary_node) => {
let (left, right) = (binary_node.left, binary_node.right);
ProofNode::Binary {
Expand Down Expand Up @@ -253,14 +253,11 @@ mod tests {
.unwrap();

log::trace!("proof: {proof:?}");
assert_eq!(
proof
.verify_proof::<Pedersen>(
tree.root_hash(&bonsai_storage.tries.db).unwrap(),
[(bits![u8, Msb0; 0,0,0,1,0,0,0,0], ONE)]
)
.all(|v| v.into()),
true
);
assert!(proof
.verify_proof::<Pedersen>(
tree.root_hash(&bonsai_storage.tries.db).unwrap(),
[(bits![u8, Msb0; 0,0,0,1,0,0,0,0], ONE)]
)
.all(|v| v.into()));
}
}
Loading

0 comments on commit b0ff3da

Please sign in to comment.