From 619f5344252c132edee85ade94b3fa52fc0b90a8 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Wed, 27 Sep 2023 10:43:30 +0700 Subject: [PATCH] more fixes --- grovedb/src/batch/estimated_costs/average_case_costs.rs | 2 +- grovedb/src/batch/single_insert_cost_tests.rs | 5 +---- grovedb/src/batch/single_sum_item_insert_cost_tests.rs | 4 ++-- grovedb/src/operations/insert/mod.rs | 6 +++--- merk/src/tree/encoding.rs | 6 ++++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/grovedb/src/batch/estimated_costs/average_case_costs.rs b/grovedb/src/batch/estimated_costs/average_case_costs.rs index e6e58975..f3421e87 100644 --- a/grovedb/src/batch/estimated_costs/average_case_costs.rs +++ b/grovedb/src/batch/estimated_costs/average_case_costs.rs @@ -576,7 +576,7 @@ mod tests { seek_count: 5, // todo: why is this 5 storage_cost: StorageCost { added_bytes: 115, - replaced_bytes: 106, + replaced_bytes: 75, removed_bytes: NoStorageRemoval, }, storage_loaded_bytes: 109, diff --git a/grovedb/src/batch/single_insert_cost_tests.rs b/grovedb/src/batch/single_insert_cost_tests.rs index c7f79146..1dd2d43c 100644 --- a/grovedb/src/batch/single_insert_cost_tests.rs +++ b/grovedb/src/batch/single_insert_cost_tests.rs @@ -335,9 +335,6 @@ mod tests { // Replaced bytes // 37 + 36 = 74 (key is not replaced) //needs update - // We instead are getting 106, because we are paying for (+ hash - key byte - // size) this means 31 extra bytes. - // In reality though we really are replacing 106 bytes. TBD what to do. // Hash node calls 8 // 1 to get tree hash @@ -359,7 +356,7 @@ mod tests { seek_count: 5, storage_cost: StorageCost { added_bytes: 115, - replaced_bytes: 106, // todo: this should actually be less + replaced_bytes: 75, removed_bytes: NoStorageRemoval, }, storage_loaded_bytes: 71, // todo: verify and explain diff --git a/grovedb/src/batch/single_sum_item_insert_cost_tests.rs b/grovedb/src/batch/single_sum_item_insert_cost_tests.rs index 09ca5ee2..d1e13fea 100644 --- a/grovedb/src/batch/single_sum_item_insert_cost_tests.rs +++ b/grovedb/src/batch/single_sum_item_insert_cost_tests.rs @@ -209,7 +209,7 @@ mod tests { seek_count: 5, storage_cost: StorageCost { added_bytes: 124, - replaced_bytes: 106, // todo: this should actually be less + replaced_bytes: 75, removed_bytes: NoStorageRemoval, }, storage_loaded_bytes: 71, // todo: verify and explain @@ -287,7 +287,7 @@ mod tests { seek_count: 5, storage_cost: StorageCost { added_bytes: 124, - replaced_bytes: 107, // todo: this should actually be less + replaced_bytes: 84, removed_bytes: NoStorageRemoval, }, storage_loaded_bytes: 72, // todo: verify and explain diff --git a/grovedb/src/operations/insert/mod.rs b/grovedb/src/operations/insert/mod.rs index d691ea34..513e2098 100644 --- a/grovedb/src/operations/insert/mod.rs +++ b/grovedb/src/operations/insert/mod.rs @@ -886,7 +886,7 @@ mod tests { seek_count: 7, storage_cost: StorageCost { added_bytes: 170, - replaced_bytes: 209, // todo: verify + replaced_bytes: 217, removed_bytes: NoStorageRemoval }, storage_loaded_bytes: 232, @@ -955,7 +955,7 @@ mod tests { seek_count: 7, storage_cost: StorageCost { added_bytes: 170, - replaced_bytes: 211, // todo: verify + replaced_bytes: 217, // todo: verify removed_bytes: NoStorageRemoval }, storage_loaded_bytes: 237, @@ -1720,7 +1720,7 @@ mod tests { seek_count: 9, // todo: verify this storage_cost: StorageCost { added_bytes: 0, - replaced_bytes: 405, // todo: verify this + replaced_bytes: 409, // todo: verify this removed_bytes: NoStorageRemoval }, storage_loaded_bytes: 487, // todo verify this diff --git a/merk/src/tree/encoding.rs b/merk/src/tree/encoding.rs index e635cd8c..05788099 100644 --- a/merk/src/tree/encoding.rs +++ b/merk/src/tree/encoding.rs @@ -129,7 +129,8 @@ impl TreeNode { let mut tree_inner: TreeNodeInner = Decode::decode(input)?; tree_inner.kv.key = key; if let Some(value_defined_cost_fn) = value_defined_cost_fn { - tree_inner.kv.value_defined_cost = value_defined_cost_fn(input); + tree_inner.kv.value_defined_cost = + value_defined_cost_fn(tree_inner.kv.value.as_slice()); } self.inner = Box::new(tree_inner); Ok(()) @@ -145,7 +146,8 @@ impl TreeNode { let mut tree_inner: TreeNodeInner = Decode::decode(input)?; tree_inner.kv.key = key; if let Some(value_defined_cost_fn) = value_defined_cost_fn { - tree_inner.kv.value_defined_cost = value_defined_cost_fn(input); + tree_inner.kv.value_defined_cost = + value_defined_cost_fn(tree_inner.kv.value.as_slice()); } Ok(TreeNode::new_with_tree_inner(tree_inner)) }