diff --git a/grovedb/src/batch/estimated_costs/average_case_costs.rs b/grovedb/src/batch/estimated_costs/average_case_costs.rs index 83a8667b..7a3dafa9 100644 --- a/grovedb/src/batch/estimated_costs/average_case_costs.rs +++ b/grovedb/src/batch/estimated_costs/average_case_costs.rs @@ -230,12 +230,15 @@ impl TreeCache for AverageCaseTreeCacheKnownPaths { )) }) ); - GroveDb::add_average_case_get_merk_at_path::( - &mut cost, - path, - layer_should_be_empty, - layer_info.is_sum_tree, - grove_version, + cost_return_on_error_no_add!( + &cost, + GroveDb::add_average_case_get_merk_at_path::( + &mut cost, + path, + layer_should_be_empty, + layer_info.is_sum_tree, + grove_version, + ) ); self.cached_merks .insert(path.clone(), layer_info.is_sum_tree); diff --git a/grovedb/src/batch/estimated_costs/worst_case_costs.rs b/grovedb/src/batch/estimated_costs/worst_case_costs.rs index 8eb0adb5..1b1d42e7 100644 --- a/grovedb/src/batch/estimated_costs/worst_case_costs.rs +++ b/grovedb/src/batch/estimated_costs/worst_case_costs.rs @@ -199,11 +199,14 @@ impl TreeCache for WorstCaseTreeCacheKnownPaths { // Then we have to get the tree if !self.cached_merks.contains(path) { - GroveDb::add_worst_case_get_merk_at_path::( - &mut cost, - path, - false, - grove_version, + cost_return_on_error_no_add!( + &cost, + GroveDb::add_worst_case_get_merk_at_path::( + &mut cost, + path, + false, + grove_version, + ) ); self.cached_merks.insert(path.clone()); } @@ -239,11 +242,14 @@ impl TreeCache for WorstCaseTreeCacheKnownPaths { if let Some(_estimated_layer_info) = self.paths.get(&base_path) { // Then we have to get the tree if !self.cached_merks.contains(&base_path) { - GroveDb::add_worst_case_get_merk_at_path::( - &mut cost, - &base_path, - false, - grove_version, + cost_return_on_error_no_add!( + &cost, + GroveDb::add_worst_case_get_merk_at_path::( + &mut cost, + &base_path, + false, + grove_version, + ) ); self.cached_merks.insert(base_path); } diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 6fd3e466..40c23033 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -2359,7 +2359,11 @@ impl GroveDb { ); cost_return_on_error!( &mut cost, - Self::apply_batch_structure(batch_structure, batch_apply_options) + Self::apply_batch_structure( + batch_structure, + batch_apply_options, + grove_version + ) ); } @@ -2377,7 +2381,11 @@ impl GroveDb { ); cost_return_on_error!( &mut cost, - Self::apply_batch_structure(batch_structure, batch_apply_options) + Self::apply_batch_structure( + batch_structure, + batch_apply_options, + grove_version + ) ); } } diff --git a/grovedb/src/estimated_costs/average_case_costs.rs b/grovedb/src/estimated_costs/average_case_costs.rs index f388b2f5..528414ad 100644 --- a/grovedb/src/estimated_costs/average_case_costs.rs +++ b/grovedb/src/estimated_costs/average_case_costs.rs @@ -16,7 +16,9 @@ use grovedb_merk::{ HASH_LENGTH, }; use grovedb_storage::{worst_case_costs::WorstKeyLength, Storage}; -use grovedb_version::{check_v0_with_cost, version::GroveVersion}; +use grovedb_version::{ + check_v0, check_v0_with_cost, error::GroveVersionError, version::GroveVersion, +}; use integer_encoding::VarInt; use crate::{ @@ -33,8 +35,8 @@ impl GroveDb { merk_should_be_empty: bool, is_sum_tree: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_average_case_get_merk_at_path", grove_version .grovedb_versions @@ -55,10 +57,13 @@ impl GroveDb { key.max_length() as u32, HASH_LENGTH as u32, is_sum_tree, + grove_version, ); } } *cost += S::get_storage_context_cost(path.as_vec()); + + Ok(()) } /// Add average case for insertion into merk @@ -140,7 +145,13 @@ impl GroveDb { TREE_COST_SIZE }; let value_len = tree_cost_size + flags_len; - add_cost_case_merk_insert_layered(&mut cost, key_len, value_len, in_tree_using_sums); + add_cost_case_merk_insert_layered( + &mut cost, + key_len, + value_len, + in_tree_using_sums, + grove_version, + ); if let Some(input) = propagate_if_input { add_average_case_merk_propagate(&mut cost, input).map_err(Error::MerkError) } else { @@ -226,13 +237,20 @@ impl GroveDb { TREE_COST_SIZE }; let value_len = tree_cost_size + flags_len; - add_cost_case_merk_insert_layered(&mut cost, key_len, value_len, in_tree_using_sums) + add_cost_case_merk_insert_layered( + &mut cost, + key_len, + value_len, + in_tree_using_sums, + grove_version, + ) } _ => add_cost_case_merk_insert( &mut cost, key_len, - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32, + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) as u32, in_tree_using_sums, + grove_version, ), }; if let Some(level) = propagate_for_level { @@ -281,6 +299,7 @@ impl GroveDb { key_len, value_len, in_tree_using_sums, + grove_version, ) } Element::Item(_, flags) | Element::SumItem(_, flags) => { @@ -292,7 +311,7 @@ impl GroveDb { let sum_item_cost_size = if value.is_sum_item() { SUM_ITEM_COST_SIZE } else { - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32 + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) as u32 }; let value_len = sum_item_cost_size + flags_len; add_cost_case_merk_replace_same_size( @@ -300,13 +319,15 @@ impl GroveDb { key_len, value_len, in_tree_using_sums, + grove_version, ) } _ => add_cost_case_merk_replace_same_size( &mut cost, key_len, - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32, + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) as u32, in_tree_using_sums, + grove_version, ), }; if let Some(level) = propagate_for_level { @@ -347,7 +368,8 @@ impl GroveDb { }); // Items need to be always the same serialized size for this to work let item_cost_size = - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32; + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) + as u32; let value_len = item_cost_size + flags_len; add_cost_case_merk_patch( &mut cost, @@ -355,6 +377,7 @@ impl GroveDb { value_len, change_in_bytes, in_tree_using_sums, + grove_version, ) } _ => { @@ -413,8 +436,8 @@ impl GroveDb { estimated_element_size: u32, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_average_case_has_raw_cost", grove_version .grovedb_versions @@ -427,10 +450,12 @@ impl GroveDb { key.max_length() as u32, estimated_element_size, in_parent_tree_using_sums, + grove_version, ); cost.seek_count += 1; cost.storage_loaded_bytes += value_size; *cost += S::get_storage_context_cost(path.as_vec()); + Ok(()) } /// Adds the average case of checking to see if a tree exists @@ -442,8 +467,8 @@ impl GroveDb { is_sum_tree: bool, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_average_case_has_raw_tree_cost", grove_version .grovedb_versions @@ -464,7 +489,7 @@ impl GroveDb { estimated_element_size, in_parent_tree_using_sums, grove_version, - ); + ) } /// Add average case to get raw cost into merk @@ -475,8 +500,8 @@ impl GroveDb { estimated_element_size: u32, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_average_case_get_raw_cost", grove_version .grovedb_versions @@ -491,7 +516,9 @@ impl GroveDb { key.max_length() as u32, estimated_element_size, in_parent_tree_using_sums, - ); + grove_version, + ) + .map_err(Error::MerkError) } /// adds the average cost of getting a tree @@ -503,8 +530,8 @@ impl GroveDb { is_sum_tree: bool, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_average_case_get_raw_tree_cost", grove_version .grovedb_versions @@ -524,7 +551,9 @@ impl GroveDb { key.max_length() as u32, estimated_element_size, in_parent_tree_using_sums, - ); + grove_version, + ) + .map_err(Error::MerkError) } /// adds the average cost of getting an element knowing there can be @@ -537,8 +566,8 @@ impl GroveDb { estimated_element_size: u32, estimated_references_sizes: Vec, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_average_case_get_cost", grove_version .grovedb_versions @@ -552,10 +581,12 @@ impl GroveDb { key.max_length() as u32, estimated_element_size, in_parent_tree_using_sums, + grove_version, ); cost.seek_count += 1 + estimated_references_sizes.len() as u16; cost.storage_loaded_bytes += value_size + estimated_references_sizes.iter().sum::(); *cost += S::get_storage_context_cost(path.as_vec()); + Ok(()) } } @@ -582,6 +613,7 @@ mod test { #[test] fn test_get_merk_node_average_case() { + let grove_version = GroveVersion::latest(); // Open a merk and insert 10 elements. let tmp_dir = TempDir::new().expect("cannot open tempdir"); let storage = RocksDbStorage::default_rocksdb_with_path(tmp_dir.path()) @@ -636,12 +668,19 @@ mod test { // (this will be the max_element_size) let mut cost = OperationCost::default(); let key = KnownKey(8_u64.to_be_bytes().to_vec()); - add_average_case_get_merk_node(&mut cost, key.max_length() as u32, 60, false); + add_average_case_get_merk_node( + &mut cost, + key.max_length() as u32, + 60, + false, + grove_version, + ); assert_eq!(cost, node_result.cost); } #[test] fn test_has_raw_average_case() { + let grove_version = GroveVersion::latest(); let tmp_dir = TempDir::new().unwrap(); let db = GroveDb::open(tmp_dir.path()).unwrap(); diff --git a/grovedb/src/estimated_costs/worst_case_costs.rs b/grovedb/src/estimated_costs/worst_case_costs.rs index 867d5f0c..6c23d6ac 100644 --- a/grovedb/src/estimated_costs/worst_case_costs.rs +++ b/grovedb/src/estimated_costs/worst_case_costs.rs @@ -18,7 +18,9 @@ use grovedb_merk::{ HASH_LENGTH, }; use grovedb_storage::{worst_case_costs::WorstKeyLength, Storage}; -use grovedb_version::{check_v0_with_cost, version::GroveVersion}; +use grovedb_version::{ + check_v0, check_v0_with_cost, error::GroveVersionError, version::GroveVersion, +}; use integer_encoding::VarInt; use crate::{ @@ -36,8 +38,8 @@ impl GroveDb { path: &KeyInfoPath, is_sum_tree: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_worst_case_get_merk_at_path", grove_version .grovedb_versions @@ -54,10 +56,12 @@ impl GroveDb { key.max_length() as u32, HASH_LENGTH as u32, is_sum_tree, + grove_version, ); } } *cost += S::get_storage_context_cost(path.as_vec()); + Ok(()) } /// Add worst case for insertion into merk @@ -131,7 +135,13 @@ impl GroveDb { TREE_COST_SIZE }; let value_len = tree_cost + flags_len; - add_cost_case_merk_insert_layered(&mut cost, key_len, value_len, is_in_parent_sum_tree); + add_cost_case_merk_insert_layered( + &mut cost, + key_len, + value_len, + is_in_parent_sum_tree, + grove_version, + ); if let Some(input) = propagate_if_input { add_worst_case_merk_propagate(&mut cost, input).map_err(Error::MerkError) } else { @@ -213,13 +223,15 @@ impl GroveDb { key_len, value_len, in_parent_tree_using_sums, + grove_version, ) } _ => add_cost_case_merk_insert( &mut cost, key_len, - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32, + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) as u32, in_parent_tree_using_sums, + grove_version, ), }; if let Some(level) = propagate_for_level { @@ -268,6 +280,7 @@ impl GroveDb { key_len, value_len, in_parent_tree_using_sums, + grove_version, ) } Element::SumItem(_, flags) => { @@ -281,13 +294,15 @@ impl GroveDb { key_len, value_len, in_parent_tree_using_sums, + grove_version, ) } _ => add_cost_case_merk_replace( &mut cost, key_len, - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32, + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) as u32, in_parent_tree_using_sums, + grove_version, ), }; if let Some(level) = propagate_for_level { @@ -328,7 +343,8 @@ impl GroveDb { }); // Items need to be always the same serialized size for this to work let sum_item_cost_size = - cost_return_on_error_no_add!(&cost, value.serialized_size()) as u32; + cost_return_on_error_no_add!(&cost, value.serialized_size(grove_version)) + as u32; let value_len = sum_item_cost_size + flags_len; add_cost_case_merk_patch( &mut cost, @@ -336,6 +352,7 @@ impl GroveDb { value_len, change_in_bytes, in_tree_using_sums, + grove_version, ) } _ => { @@ -387,8 +404,8 @@ impl GroveDb { max_element_size: u32, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_worst_case_has_raw_cost", grove_version .grovedb_versions @@ -401,10 +418,12 @@ impl GroveDb { key.max_length() as u32, max_element_size, in_parent_tree_using_sums, + grove_version, ); cost.seek_count += 1; cost.storage_loaded_bytes += value_size; *cost += S::get_storage_context_cost(path.as_vec()); + Ok(()) } /// Add worst case cost for get raw tree into merk @@ -415,8 +434,8 @@ impl GroveDb { is_sum_tree: bool, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_worst_case_get_raw_tree_cost", grove_version .grovedb_versions @@ -436,7 +455,9 @@ impl GroveDb { key.max_length() as u32, tree_cost_size, in_parent_tree_using_sums, - ); + grove_version, + ) + .map_err(Error::MerkError) } /// Add worst case cost for get raw into merk @@ -447,8 +468,8 @@ impl GroveDb { max_element_size: u32, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_worst_case_get_raw_cost", grove_version .grovedb_versions @@ -463,7 +484,9 @@ impl GroveDb { key.max_length() as u32, max_element_size, in_parent_tree_using_sums, + grove_version, ); + Ok(()) } /// Add worst case cost for get into merk @@ -475,8 +498,8 @@ impl GroveDb { in_parent_tree_using_sums: bool, max_references_sizes: Vec, grove_version: &GroveVersion, - ) { - check_v0_with_cost!( + ) -> Result<(), Error> { + check_v0!( "add_worst_case_get_cost", grove_version .grovedb_versions @@ -490,10 +513,12 @@ impl GroveDb { key.max_length() as u32, max_element_size, in_parent_tree_using_sums, + grove_version, ); cost.seek_count += 1 + max_references_sizes.len() as u16; cost.storage_loaded_bytes += value_size + max_references_sizes.iter().sum::(); *cost += S::get_storage_context_cost(path.as_vec()); + Ok(()) } } @@ -523,6 +548,7 @@ mod test { #[test] fn test_get_merk_node_worst_case() { + let grove_version = GroveVersion::latest(); // Open a merk and insert 10 elements. let storage = TempStorage::new(); let batch = StorageBatch::new(); @@ -559,12 +585,13 @@ mod test { // (this will be the max_element_size) let mut cost = OperationCost::default(); let key = KnownKey(8_u64.to_be_bytes().to_vec()); - add_worst_case_get_merk_node(&mut cost, key.max_length() as u32, 60, false); + add_worst_case_get_merk_node(&mut cost, key.max_length() as u32, 60, false, grove_version); assert_eq!(cost, node_result.cost); } #[test] fn test_has_raw_worst_case() { + let grove_version = GroveVersion::latest(); let tmp_dir = TempDir::new().unwrap(); let db = GroveDb::open(tmp_dir.path()).unwrap(); diff --git a/grovedb/src/operations/delete/average_case.rs b/grovedb/src/operations/delete/average_case.rs index 2dfa957a..5474a5db 100644 --- a/grovedb/src/operations/delete/average_case.rs +++ b/grovedb/src/operations/delete/average_case.rs @@ -11,6 +11,7 @@ use grovedb_merk::{ HASH_LENGTH_U32, }; use grovedb_storage::{worst_case_costs::WorstKeyLength, Storage}; +use grovedb_version::version::GroveVersion; use intmap::IntMap; use crate::{ @@ -30,6 +31,7 @@ impl GroveDb { stop_path_height: Option, validate: bool, estimated_layer_info: IntMap, + grove_version: &GroveVersion, ) -> CostResult, Error> { let mut cost = OperationCost::default(); @@ -113,7 +115,8 @@ impl GroveDb { validate, check_if_tree, except_keys_count, - (key_len, estimated_element_size) + (key_len, estimated_element_size), + grove_version, ) ); ops.push(op); @@ -131,24 +134,33 @@ impl GroveDb { check_if_tree: bool, except_keys_count: u16, estimated_key_element_size: EstimatedKeyAndElementSize, + grove_version: &GroveVersion, ) -> CostResult { let mut cost = OperationCost::default(); if validate { - GroveDb::add_average_case_get_merk_at_path::( - &mut cost, - path, - false, - parent_tree_is_sum_tree, + cost_return_on_error_no_add!( + &cost, + GroveDb::add_average_case_get_merk_at_path::( + &mut cost, + path, + false, + parent_tree_is_sum_tree, + grove_version, + ) ); } if check_if_tree { - GroveDb::add_average_case_get_raw_cost::( - &mut cost, - path, - key, - estimated_key_element_size.1, - parent_tree_is_sum_tree, + cost_return_on_error_no_add!( + &cost, + GroveDb::add_average_case_get_raw_cost::( + &mut cost, + path, + key, + estimated_key_element_size.1, + parent_tree_is_sum_tree, + grove_version, + ) ); } // in the worst case this is a tree diff --git a/grovedb/src/operations/delete/worst_case.rs b/grovedb/src/operations/delete/worst_case.rs index ede20314..dbf38015 100644 --- a/grovedb/src/operations/delete/worst_case.rs +++ b/grovedb/src/operations/delete/worst_case.rs @@ -7,6 +7,7 @@ use grovedb_merk::{ estimated_costs::worst_case_costs::add_worst_case_cost_for_is_empty_tree_except, tree::kv::KV, }; use grovedb_storage::{worst_case_costs::WorstKeyLength, Storage}; +use grovedb_version::version::GroveVersion; use intmap::IntMap; use crate::{ @@ -25,6 +26,7 @@ impl GroveDb { validate: bool, intermediate_tree_info: IntMap<(bool, u32)>, max_element_size: u32, + grove_version: &GroveVersion, ) -> CostResult, Error> { let mut cost = OperationCost::default(); @@ -95,7 +97,8 @@ impl GroveDb { validate, check_if_tree, except_keys_count, - max_element_size + max_element_size, + grove_version ) ); ops.push(op); @@ -113,11 +116,17 @@ impl GroveDb { check_if_tree: bool, except_keys_count: u16, max_element_size: u32, + grove_version: &GroveVersion, ) -> CostResult { let mut cost = OperationCost::default(); if validate { - GroveDb::add_worst_case_get_merk_at_path::(&mut cost, path, parent_tree_is_sum_tree); + GroveDb::add_worst_case_get_merk_at_path::( + &mut cost, + path, + parent_tree_is_sum_tree, + grove_version, + ); } if check_if_tree { GroveDb::add_worst_case_get_raw_cost::( @@ -126,6 +135,7 @@ impl GroveDb { key, max_element_size, parent_tree_is_sum_tree, + grove_version, ); } // in the worst case this is a tree diff --git a/grovedb/src/operations/get/average_case.rs b/grovedb/src/operations/get/average_case.rs index eee6525d..605ebb55 100644 --- a/grovedb/src/operations/get/average_case.rs +++ b/grovedb/src/operations/get/average_case.rs @@ -6,6 +6,7 @@ use grovedb_costs::OperationCost; use grovedb_storage::rocksdb_storage::RocksDbStorage; use grovedb_version::version::GroveVersion; +use crate::Error; #[cfg(feature = "full")] use crate::{ batch::{key_info::KeyInfo, KeyInfoPath}, @@ -66,7 +67,7 @@ impl GroveDb { estimated_element_size: u32, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) -> OperationCost { + ) -> Result { let mut cost = OperationCost::default(); GroveDb::add_average_case_get_raw_cost::( &mut cost, @@ -75,8 +76,8 @@ impl GroveDb { estimated_element_size, in_parent_tree_using_sums, grove_version, - ); - cost + )?; + Ok(cost) } /// Get the Operation Cost for a get query with the following parameters @@ -87,7 +88,7 @@ impl GroveDb { estimated_element_size: u32, estimated_references_sizes: Vec, grove_version: &GroveVersion, - ) -> OperationCost { + ) -> Result { let mut cost = OperationCost::default(); GroveDb::add_average_case_get_cost::( &mut cost, @@ -97,8 +98,8 @@ impl GroveDb { estimated_element_size, estimated_references_sizes, grove_version, - ); - cost + )?; + Ok(cost) } /// Get the Operation Cost for a get query with the following parameters @@ -109,7 +110,7 @@ impl GroveDb { is_sum_tree: bool, in_parent_tree_using_sums: bool, grove_version: &GroveVersion, - ) -> OperationCost { + ) -> Result { let mut cost = OperationCost::default(); GroveDb::add_average_case_get_raw_tree_cost::( &mut cost, @@ -119,7 +120,7 @@ impl GroveDb { is_sum_tree, in_parent_tree_using_sums, grove_version, - ); - cost + )?; + Ok(cost) } } diff --git a/grovedb/src/operations/get/worst_case.rs b/grovedb/src/operations/get/worst_case.rs index 5510bb6e..4be80b3f 100644 --- a/grovedb/src/operations/get/worst_case.rs +++ b/grovedb/src/operations/get/worst_case.rs @@ -4,7 +4,9 @@ use grovedb_costs::OperationCost; #[cfg(feature = "full")] use grovedb_storage::rocksdb_storage::RocksDbStorage; +use grovedb_version::version::GroveVersion; +use crate::Error; #[cfg(feature = "full")] use crate::{ batch::{key_info::KeyInfo, KeyInfoPath}, @@ -19,7 +21,8 @@ impl GroveDb { key: &KeyInfo, max_element_size: u32, in_parent_tree_using_sums: bool, - ) -> OperationCost { + grove_version: &GroveVersion, + ) -> Result { let mut cost = OperationCost::default(); GroveDb::add_worst_case_has_raw_cost::( &mut cost, @@ -27,8 +30,9 @@ impl GroveDb { key, max_element_size, in_parent_tree_using_sums, - ); - cost + grove_version, + )?; + Ok(cost) } /// Worst case cost for get raw @@ -37,7 +41,8 @@ impl GroveDb { key: &KeyInfo, max_element_size: u32, in_parent_tree_using_sums: bool, - ) -> OperationCost { + grove_version: &GroveVersion, + ) -> Result { let mut cost = OperationCost::default(); GroveDb::add_worst_case_get_raw_cost::( &mut cost, @@ -45,8 +50,9 @@ impl GroveDb { key, max_element_size, in_parent_tree_using_sums, - ); - cost + grove_version, + )?; + Ok(cost) } /// Worst case cost for get @@ -56,7 +62,8 @@ impl GroveDb { max_element_size: u32, max_references_sizes: Vec, in_parent_tree_using_sums: bool, - ) -> OperationCost { + grove_version: &GroveVersion, + ) -> Result { let mut cost = OperationCost::default(); GroveDb::add_worst_case_get_cost::( &mut cost, @@ -65,7 +72,8 @@ impl GroveDb { max_element_size, in_parent_tree_using_sums, max_references_sizes, - ); - cost + grove_version, + )?; + Ok(cost) } } diff --git a/merk/src/estimated_costs/average_case_costs.rs b/merk/src/estimated_costs/average_case_costs.rs index 1453d708..0f2415f6 100644 --- a/merk/src/estimated_costs/average_case_costs.rs +++ b/merk/src/estimated_costs/average_case_costs.rs @@ -30,6 +30,7 @@ #[cfg(feature = "full")] use grovedb_costs::{CostResult, CostsExt, OperationCost}; +use grovedb_version::version::GroveVersion; #[cfg(feature = "full")] use integer_encoding::VarInt; @@ -320,12 +321,13 @@ impl TreeNode { not_prefixed_key_len: u32, estimated_element_size: u32, is_sum_node: bool, + grove_version: &GroveVersion, ) -> u32 { // two option values for the left and right link // the actual left and right link encoding size // the encoded kv node size 2 + (2 * Link::encoded_link_size(not_prefixed_key_len, is_sum_node)) - + KV::encoded_kv_node_size(estimated_element_size, is_sum_node) + + KV::encoded_kv_node_size(estimated_element_size, is_sum_node, grove_version) } } @@ -336,7 +338,8 @@ pub fn add_average_case_get_merk_node( not_prefixed_key_len: u32, approximate_element_size: u32, is_sum_tree: bool, -) { + grove_version: &GroveVersion, +) -> Result<(), Error> { // Worst case scenario, the element is not already in memory. // One direct seek has to be performed to read the node from storage. cost.seek_count += 1; @@ -347,7 +350,9 @@ pub fn add_average_case_get_merk_node( not_prefixed_key_len, approximate_element_size, is_sum_tree, + grove_version, ); + Ok(()) } #[cfg(feature = "full")] diff --git a/merk/src/estimated_costs/mod.rs b/merk/src/estimated_costs/mod.rs index faabce81..765e83ab 100644 --- a/merk/src/estimated_costs/mod.rs +++ b/merk/src/estimated_costs/mod.rs @@ -1,35 +1,8 @@ -// MIT LICENSE -// -// Copyright (c) 2021 Dash Core Group -// -// Permission is hereby granted, free of charge, to any -// person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the -// Software without restriction, including without -// limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software -// is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice -// shall be included in all copies or substantial portions -// of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - //! Estimated costs for Merk #[cfg(feature = "full")] use grovedb_costs::OperationCost; +use grovedb_version::version::GroveVersion; #[cfg(feature = "full")] use integer_encoding::VarInt; @@ -61,7 +34,11 @@ pub const SUM_LAYER_COST_SIZE: u32 = LAYER_COST_SIZE + SUM_VALUE_EXTRA_COST; #[cfg(feature = "full")] impl KV { - fn encoded_kv_node_size(element_size: u32, is_sum_node: bool) -> u32 { + fn encoded_kv_node_size( + element_size: u32, + is_sum_node: bool, + grove_version: &GroveVersion, + ) -> u32 { // We always charge 8 bytes for the sum node (even though // it could theoretically be 9 bytes let sum_node_feature_size = if is_sum_node { 9 } else { 1 }; @@ -80,6 +57,7 @@ pub fn add_cost_case_merk_insert( key_len: u32, value_len: u32, in_tree_using_sums: bool, + grove_version: &GroveVersion, ) { cost.seek_count += 1; cost.storage_cost.added_bytes += KV::node_byte_cost_size_for_key_and_raw_value_lengths( @@ -104,6 +82,7 @@ pub fn add_cost_case_merk_insert_layered( key_len: u32, value_len: u32, in_tree_using_sums: bool, + grove_version: &GroveVersion, ) { cost.seek_count += 1; cost.storage_cost.added_bytes += KV::layered_node_byte_cost_size_for_key_and_value_lengths( @@ -130,6 +109,7 @@ pub fn add_cost_case_merk_replace( key_len: u32, value_len: u32, in_tree_using_sums: bool, + grove_version: &GroveVersion, ) { cost.seek_count += 1; cost.storage_cost.added_bytes += @@ -153,6 +133,7 @@ pub fn add_cost_case_merk_replace_same_size( key_len: u32, value_len: u32, in_tree_using_sums: bool, + grove_version: &GroveVersion, ) { cost.seek_count += 1; cost.storage_cost.replaced_bytes += KV::node_byte_cost_size_for_key_and_raw_value_lengths( @@ -177,6 +158,7 @@ pub fn add_cost_case_merk_replace_layered( key_len: u32, value_len: u32, in_tree_using_sums: bool, + grove_version: &GroveVersion, ) { cost.seek_count += 1; cost.storage_cost.replaced_bytes += KV::layered_node_byte_cost_size_for_key_and_value_lengths( @@ -205,6 +187,7 @@ pub fn add_cost_case_merk_patch( value_len: u32, change_in_bytes: i32, in_tree_using_sums: bool, + grove_version: &GroveVersion, ) { cost.seek_count += 1; if change_in_bytes >= 0 { diff --git a/merk/src/estimated_costs/worst_case_costs.rs b/merk/src/estimated_costs/worst_case_costs.rs index 407e2c70..b501c0e3 100644 --- a/merk/src/estimated_costs/worst_case_costs.rs +++ b/merk/src/estimated_costs/worst_case_costs.rs @@ -32,6 +32,7 @@ use std::cmp::Ordering; #[cfg(feature = "full")] use grovedb_costs::{CostResult, CostsExt, OperationCost}; +use grovedb_version::version::GroveVersion; #[cfg(feature = "full")] use crate::{ @@ -58,12 +59,13 @@ impl TreeNode { not_prefixed_key_len: u32, max_element_size: u32, is_sum_node: bool, + grove_version: &GroveVersion, ) -> u32 { // two option values for the left and right link // the actual left and right link encoding size // the encoded kv node size 2 + (2 * Link::encoded_link_size(not_prefixed_key_len, is_sum_node)) - + KV::encoded_kv_node_size(max_element_size, is_sum_node) + + KV::encoded_kv_node_size(max_element_size, is_sum_node, grove_version) } } @@ -74,15 +76,21 @@ pub fn add_worst_case_get_merk_node( not_prefixed_key_len: u32, max_element_size: u32, is_sum_node: bool, -) { + grove_version: &GroveVersion, +) -> Result<(), Error> { // Worst case scenario, the element is not already in memory. // One direct seek has to be performed to read the node from storage. cost.seek_count += 1; // To write a node to disk, the left link, right link and kv nodes are encoded. // worst case, the node has both the left and right link present. - cost.storage_loaded_bytes += - TreeNode::worst_case_encoded_tree_size(not_prefixed_key_len, max_element_size, is_sum_node); + cost.storage_loaded_bytes += TreeNode::worst_case_encoded_tree_size( + not_prefixed_key_len, + max_element_size, + is_sum_node, + grove_version, + ); + Ok(()) } #[cfg(feature = "full")] diff --git a/merk/src/merk/chunks.rs b/merk/src/merk/chunks.rs index 41afeb35..20c6cc39 100644 --- a/merk/src/merk/chunks.rs +++ b/merk/src/merk/chunks.rs @@ -587,17 +587,45 @@ mod test { assert_eq!( chunk, vec![ - Op::Push(traverse_get_node_hash(&mut tree_walker, &[LEFT, LEFT])), - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[LEFT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[LEFT, LEFT], + grove_version + )), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[LEFT], + grove_version + )), Op::Parent, - Op::Push(traverse_get_node_hash(&mut tree_walker, &[LEFT, RIGHT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[LEFT, RIGHT], + grove_version + )), Op::Child, - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[])), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[], + grove_version + )), Op::Parent, - Op::Push(traverse_get_node_hash(&mut tree_walker, &[RIGHT, LEFT])), - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[RIGHT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[RIGHT, LEFT], + grove_version + )), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[RIGHT], + grove_version + )), Op::Parent, - Op::Push(traverse_get_node_hash(&mut tree_walker, &[RIGHT, RIGHT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[RIGHT, RIGHT], + grove_version + )), Op::Child, Op::Child ] @@ -618,16 +646,19 @@ mod test { vec![ Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, LEFT, LEFT] + &[LEFT, LEFT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, LEFT] + &[LEFT, LEFT], + grove_version )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, LEFT, RIGHT] + &[LEFT, LEFT, RIGHT], + grove_version )), Op::Child ] @@ -648,16 +679,19 @@ mod test { vec![ Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, RIGHT, LEFT] + &[LEFT, RIGHT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, RIGHT] + &[LEFT, RIGHT], + grove_version )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, RIGHT, RIGHT] + &[LEFT, RIGHT, RIGHT], + grove_version )), Op::Child ] @@ -678,16 +712,19 @@ mod test { vec![ Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT, LEFT] + &[RIGHT, LEFT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT] + &[RIGHT, LEFT], + grove_version )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT, RIGHT] + &[RIGHT, LEFT, RIGHT], + grove_version )), Op::Child ] @@ -708,16 +745,19 @@ mod test { vec![ Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT, LEFT] + &[RIGHT, RIGHT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT] + &[RIGHT, RIGHT], + grove_version )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT, RIGHT] + &[RIGHT, RIGHT, RIGHT], + grove_version )), Op::Child ] diff --git a/merk/src/merk/mod.rs b/merk/src/merk/mod.rs index e31d4bc6..ee0deccc 100644 --- a/merk/src/merk/mod.rs +++ b/merk/src/merk/mod.rs @@ -757,6 +757,7 @@ mod test { rocksdb_storage::{PrefixedRocksDbStorageContext, RocksDbStorage}, RawIterator, Storage, StorageBatch, StorageContext, }; + use grovedb_version::version::GroveVersion; use tempfile::TempDir; use super::{Merk, RefWalker}; @@ -776,6 +777,7 @@ mod test { #[test] fn simple_insert_apply() { + let grove_version = GroveVersion::latest(); let batch_size = 20; let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..batch_size); @@ -795,6 +797,7 @@ mod test { #[test] fn tree_height() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..1); merk.apply::<_, Vec<_>>(&batch, &[], None, grove_version) @@ -830,6 +833,7 @@ mod test { #[test] fn insert_uncached() { + let grove_version = GroveVersion::latest(); let batch_size = 20; let mut merk = TempMerk::new(grove_version); @@ -848,6 +852,7 @@ mod test { #[test] fn insert_two() { + let grove_version = GroveVersion::latest(); let tree_size = 2; let batch_size = 1; let mut merk = TempMerk::new(grove_version); @@ -862,6 +867,7 @@ mod test { #[test] fn insert_rand() { + let grove_version = GroveVersion::latest(); let tree_size = 40; let batch_size = 4; let mut merk = TempMerk::new(grove_version); @@ -877,6 +883,7 @@ mod test { #[test] fn actual_deletes() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_rand(10, 1); @@ -895,6 +902,7 @@ mod test { #[test] fn aux_data() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); merk.apply::, _>( &[], @@ -912,6 +920,7 @@ mod test { #[test] fn get_not_found() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); // no root @@ -974,6 +983,7 @@ mod test { // TODO: what this test should do? #[test] fn reopen_check_root_hash() { + let grove_version = GroveVersion::latest(); let tmp_dir = TempDir::new().expect("cannot open tempdir"); let storage = RocksDbStorage::default_rocksdb_with_path(tmp_dir.path()) .expect("cannot open rocksdb storage"); @@ -999,6 +1009,7 @@ mod test { #[test] fn test_get_node_cost() { + let grove_version = GroveVersion::latest(); let tmp_dir = TempDir::new().expect("cannot open tempdir"); let storage = RocksDbStorage::default_rocksdb_with_path(tmp_dir.path()) .expect("cannot open rocksdb storage"); @@ -1021,15 +1032,17 @@ mod test { #[test] fn reopen() { + let grove_version = GroveVersion::latest(); fn collect( mut node: RefWalker>, nodes: &mut Vec>, ) { + let grove_version = GroveVersion::latest(); nodes.push(node.tree().encode()); if let Some(c) = node .walk( true, - None::<&fn(&[u8]) -> Option>, + None::<&fn(&[u8], &GroveVersion) -> Option>, grove_version, ) .unwrap() @@ -1040,7 +1053,7 @@ mod test { if let Some(c) = node .walk( false, - None::<&fn(&[u8]) -> Option>, + None::<&fn(&[u8], &GroveVersion) -> Option>, grove_version, ) .unwrap() @@ -1120,6 +1133,7 @@ mod test { #[test] fn reopen_iter() { + let grove_version = GroveVersion::latest(); fn collect(iter: PrefixedStorageIter<'_, '_>, nodes: &mut Vec<(Vec, Vec)>) { while iter.valid().unwrap() { nodes.push(( @@ -1190,6 +1204,7 @@ mod test { #[test] fn update_node() { + let grove_version = GroveVersion::latest(); let tmp_dir = TempDir::new().expect("cannot open tempdir"); let storage = RocksDbStorage::default_rocksdb_with_path(tmp_dir.path()) .expect("cannot open rocksdb storage"); diff --git a/merk/src/merk/restore.rs b/merk/src/merk/restore.rs index a5cb7420..1082e80b 100644 --- a/merk/src/merk/restore.rs +++ b/merk/src/merk/restore.rs @@ -664,6 +664,7 @@ mod tests { #[test] fn test_process_chunk_correct_chunk_id_map() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..15); merk.apply::<_, Vec<_>>(&batch, &[], None, grove_version) @@ -725,23 +726,51 @@ mod tests { // assert all the chunk hash values assert_eq!( restorer.chunk_id_to_root_hash.get(vec![1, 1].as_slice()), - Some(get_node_hash(traverse_get_node_hash(&mut tree_walker, &[LEFT, LEFT])).unwrap()) - .as_ref() + Some( + get_node_hash(traverse_get_node_hash( + &mut tree_walker, + &[LEFT, LEFT], + grove_version + )) + .unwrap() + ) + .as_ref() ); assert_eq!( restorer.chunk_id_to_root_hash.get(vec![1, 0].as_slice()), - Some(get_node_hash(traverse_get_node_hash(&mut tree_walker, &[LEFT, RIGHT])).unwrap()) - .as_ref() + Some( + get_node_hash(traverse_get_node_hash( + &mut tree_walker, + &[LEFT, RIGHT], + grove_version + )) + .unwrap() + ) + .as_ref() ); assert_eq!( restorer.chunk_id_to_root_hash.get(vec![0, 1].as_slice()), - Some(get_node_hash(traverse_get_node_hash(&mut tree_walker, &[RIGHT, LEFT])).unwrap()) - .as_ref() + Some( + get_node_hash(traverse_get_node_hash( + &mut tree_walker, + &[RIGHT, LEFT], + grove_version + )) + .unwrap() + ) + .as_ref() ); assert_eq!( restorer.chunk_id_to_root_hash.get(vec![0, 0].as_slice()), - Some(get_node_hash(traverse_get_node_hash(&mut tree_walker, &[RIGHT, RIGHT])).unwrap()) - .as_ref() + Some( + get_node_hash(traverse_get_node_hash( + &mut tree_walker, + &[RIGHT, RIGHT], + grove_version + )) + .unwrap() + ) + .as_ref() ); // generate second chunk @@ -895,6 +924,7 @@ mod tests { // attempts restoration on some empty merk // verifies that restoration was performed correctly. fn test_restoration_single_chunk_strategy(batch_size: u64) { + let grove_version = GroveVersion::latest(); // build the source merk let storage = TempStorage::new(); let tx = storage.start_transaction(); @@ -980,6 +1010,7 @@ mod tests { #[test] fn test_process_multi_chunk_no_limit() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..15); merk.apply::<_, Vec<_>>(&batch, &[], None, grove_version) @@ -1048,6 +1079,7 @@ mod tests { #[test] fn test_process_multi_chunk_no_limit_but_non_root() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..15); merk.apply::<_, Vec<_>>(&batch, &[], None, grove_version) @@ -1129,6 +1161,7 @@ mod tests { #[test] fn test_process_multi_chunk_with_limit() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..15); merk.apply::<_, Vec<_>>(&batch, &[], None, grove_version) @@ -1228,6 +1261,7 @@ mod tests { // attempts restoration on some empty merk, with multi chunks // verifies that restoration was performed correctly. fn test_restoration_multi_chunk_strategy(batch_size: u64, limit: Option) { + let grove_version = GroveVersion::latest(); // build the source merk let mut source_merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..batch_size); @@ -1311,6 +1345,7 @@ mod tests { #[test] fn test_restoration_interruption() { + let grove_version = GroveVersion::latest(); let mut merk = TempMerk::new(grove_version); let batch = make_batch_seq(0..15); merk.apply::<_, Vec<_>>(&batch, &[], None, grove_version) diff --git a/merk/src/proofs/chunk/chunk.rs b/merk/src/proofs/chunk/chunk.rs index b4fe6ffa..195b3b95 100644 --- a/merk/src/proofs/chunk/chunk.rs +++ b/merk/src/proofs/chunk/chunk.rs @@ -231,6 +231,7 @@ pub fn verify_height_tree(height_proof_tree: &Tree) -> Result { #[cfg(test)] pub mod tests { use ed::Encode; + use grovedb_version::version::GroveVersion; use crate::{ proofs::{ @@ -244,6 +245,7 @@ pub mod tests { }; fn build_tree_10_nodes() -> TreeNode { + let grove_version = GroveVersion::latest(); // 3 // / \ // 1 7 @@ -259,10 +261,14 @@ pub mod tests { pub fn traverse_get_node_hash( walker: &mut RefWalker, traverse_instructions: &[bool], + grove_version: &GroveVersion, ) -> Node { - traverse_and_apply(walker, traverse_instructions, |walker| { - walker.to_hash_node().unwrap() - }) + traverse_and_apply( + walker, + traverse_instructions, + |walker| walker.to_hash_node().unwrap(), + grove_version, + ) } /// Traverses a tree to a certain node and returns the kv_feature_type of @@ -270,20 +276,28 @@ pub mod tests { pub fn traverse_get_kv_feature_type( walker: &mut RefWalker, traverse_instructions: &[bool], + grove_version: &GroveVersion, ) -> Node { - traverse_and_apply(walker, traverse_instructions, |walker| { - walker.to_kv_value_hash_feature_type_node() - }) + traverse_and_apply( + walker, + traverse_instructions, + |walker| walker.to_kv_value_hash_feature_type_node(), + grove_version, + ) } /// Traverses a tree to a certain node and returns the kv_hash of /// that node pub fn traverse_get_kv_hash( walker: &mut RefWalker, traverse_instructions: &[bool], + grove_version: &GroveVersion, ) -> Node { - traverse_and_apply(walker, traverse_instructions, |walker| { - walker.to_kvhash_node() - }) + traverse_and_apply( + walker, + traverse_instructions, + |walker| walker.to_kvhash_node(), + grove_version, + ) } /// Traverses a tree to a certain node and returns the result of applying @@ -292,6 +306,7 @@ pub mod tests { walker: &mut RefWalker, traverse_instructions: &[bool], apply_fn: T, + grove_version: &GroveVersion, ) -> Node where T: Fn(&mut RefWalker) -> Node, @@ -309,11 +324,17 @@ pub mod tests { .unwrap() .unwrap() .unwrap(); - traverse_and_apply(&mut child, &traverse_instructions[1..], apply_fn) + traverse_and_apply( + &mut child, + &traverse_instructions[1..], + apply_fn, + grove_version, + ) } #[test] fn build_chunk_from_root_depth_0() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -324,7 +345,7 @@ pub mod tests { assert_eq!(chunk.len(), 1); assert_eq!( chunk[0], - Op::Push(traverse_get_node_hash(&mut tree_walker, &[])) + Op::Push(traverse_get_node_hash(&mut tree_walker, &[], grove_version)) ); let computed_tree = execute(chunk.into_iter().map(Ok), true, |_| Ok(())) @@ -335,6 +356,7 @@ pub mod tests { #[test] fn build_chunk_from_root_depth_1() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -350,10 +372,22 @@ pub mod tests { assert_eq!( chunk, vec![ - Op::Push(traverse_get_node_hash(&mut tree_walker, &[LEFT])), - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[LEFT], + grove_version + )), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[], + grove_version + )), Op::Parent, - Op::Push(traverse_get_node_hash(&mut tree_walker, &[RIGHT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[RIGHT], + grove_version + )), Op::Child ] ); @@ -366,6 +400,7 @@ pub mod tests { #[test] fn build_chunk_from_root_depth_3() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -387,40 +422,59 @@ pub mod tests { vec![ Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, LEFT] + &[LEFT, LEFT], + grove_version + )), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[LEFT], + grove_version )), - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[LEFT])), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, RIGHT] + &[LEFT, RIGHT], + grove_version )), Op::Child, - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[])), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[], + grove_version + )), Op::Parent, Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, LEFT, LEFT] + &[RIGHT, LEFT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT] + &[RIGHT, LEFT], + grove_version )), Op::Parent, Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, LEFT, RIGHT] + &[RIGHT, LEFT, RIGHT], + grove_version )), Op::Child, - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[RIGHT])), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[RIGHT], + grove_version + )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT] + &[RIGHT, RIGHT], + grove_version )), Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, RIGHT, RIGHT] + &[RIGHT, RIGHT, RIGHT], + grove_version )), Op::Child, Op::Child, @@ -436,6 +490,7 @@ pub mod tests { #[test] fn build_chunk_from_root_depth_max_depth() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -456,40 +511,59 @@ pub mod tests { vec![ Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, LEFT] + &[LEFT, LEFT], + grove_version + )), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[LEFT], + grove_version )), - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[LEFT])), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[LEFT, RIGHT] + &[LEFT, RIGHT], + grove_version )), Op::Child, - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[])), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[], + grove_version + )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT, LEFT] + &[RIGHT, LEFT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT] + &[RIGHT, LEFT], + grove_version )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT, RIGHT] + &[RIGHT, LEFT, RIGHT], + grove_version )), Op::Child, - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[RIGHT])), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[RIGHT], + grove_version + )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT] + &[RIGHT, RIGHT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT, RIGHT] + &[RIGHT, RIGHT, RIGHT], + grove_version )), Op::Child, Op::Child, @@ -505,6 +579,7 @@ pub mod tests { #[test] fn chunk_greater_than_max_should_equal_max_depth() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -529,6 +604,7 @@ pub mod tests { #[test] fn build_chunk_after_traversal_depth_2() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -549,27 +625,36 @@ pub mod tests { vec![ Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, LEFT, LEFT] + &[RIGHT, LEFT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT] + &[RIGHT, LEFT], + grove_version )), Op::Parent, Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, LEFT, RIGHT] + &[RIGHT, LEFT, RIGHT], + grove_version )), Op::Child, - Op::Push(traverse_get_kv_feature_type(&mut tree_walker, &[RIGHT])), + Op::Push(traverse_get_kv_feature_type( + &mut tree_walker, + &[RIGHT], + grove_version + )), Op::Parent, Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, RIGHT] + &[RIGHT, RIGHT], + grove_version )), Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, RIGHT, RIGHT] + &[RIGHT, RIGHT, RIGHT], + grove_version )), Op::Child, Op::Child, @@ -584,12 +669,13 @@ pub mod tests { .expect("should reconstruct tree"); assert_eq!( Node::Hash(computed_tree.hash().unwrap()), - traverse_get_node_hash(&mut tree_walker, &[RIGHT]) + traverse_get_node_hash(&mut tree_walker, &[RIGHT], grove_version) ); } #[test] fn build_chunk_after_traversal_depth_1() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -608,16 +694,19 @@ pub mod tests { vec![ Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, LEFT, LEFT] + &[RIGHT, LEFT, LEFT], + grove_version )), Op::Push(traverse_get_kv_feature_type( &mut tree_walker, - &[RIGHT, LEFT] + &[RIGHT, LEFT], + grove_version )), Op::Parent, Op::Push(traverse_get_node_hash( &mut tree_walker, - &[RIGHT, LEFT, RIGHT] + &[RIGHT, LEFT, RIGHT], + grove_version )), Op::Child, ] @@ -628,12 +717,13 @@ pub mod tests { .expect("should reconstruct tree"); assert_eq!( Node::Hash(computed_tree.hash().unwrap()), - traverse_get_node_hash(&mut tree_walker, &[RIGHT, LEFT]) + traverse_get_node_hash(&mut tree_walker, &[RIGHT, LEFT], grove_version) ); } #[test] fn test_chunk_encoding() { + let grove_version = GroveVersion::latest(); let chunk = vec![ Op::Push(Node::Hash([0; 32])), Op::Push(Node::KVValueHashFeatureType( @@ -653,6 +743,7 @@ pub mod tests { #[test] fn test_height_proof_generation() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); @@ -666,14 +757,30 @@ pub mod tests { assert_eq!( height_proof, vec![ - Op::Push(traverse_get_kv_hash(&mut tree_walker, &[LEFT, LEFT])), - Op::Push(traverse_get_kv_hash(&mut tree_walker, &[LEFT])), + Op::Push(traverse_get_kv_hash( + &mut tree_walker, + &[LEFT, LEFT], + grove_version + )), + Op::Push(traverse_get_kv_hash( + &mut tree_walker, + &[LEFT], + grove_version + )), Op::Parent, - Op::Push(traverse_get_node_hash(&mut tree_walker, &[LEFT, RIGHT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[LEFT, RIGHT], + grove_version + )), Op::Child, - Op::Push(traverse_get_kv_hash(&mut tree_walker, &[])), + Op::Push(traverse_get_kv_hash(&mut tree_walker, &[], grove_version)), Op::Parent, - Op::Push(traverse_get_node_hash(&mut tree_walker, &[RIGHT])), + Op::Push(traverse_get_node_hash( + &mut tree_walker, + &[RIGHT], + grove_version + )), Op::Child, ] ); @@ -681,6 +788,7 @@ pub mod tests { #[test] fn test_height_proof_verification() { + let grove_version = GroveVersion::latest(); let mut tree = build_tree_10_nodes(); let mut tree_walker = RefWalker::new(&mut tree, PanicSource {}); diff --git a/merk/src/proofs/query/mod.rs b/merk/src/proofs/query/mod.rs index 1938e493..669940cc 100644 --- a/merk/src/proofs/query/mod.rs +++ b/merk/src/proofs/query/mod.rs @@ -72,7 +72,7 @@ pub struct SubqueryBranch { #[cfg(any(feature = "full", feature = "verify"))] /// `Query` represents one or more keys or ranges of keys, which can be used to -/// resolve a proof which will include all of the requested values. +/// resolve a proof which will include all the requested values. #[derive(Debug, Default, Clone, PartialEq)] pub struct Query { /// Items @@ -459,7 +459,7 @@ impl Query { } } - /// Check if has subquery + /// Check if there is a subquery pub fn has_subquery(&self) -> bool { // checks if a query has subquery items if self.default_subquery_branch.subquery.is_some() @@ -471,7 +471,7 @@ impl Query { false } - /// Check if has only keys + /// Check if there are only keys pub fn has_only_keys(&self) -> bool { // checks if all searched for items are keys self.items.iter().all(|a| a.is_key()) @@ -862,7 +862,7 @@ mod test { *, }; use crate::{ - proofs::query::{query_item::QueryItem::RangeAfter, verify}, + proofs::query::verify, test_utils::make_tree_seq, tree::{NoopCommit, PanicSource, RefWalker, TreeNode}, TreeFeatureType::BasicMerkNode, @@ -919,11 +919,12 @@ mod test { } fn verify_keys_test(keys: Vec>, expected_result: Vec>>) { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let (proof, ..) = walker - .create_full_proof( + .create_proof( keys.clone() .into_iter() .map(QueryItem::Key) @@ -931,6 +932,7 @@ mod test { .as_slice(), None, true, + grove_version, ) .unwrap() .expect("failed to create proof"); @@ -1159,11 +1161,12 @@ mod test { #[test] fn empty_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let (proof, absence, ..) = walker - .create_full_proof(vec![].as_slice(), None, true) + .create_proof(vec![].as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1205,12 +1208,13 @@ mod test { #[test] fn root_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::Key(vec![5])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1260,12 +1264,13 @@ mod test { #[test] fn leaf_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::Key(vec![3])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1315,12 +1320,13 @@ mod test { #[test] fn double_leaf_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::Key(vec![3]), QueryItem::Key(vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1377,6 +1383,7 @@ mod test { #[test] fn all_nodes_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); @@ -1386,7 +1393,7 @@ mod test { QueryItem::Key(vec![7]), ]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1447,12 +1454,13 @@ mod test { #[test] fn global_edge_absence_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::Key(vec![8])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1501,12 +1509,13 @@ mod test { #[test] fn absence_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::Key(vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1558,6 +1567,7 @@ mod test { #[test] fn doc_proof() { + let grove_version = GroveVersion::latest(); let mut tree = TreeNode::new(vec![5], vec![5], None, BasicMerkNode) .unwrap() .attach( @@ -1640,7 +1650,7 @@ mod test { QueryItem::Key(vec![4]), ]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1797,6 +1807,7 @@ mod test { #[test] fn range_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_tree_seq(10, grove_version); let mut walker = RefWalker::new(&mut tree, PanicSource {}); @@ -1804,7 +1815,7 @@ mod test { vec![0, 0, 0, 0, 0, 0, 0, 5]..vec![0, 0, 0, 0, 0, 0, 0, 7], )]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -1905,7 +1916,7 @@ mod test { vec![0, 0, 0, 0, 0, 0, 0, 5]..vec![0, 0, 0, 0, 0, 0, 0, 7], )]; let (proof, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -1930,6 +1941,7 @@ mod test { #[test] fn range_proof_inclusive() { + let grove_version = GroveVersion::latest(); let mut tree = make_tree_seq(10, grove_version); let mut walker = RefWalker::new(&mut tree, PanicSource {}); @@ -1937,7 +1949,7 @@ mod test { vec![0, 0, 0, 0, 0, 0, 0, 5]..=vec![0, 0, 0, 0, 0, 0, 0, 7], )]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2040,7 +2052,7 @@ mod test { vec![0, 0, 0, 0, 0, 0, 0, 5]..=vec![0, 0, 0, 0, 0, 0, 0, 7], )]; let (proof, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -2067,12 +2079,13 @@ mod test { #[test] fn range_from_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeFrom(vec![5]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2145,13 +2158,13 @@ mod test { let query_items = vec![QueryItem::RangeFrom(vec![5]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::Key(vec![5])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2177,7 +2190,7 @@ mod test { let query_items = vec![QueryItem::RangeFrom(vec![5]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2187,7 +2200,7 @@ mod test { QueryItem::Key(vec![7]), ]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2216,13 +2229,13 @@ mod test { let query_items = vec![QueryItem::RangeFrom(vec![5]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeFrom(vec![5]..)]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2251,7 +2264,7 @@ mod test { let query_items = vec![QueryItem::RangeFrom(vec![5]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -2275,12 +2288,13 @@ mod test { #[test] fn range_to_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeTo(..vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2381,13 +2395,13 @@ mod test { let query_items = vec![QueryItem::RangeTo(..vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![2])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2413,13 +2427,13 @@ mod test { let query_items = vec![QueryItem::RangeTo(..vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![3])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2448,13 +2462,13 @@ mod test { let query_items = vec![QueryItem::RangeTo(..vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeTo(..vec![6])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2488,7 +2502,7 @@ mod test { let query_items = vec![QueryItem::RangeTo(..vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -2519,7 +2533,7 @@ mod test { let query_items = vec![QueryItem::RangeTo(..vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), false) + .create_proof(query_items.as_slice(), Some(2), false, grove_version) .unwrap() .expect("create_proof errored"); @@ -2544,12 +2558,13 @@ mod test { #[test] fn range_to_proof_inclusive() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2650,13 +2665,13 @@ mod test { let query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![2])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2682,13 +2697,13 @@ mod test { let query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![3])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2717,13 +2732,13 @@ mod test { let query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2757,7 +2772,7 @@ mod test { let query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -2788,7 +2803,7 @@ mod test { let query_items = vec![QueryItem::RangeToInclusive(..=vec![6])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), false) + .create_proof(query_items.as_slice(), Some(1), false, grove_version) .unwrap() .expect("create_proof errored"); @@ -2810,12 +2825,13 @@ mod test { #[test] fn range_after_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); - let query_items = vec![RangeAfter(vec![3]..)]; + let query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2916,13 +2932,13 @@ mod test { let query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![4])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2948,13 +2964,13 @@ mod test { let query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![5])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -2983,13 +2999,13 @@ mod test { let query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3021,9 +3037,9 @@ mod test { let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); - let query_items = vec![RangeAfter(vec![3]..)]; + let query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3052,9 +3068,9 @@ mod test { let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); - let query_items = vec![RangeAfter(vec![3]..)]; + let query_items = vec![QueryItem::RangeAfter(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(3), false) + .create_proof(query_items.as_slice(), Some(3), false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3079,12 +3095,13 @@ mod test { #[test] fn range_after_to_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3175,13 +3192,13 @@ mod test { let query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![4])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3207,13 +3224,13 @@ mod test { let query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![5])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3242,13 +3259,13 @@ mod test { let query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3277,7 +3294,7 @@ mod test { let query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3303,7 +3320,7 @@ mod test { let query_items = vec![QueryItem::RangeAfterTo(vec![3]..vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(300), false) + .create_proof(query_items.as_slice(), Some(300), false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3328,12 +3345,13 @@ mod test { #[test] fn range_after_to_proof_inclusive() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3423,13 +3441,13 @@ mod test { let query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![4])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3455,13 +3473,13 @@ mod test { let query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![5])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3490,13 +3508,13 @@ mod test { let query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![7])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3525,7 +3543,7 @@ mod test { let query_items = vec![QueryItem::RangeAfterToInclusive(vec![3]..=vec![7])]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3549,12 +3567,13 @@ mod test { #[test] fn range_full_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeFull(..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3663,13 +3682,13 @@ mod test { let query_items = vec![QueryItem::RangeFull(..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![2])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3695,13 +3714,13 @@ mod test { let query_items = vec![QueryItem::RangeFull(..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), true) + .create_proof(query_items.as_slice(), Some(2), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeToInclusive(..=vec![3])]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3730,13 +3749,13 @@ mod test { let query_items = vec![QueryItem::RangeFull(..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(100), true) + .create_proof(query_items.as_slice(), Some(100), true, grove_version) .unwrap() .expect("create_proof errored"); let equivalent_query_items = vec![QueryItem::RangeFull(..)]; let (equivalent_proof, equivalent_absence, ..) = walker - .create_full_proof(equivalent_query_items.as_slice(), None, true) + .create_proof(equivalent_query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3772,7 +3791,7 @@ mod test { let query_items = vec![QueryItem::RangeFull(..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3805,7 +3824,7 @@ mod test { let query_items = vec![QueryItem::RangeFull(..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), Some(2), false) + .create_proof(query_items.as_slice(), Some(2), false, grove_version) .unwrap() .expect("create_proof errored"); @@ -3830,12 +3849,13 @@ mod test { #[test] fn proof_with_limit() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeFrom(vec![2]..)]; let (proof, _, limit) = walker - .create_full_proof(query_items.as_slice(), Some(1), true) + .create_proof(query_items.as_slice(), Some(1), true, grove_version) .unwrap() .expect("create_proof errored"); @@ -3904,12 +3924,13 @@ mod test { #[test] fn right_to_left_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_6_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let query_items = vec![QueryItem::RangeFrom(vec![3]..)]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, false) + .create_proof(query_items.as_slice(), None, false, grove_version) .unwrap() .expect("create_proof errored"); @@ -4009,6 +4030,7 @@ mod test { #[test] fn range_proof_missing_upper_bound() { + let grove_version = GroveVersion::latest(); let mut tree = make_tree_seq(10, grove_version); let mut walker = RefWalker::new(&mut tree, PanicSource {}); @@ -4016,7 +4038,7 @@ mod test { vec![0, 0, 0, 0, 0, 0, 0, 5]..vec![0, 0, 0, 0, 0, 0, 0, 6, 5], )]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4111,6 +4133,7 @@ mod test { #[test] fn range_proof_missing_lower_bound() { + let grove_version = GroveVersion::latest(); let mut tree = make_tree_seq(10, grove_version); let mut walker = RefWalker::new(&mut tree, PanicSource {}); @@ -4119,7 +4142,7 @@ mod test { QueryItem::Range(vec![0, 0, 0, 0, 0, 0, 0, 5, 5]..vec![0, 0, 0, 0, 0, 0, 0, 7]), ]; let (proof, absence, ..) = walker - .create_full_proof(query_items.as_slice(), None, true) + .create_proof(query_items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4210,6 +4233,7 @@ mod test { #[test] fn subset_proof() { + let grove_version = GroveVersion::latest(); let mut tree = make_tree_seq(10, grove_version); let expected_hash = tree.hash().unwrap().to_owned(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); @@ -4219,7 +4243,7 @@ mod test { query.insert_all(); let (proof, ..) = walker - .create_full_proof(query.items.as_slice(), None, true) + .create_proof(query.items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4246,7 +4270,7 @@ mod test { query.insert_range_inclusive(vec![0, 0, 0, 0, 0, 0, 0, 2]..=vec![0, 0, 0, 0, 0, 0, 0, 5]); query.insert_range(vec![0, 0, 0, 0, 0, 0, 0, 7]..vec![0, 0, 0, 0, 0, 0, 0, 10]); let (proof, ..) = walker - .create_full_proof(query.items.as_slice(), None, true) + .create_proof(query.items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4277,7 +4301,7 @@ mod test { query.insert_range_inclusive(vec![0, 0, 0, 0, 0, 0, 0, 2]..=vec![0, 0, 0, 0, 0, 0, 0, 5]); query.insert_range(vec![0, 0, 0, 0, 0, 0, 0, 6]..vec![0, 0, 0, 0, 0, 0, 0, 10]); let (proof, ..) = walker - .create_full_proof(query.items.as_slice(), None, true) + .create_proof(query.items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4308,7 +4332,7 @@ mod test { query.insert_range_inclusive(vec![0, 0, 0, 0, 0, 0, 0, 1]..=vec![0, 0, 0, 0, 0, 0, 0, 3]); query.insert_range_inclusive(vec![0, 0, 0, 0, 0, 0, 0, 2]..=vec![0, 0, 0, 0, 0, 0, 0, 5]); let (proof, ..) = walker - .create_full_proof(query.items.as_slice(), None, true) + .create_proof(query.items.as_slice(), None, true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4338,7 +4362,7 @@ mod test { let mut query = Query::new(); query.insert_range_from(vec![0, 0, 0, 0, 0, 0, 0, 1]..); let (proof, ..) = walker - .create_full_proof(query.items.as_slice(), Some(5), true) + .create_proof(query.items.as_slice(), Some(5), true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4367,6 +4391,7 @@ mod test { #[test] fn break_subset_proof() { + let grove_version = GroveVersion::latest(); // TODO: move this to where you'd set the constraints for this definition // goal is to show that ones limit and offset values are involved // whether a query is subset or not now also depends on the state @@ -4384,7 +4409,7 @@ mod test { let mut query = Query::new(); query.insert_range_from(vec![0, 0, 0, 0, 0, 0, 0, 1]..); let (proof, ..) = walker - .create_full_proof(query.items.as_slice(), Some(3), true) + .create_proof(query.items.as_slice(), Some(3), true, grove_version) .unwrap() .expect("create_proof errored"); @@ -4462,6 +4487,7 @@ mod test { #[test] fn verify_ops() { + let grove_version = GroveVersion::latest(); let mut tree = TreeNode::new(vec![5], vec![5], None, BasicMerkNode).unwrap(); tree.commit(&mut NoopCommit {}, &|_, _| Ok(0)) .unwrap() @@ -4471,7 +4497,12 @@ mod test { let mut walker = RefWalker::new(&mut tree, PanicSource {}); let (proof, ..) = walker - .create_full_proof(vec![QueryItem::Key(vec![5])].as_slice(), None, true) + .create_proof( + vec![QueryItem::Key(vec![5])].as_slice(), + None, + true, + grove_version, + ) .unwrap() .expect("failed to create proof"); let mut bytes = vec![]; @@ -4488,6 +4519,7 @@ mod test { #[test] #[should_panic(expected = "verify failed")] fn verify_ops_mismatched_hash() { + let grove_version = GroveVersion::latest(); let mut tree = TreeNode::new(vec![5], vec![5], None, BasicMerkNode).unwrap(); tree.commit(&mut NoopCommit {}, &|_, _| Ok(0)) .unwrap() @@ -4496,7 +4528,12 @@ mod test { let mut walker = RefWalker::new(&mut tree, PanicSource {}); let (proof, ..) = walker - .create_full_proof(vec![QueryItem::Key(vec![5])].as_slice(), None, true) + .create_proof( + vec![QueryItem::Key(vec![5])].as_slice(), + None, + true, + grove_version, + ) .unwrap() .expect("failed to create proof"); let mut bytes = vec![]; @@ -4511,11 +4548,12 @@ mod test { #[test] #[should_panic(expected = "verify failed")] fn verify_query_mismatched_hash() { + let grove_version = GroveVersion::latest(); let mut tree = make_3_node_tree(); let mut walker = RefWalker::new(&mut tree, PanicSource {}); let keys = vec![vec![5], vec![7]]; let (proof, ..) = walker - .create_full_proof( + .create_proof( keys.clone() .into_iter() .map(QueryItem::Key) @@ -4523,6 +4561,7 @@ mod test { .as_slice(), None, true, + grove_version, ) .unwrap() .expect("failed to create proof"); diff --git a/merk/src/tree/walk/mod.rs b/merk/src/tree/walk/mod.rs index 5ad47b6f..464d1477 100644 --- a/merk/src/tree/walk/mod.rs +++ b/merk/src/tree/walk/mod.rs @@ -404,6 +404,7 @@ mod test { #[test] fn walk_modified() { + let grove_version = GroveVersion::latest(); let tree = TreeNode::new(b"test".to_vec(), b"abc".to_vec(), None, BasicMerkNode) .unwrap() .attach( @@ -431,6 +432,7 @@ mod test { #[test] fn walk_stored() { + let grove_version = GroveVersion::latest(); let mut tree = TreeNode::new(b"test".to_vec(), b"abc".to_vec(), None, BasicMerkNode) .unwrap() .attach( @@ -461,6 +463,7 @@ mod test { #[test] fn walk_pruned() { + let grove_version = GroveVersion::latest(); let tree = TreeNode::from_fields( b"test".to_vec(), b"abc".to_vec(), @@ -496,6 +499,7 @@ mod test { #[test] fn walk_none() { + let grove_version = GroveVersion::latest(); let tree = TreeNode::new(b"test".to_vec(), b"abc".to_vec(), None, BasicMerkNode).unwrap(); let source = MockSource {}; diff --git a/node-grove/Cargo.toml b/node-grove/Cargo.toml index 1e18a6f3..7656ea7d 100644 --- a/node-grove/Cargo.toml +++ b/node-grove/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["cdylib"] [dependencies] grovedb = { path = "../grovedb", features = ["full", "estimated_costs"] } +grovedb-version = { path = "../grovedb-version" } [dependencies.neon] version = "0.10.1" diff --git a/node-grove/src/lib.rs b/node-grove/src/lib.rs index 032eaa3d..e9e4ac0a 100644 --- a/node-grove/src/lib.rs +++ b/node-grove/src/lib.rs @@ -1,31 +1,3 @@ -// MIT LICENSE -// -// Copyright (c) 2021 Dash Core Group -// -// Permission is hereby granted, free of charge, to any -// person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the -// Software without restriction, including without -// limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software -// is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice -// shall be included in all copies or substantial portions -// of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - //! GroveDB binding for Node.JS #![deny(missing_docs)] @@ -35,6 +7,7 @@ mod converter; use std::{option::Option::None, path::Path, sync::mpsc, thread}; use grovedb::{GroveDb, Transaction, TransactionArg}; +use grovedb_version::version::GroveVersion; use neon::prelude::*; type DbCallback = Box FnOnce(&'a GroveDb, TransactionArg, &Channel) + Send>; @@ -348,7 +321,7 @@ impl GroveDbWrapper { path.as_slice(), &key, using_transaction.then_some(transaction).flatten(), - grove_version, + GroveVersion::latest(), ) .unwrap(); // Todo: Costs @@ -398,6 +371,7 @@ impl GroveDbWrapper { &key, None, using_transaction.then_some(transaction).flatten(), + GroveVersion::latest(), ) .unwrap(); // Todo: Costs; @@ -447,7 +421,7 @@ impl GroveDbWrapper { element, None, using_transaction.then_some(transaction).flatten(), - grove_version, + GroveVersion::latest(), ) .unwrap(); // Todo: Costs; @@ -490,7 +464,7 @@ impl GroveDbWrapper { &key, element, using_transaction.then_some(transaction).flatten(), - grove_version, + GroveVersion::latest(), ) .unwrap(); // Todo: Costs; @@ -669,6 +643,7 @@ impl GroveDbWrapper { true, true, using_transaction.then_some(transaction).flatten(), + GroveVersion::latest(), ) .unwrap(); // Todo: Costs; @@ -765,7 +740,7 @@ impl GroveDbWrapper { let result = grove_db .root_hash( using_transaction.then_some(transaction).flatten(), - grove_version, + GroveVersion::latest(), ) .unwrap(); // Todo: Costs;