Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
iammadab committed Sep 25, 2023
1 parent f4eb8d7 commit 7dabaab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
23 changes: 14 additions & 9 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,17 @@ impl fmt::Debug for GroveDbOp {
Element::SumTree(..) => "Patch Sum Tree".to_string(),
Element::SumItem(..) => "Patch Sum Item".to_string(),
},
Op::RefreshReference { reference_path_type, max_reference_hop, trust_refresh_reference, .. } => {
format!("Refresh Reference: path {:?}, max_hop {:?}, trust_reference {} ", reference_path_type, max_reference_hop, trust_refresh_reference)
},
Op::RefreshReference {
reference_path_type,
max_reference_hop,
trust_refresh_reference,
..
} => {
format!(
"Refresh Reference: path {:?}, max_hop {:?}, trust_reference {} ",
reference_path_type, max_reference_hop, trust_refresh_reference
)
}
Op::Delete => "Delete".to_string(),
Op::DeleteTree => "Delete Tree".to_string(),
Op::DeleteSumTree => "Delete Sum Tree".to_string(),
Expand Down Expand Up @@ -768,7 +776,7 @@ where
if recursions_allowed == 1 {
let referenced_element_value_hash_opt = cost_return_on_error!(
&mut cost,
merk.get_value_hash(key.as_ref(), false)
merk.get_value_hash(key.as_ref(), true)
.map_err(|e| Error::CorruptedData(e.to_string()))
);

Expand Down Expand Up @@ -924,7 +932,6 @@ where
trust_refresh_reference,
..
} => {
dbg!("In RefreshReference");
// We are pointing towards a reference that will be refreshed
let reference_info = if *trust_refresh_reference {
Some(reference_path_type)
Expand Down Expand Up @@ -1153,7 +1160,8 @@ where
let Element::Reference(path_reference, max_reference_hop, _) = &element else {
return Err(Error::InvalidInput(
"trying to refresh a an element that is not a reference",
)).wrap_with_cost(cost)
))
.wrap_with_cost(cost);
};

let merk_feature_type = if is_sum_tree {
Expand All @@ -1171,7 +1179,6 @@ where
)
.wrap_with_cost(OperationCost::default())
);
dbg!(&path_reference);
if path_reference.is_empty() {
return Err(Error::CorruptedReferencePathNotFound(
"attempting to refresh an empty reference".to_string(),
Expand Down Expand Up @@ -1403,8 +1410,6 @@ impl GroveDb {
} = batch_structure;
let mut current_level = last_level;

dbg!(&ops_by_level_paths);

let batch_apply_options = batch_apply_options.unwrap_or_default();
let stop_level = batch_apply_options.batch_pause_height.unwrap_or_default() as u32;

Expand Down
25 changes: 19 additions & 6 deletions grovedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,21 @@ impl GroveDb {

/// Method to check that the value_hash of Element::Tree nodes are computed
/// correctly.
pub fn verify_grovedb(&self, transaction: TransactionArg) -> HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)> {
pub fn verify_grovedb(
&self,
transaction: TransactionArg,
) -> HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)> {
if let Some(transaction) = transaction {
let root_merk = self
.open_transactional_merk_at_path(SubtreePath::empty(), transaction, None)
.unwrap()
.expect("should exist");
self.verify_merk_and_submerks_in_transaction(root_merk, &SubtreePath::empty(), None, transaction)
self.verify_merk_and_submerks_in_transaction(
root_merk,
&SubtreePath::empty(),
None,
transaction,
)
} else {
let root_merk = self
.open_non_transactional_merk_at_path(SubtreePath::empty(), None)
Expand Down Expand Up @@ -872,7 +880,7 @@ impl GroveDb {
if actual_value_hash != element_value_hash {
issues.insert(
path.derive_owned_with_child(key).to_vec(),
(actual_value_hash, element_value_hash, actual_value_hash)
(actual_value_hash, element_value_hash, actual_value_hash),
);
}
}
Expand All @@ -885,7 +893,7 @@ impl GroveDb {
merk: Merk<S>,
path: &SubtreePath<B>,
batch: Option<&'db StorageBatch>,
transaction: &Transaction
transaction: &Transaction,
) -> HashMap<Vec<Vec<u8>>, (CryptoHash, CryptoHash, CryptoHash)> {
let mut all_query = Query::new();
all_query.insert_all();
Expand Down Expand Up @@ -920,7 +928,12 @@ impl GroveDb {
(root_hash, combined_value_hash, element_value_hash),
);
}
issues.extend(self.verify_merk_and_submerks_in_transaction(inner_merk, &new_path_ref, batch, transaction));
issues.extend(self.verify_merk_and_submerks_in_transaction(
inner_merk,
&new_path_ref,
batch,
transaction,
));
} else if element.is_item() {
let (kv_value, element_value_hash) = merk
.get_value_and_value_hash(&key, true)
Expand All @@ -931,7 +944,7 @@ impl GroveDb {
if actual_value_hash != element_value_hash {
issues.insert(
path.derive_owned_with_child(key).to_vec(),
(actual_value_hash, element_value_hash, actual_value_hash)
(actual_value_hash, element_value_hash, actual_value_hash),
);
}
}
Expand Down

0 comments on commit 7dabaab

Please sign in to comment.