diff --git a/grovedb/src/batch/estimated_costs/average_case_costs.rs b/grovedb/src/batch/estimated_costs/average_case_costs.rs index f3421e87..64653793 100644 --- a/grovedb/src/batch/estimated_costs/average_case_costs.rs +++ b/grovedb/src/batch/estimated_costs/average_case_costs.rs @@ -723,7 +723,7 @@ mod tests { seek_count: 41, storage_cost: StorageCost { added_bytes: 0, - replaced_bytes: 5625, + replaced_bytes: 5594, removed_bytes: NoStorageRemoval, }, storage_loaded_bytes: 7669, diff --git a/merk/src/estimated_costs/average_case_costs.rs b/merk/src/estimated_costs/average_case_costs.rs index 53d6cc9b..099978fa 100644 --- a/merk/src/estimated_costs/average_case_costs.rs +++ b/merk/src/estimated_costs/average_case_costs.rs @@ -461,16 +461,16 @@ pub fn add_average_case_merk_propagate( estimated_sum_trees, average_flags_size, ) => { - let flags_len = average_flags_size.unwrap_or(0); - // it is normal to have LAYER_COST_SIZE here, as we add estimated sum tree // additions right after - let value_len = LAYER_COST_SIZE + flags_len; + let value_len = LAYER_COST_SIZE + + average_flags_size + .map_or(0, |flags_len| flags_len + flags_len.required_space() as u32); // in order to simplify calculations we get the estimated size and remove the // cost for the basic merk let sum_tree_addition = estimated_sum_trees.estimated_size()?; nodes_updated - * (KV::value_byte_cost_size_for_key_and_raw_value_lengths( + * (KV::layered_value_byte_cost_size_for_key_and_value_lengths( *average_key_size as u32, value_len, *is_sum_tree, @@ -520,7 +520,7 @@ pub fn add_average_case_merk_propagate( let flags_len = average_flags_size.unwrap_or(0); let value_len = LAYER_COST_SIZE + flags_len; let sum_tree_addition = estimated_sum_trees.estimated_size()?; - let cost = KV::value_byte_cost_size_for_key_and_raw_value_lengths( + let cost = KV::layered_value_byte_cost_size_for_key_and_value_lengths( *average_key_size as u32, value_len, in_sum_tree, diff --git a/merk/src/merk/apply.rs b/merk/src/merk/apply.rs index 4418dfc1..a33dfcc4 100644 --- a/merk/src/merk/apply.rs +++ b/merk/src/merk/apply.rs @@ -146,12 +146,14 @@ where /// &[], /// None, /// &|k, v| Ok(0), + /// None::<&fn(&[u8]) -> Option>, /// &mut |s, v, o| Ok((false, None)), /// &mut |s, k, v| Ok((NoStorageRemoval, NoStorageRemoval)) /// ).unwrap().expect(""); /// /// use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval; /// use grovedb_merk::Op; + /// use grovedb_merk::tree::kv::ValueDefinedCostType; /// use grovedb_merk::TreeFeatureType::BasicMerkNode; /// /// let batch = &[ @@ -166,6 +168,7 @@ where /// &[], /// None, /// &|k, v| Ok(0), + /// None::<&fn(&[u8]) -> Option>, /// &mut |s, v, o| Ok((false, None)), /// &mut |s, k, v| Ok((NoStorageRemoval, NoStorageRemoval)) /// ).unwrap().expect(""); @@ -244,12 +247,14 @@ where /// &[], /// None, /// &|k, v| Ok(0), + /// None::<&fn(&[u8]) -> Option>, /// &mut |s, o, v| Ok((false, None)), /// &mut |s, k, v| Ok((NoStorageRemoval, NoStorageRemoval)) /// ).unwrap().expect(""); /// /// use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval; /// use grovedb_merk::Op; + /// use grovedb_merk::tree::kv::ValueDefinedCostType; /// use grovedb_merk::TreeFeatureType::BasicMerkNode; /// /// let batch = &[ @@ -258,12 +263,12 @@ where /// // deletes key [4,5,6] /// (vec![4, 5, 6], Op::Delete), /// ]; - /// unsafe { store.apply_unchecked::<_, Vec<_>, _, _, _>( /// /// /// + /// unsafe { store.apply_unchecked::<_, Vec<_>, _, _, _, _>( /// /// /// /// batch, /// &[], /// None, /// &|k, v| Ok(0), - /// &|v| None, + /// None::<&fn(&[u8]) -> Option>, /// &mut |s, o, v| Ok((false, None)), /// &mut |s, k, v| Ok((NoStorageRemoval, NoStorageRemoval)) /// ).unwrap().expect("");