diff --git a/grovedb/src/operations/proof/verify.rs b/grovedb/src/operations/proof/verify.rs index ac13306c..9e8c6e44 100644 --- a/grovedb/src/operations/proof/verify.rs +++ b/grovedb/src/operations/proof/verify.rs @@ -260,7 +260,7 @@ impl ProofVerifier { query: &PathQuery, is_verbose: bool, ) -> Result<[u8; 32], Error> { - let (proof_version, proof) = read_and_consume_proof_version(proof)?; + let (_proof_version, proof) = read_and_consume_proof_version(proof)?; let mut proof_reader = ProofReader::new_with_verbose_status(proof, is_verbose); let path_slices = query.path.iter().map(|x| x.as_slice()).collect::>(); diff --git a/grovedb/src/tests/mod.rs b/grovedb/src/tests/mod.rs index 922f5e9b..451b2307 100644 --- a/grovedb/src/tests/mod.rs +++ b/grovedb/src/tests/mod.rs @@ -2929,7 +2929,7 @@ fn test_tree_value_exists_method_tx() { #[test] fn test_storage_wipe() { let db = make_test_grovedb(); - let path = db._tmp_dir.path(); + let _path = db._tmp_dir.path(); // Test keys in non-root tree db.insert( diff --git a/grovedb/src/versioning.rs b/grovedb/src/versioning.rs index ca9a2924..a041b3d8 100644 --- a/grovedb/src/versioning.rs +++ b/grovedb/src/versioning.rs @@ -1,8 +1,8 @@ use std::io::Cursor; -use integer_encoding::{VarInt, VarIntReader, VarIntWriter}; +use integer_encoding::{VarInt, VarIntReader}; -use crate::{Error, Error::InternalError}; +use crate::Error; pub(crate) const PROOF_VERSION: u32 = 1; @@ -44,11 +44,11 @@ mod tests { #[test] fn read_correct_version() { - let mut data = vec![1, 2, 3]; + let data = vec![1, 2, 3]; let version = 500_u32; // prepend the version information to the data vector - let mut new_data = prepend_version_to_bytes(data, version).unwrap(); + let new_data = prepend_version_to_bytes(data, version).unwrap(); assert_eq!(new_data, [244, 3, 1, 2, 3]); // show that read_version doesn't consume diff --git a/merk/benches/merk.rs b/merk/benches/merk.rs index 7846a78c..b0f9cca4 100644 --- a/merk/benches/merk.rs +++ b/merk/benches/merk.rs @@ -30,9 +30,14 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use grovedb_costs::storage_cost::removal::StorageRemovedBytes::BasicStorageRemoval; +use grovedb_merk::{ + proofs, + test_utils::{make_batch_rand, make_batch_seq, make_del_batch_rand, TempMerk}, + tree::kv::ValueDefinedCostType, + Merk, +}; use grovedb_path::SubtreePath; use grovedb_storage::{rocksdb_storage::test_utils::TempStorage, Storage}; -use merk::{proofs::encode_into as encode_proof_into, test_utils::*, Merk}; use rand::prelude::*; /// 1 million gets in 2k batches @@ -46,11 +51,12 @@ pub fn get(c: &mut Criterion) { let mut batches = vec![]; for i in 0..num_batches { let batch = make_batch_rand(batch_size, i); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -72,7 +78,9 @@ pub fn get(c: &mut Criterion) { let key_index = (i / num_batches) as usize; let key = &batches[batch_index][key_index].0; - merk.get(key, true).unwrap().expect("get failed"); + merk.get(key, true, None:: Option>) + .unwrap() + .expect("get failed"); i = (i + 1) % initial_size; }) @@ -98,11 +106,12 @@ pub fn insert_1m_2k_seq(c: &mut Criterion) { b.iter_with_large_drop(|| { let batch = &batches[i % n_batches]; - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -137,11 +146,12 @@ pub fn insert_1m_2k_rand(c: &mut Criterion) { b.iter_with_large_drop(|| { let batch = &batches[i % n_batches]; - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -169,11 +179,12 @@ pub fn update_1m_2k_seq(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_seq(((i * batch_size) as u64)..((i + 1) * batch_size) as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -193,11 +204,12 @@ pub fn update_1m_2k_seq(c: &mut Criterion) { b.iter_with_large_drop(|| { let batch = &batches[i % n_batches]; - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -225,11 +237,12 @@ pub fn update_1m_2k_rand(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_rand(batch_size as u64, i as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -249,11 +262,12 @@ pub fn update_1m_2k_rand(c: &mut Criterion) { b.iter_with_large_drop(|| { let batch = &batches[i % n_batches]; - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -283,11 +297,12 @@ pub fn delete_1m_2k_rand(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_rand(batch_size as u64, i as u64); let delete_batch = make_del_batch_rand(batch_size as u64, i as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -311,11 +326,12 @@ pub fn delete_1m_2k_rand(c: &mut Criterion) { // Merk tree is kept with 1m elements before each bench iteration for more or // less same inputs. - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( insert_batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -328,11 +344,12 @@ pub fn delete_1m_2k_rand(c: &mut Criterion) { .expect("apply failed"); b.iter_with_large_drop(|| { - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( delete_batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -361,11 +378,12 @@ pub fn prove_1m_2k_rand(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_rand(batch_size as u64, i as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -378,7 +396,7 @@ pub fn prove_1m_2k_rand(c: &mut Criterion) { .expect("apply failed"); let mut prove_keys = Vec::with_capacity(batch_size); for (key, _) in batch.iter() { - prove_keys.push(merk::proofs::query::query_item::QueryItem::Key(key.clone())); + prove_keys.push(proofs::query::query_item::QueryItem::Key(key.clone())); } prove_keys_per_batch.push(prove_keys); batches.push(batch); @@ -409,11 +427,12 @@ pub fn build_trunk_chunk_1m_2k_rand(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_rand(batch_size as u64, i as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -434,7 +453,7 @@ pub fn build_trunk_chunk_1m_2k_rand(c: &mut Criterion) { let (ops, _) = merk.walk(|walker| walker.unwrap().create_trunk_proof().unwrap().unwrap()); - encode_proof_into(ops.iter(), &mut bytes); + proofs::encode_into(ops.iter(), &mut bytes); }); }); } @@ -450,11 +469,12 @@ pub fn chunkproducer_rand_1m_1_rand(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_rand(batch_size as u64, i as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -489,11 +509,12 @@ pub fn chunk_iter_1m_1(c: &mut Criterion) { for i in 0..n_batches { let batch = make_batch_rand(batch_size as u64, i as u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -530,11 +551,12 @@ pub fn restore_500_1(c: &mut Criterion) { let mut merk = TempMerk::new(); let batch = make_batch_rand(merk_size as u64, 0_u64); - merk.apply_unchecked::<_, Vec, _, _, _>( + merk.apply_unchecked::<_, Vec, _, _, _, _>( &batch, &[], None, &|_k, _v| Ok(0), + None::<&fn(&[u8]) -> Option>, &mut |_costs, _old_value, _value| Ok((false, None)), &mut |_a, key_bytes_to_remove, value_bytes_to_remove| { Ok(( @@ -560,7 +582,13 @@ pub fn restore_500_1(c: &mut Criterion) { .0 .get_immediate_storage_context(SubtreePath::empty(), &tx) .unwrap(); - let m = Merk::open_standalone(ctx, false).unwrap().unwrap(); + let m = Merk::open_standalone( + ctx, + false, + None::<&fn(&[u8]) -> Option>, + ) + .unwrap() + .unwrap(); let mut restorer = Merk::restore(m, root_hash); for chunk in data.1 { diff --git a/merk/benches/ops.rs b/merk/benches/ops.rs index a1fa8bf2..f9576fba 100644 --- a/merk/benches/ops.rs +++ b/merk/benches/ops.rs @@ -29,7 +29,12 @@ //! Merk benches ops use criterion::{criterion_group, criterion_main, Criterion}; -use merk::{owner::Owner, test_utils::*}; +use grovedb_merk::{ + owner::Owner, + test_utils::{ + apply_memonly_unchecked, make_batch_rand, make_batch_seq, make_tree_rand, make_tree_seq, + }, +}; /// 1m sequential inserts in 10k batches, memonly fn insert_1m_10k_seq_memonly(c: &mut Criterion) { diff --git a/merk/src/merk/committer.rs b/merk/src/merk/committer.rs index af460bd8..9fb02987 100644 --- a/merk/src/merk/committer.rs +++ b/merk/src/merk/committer.rs @@ -1,5 +1,3 @@ -use grovedb_costs::storage_cost::key_value_cost::KeyValueStorageCost; - use crate::{ merk::BatchValue, tree::{Commit, TreeNode}, diff --git a/merk/src/merk/mod.rs b/merk/src/merk/mod.rs index 9c025dcb..92f7cc93 100644 --- a/merk/src/merk/mod.rs +++ b/merk/src/merk/mod.rs @@ -52,10 +52,8 @@ use std::{ use committer::MerkCommitter; use grovedb_costs::{ cost_return_on_error, cost_return_on_error_default, cost_return_on_error_no_add, - storage_cost::{ - key_value_cost::KeyValueStorageCost, removal::StorageRemovedBytes, StorageCost, - }, - ChildrenSizesWithValue, CostContext, CostResult, CostsExt, FeatureSumLength, OperationCost, + storage_cost::key_value_cost::KeyValueStorageCost, ChildrenSizesWithValue, CostContext, + CostResult, CostsExt, FeatureSumLength, OperationCost, }; use grovedb_storage::{self, Batch, RawIterator, StorageContext}; use source::MerkSource; @@ -63,10 +61,9 @@ use source::MerkSource; use crate::{ error::Error, merk::{defaults::ROOT_KEY_KEY, options::MerkOptions}, - proofs::{query::query_item::QueryItem, Op as ProofOp, Query}, + proofs::{query::query_item::QueryItem, Query}, tree::{ - kv::ValueDefinedCostType, AuxMerkBatch, Commit, CryptoHash, Fetch, Op, RefWalker, TreeNode, - NULL_HASH, + kv::ValueDefinedCostType, AuxMerkBatch, CryptoHash, Op, RefWalker, TreeNode, NULL_HASH, }, Error::{CostsError, EdError, StorageError}, MerkType::{BaseMerk, LayeredMerk, StandaloneMerk}, diff --git a/merk/src/proofs/chunk.rs b/merk/src/proofs/chunk.rs index 5e852ec1..1e3b9fb1 100644 --- a/merk/src/proofs/chunk.rs +++ b/merk/src/proofs/chunk.rs @@ -397,7 +397,6 @@ pub(crate) fn verify_trunk>>( mod tests { use std::usize; - use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval; use grovedb_storage::StorageContext; use super::{super::tree::Tree, *}; diff --git a/merk/src/proofs/query/mod.rs b/merk/src/proofs/query/mod.rs index 7a122f23..4ecc808b 100644 --- a/merk/src/proofs/query/mod.rs +++ b/merk/src/proofs/query/mod.rs @@ -782,7 +782,6 @@ where #[allow(deprecated)] #[cfg(test)] mod test { - use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval; use super::{ super::{encoding::encode_into, *}, diff --git a/merk/src/tree/commit.rs b/merk/src/tree/commit.rs index e7bcc66a..24c1d996 100644 --- a/merk/src/tree/commit.rs +++ b/merk/src/tree/commit.rs @@ -28,14 +28,10 @@ //! Merk tree commit -#[cfg(feature = "full")] -use grovedb_costs::storage_cost::{removal::StorageRemovedBytes, StorageCost}; - #[cfg(feature = "full")] use super::TreeNode; #[cfg(feature = "full")] use crate::error::Error; -use crate::tree::kv::ValueDefinedCostType; #[cfg(feature = "full")] /// To be used when committing a tree (writing it to a store after applying the diff --git a/merk/src/tree/mod.rs b/merk/src/tree/mod.rs index b257d8db..cb732b56 100644 --- a/merk/src/tree/mod.rs +++ b/merk/src/tree/mod.rs @@ -992,7 +992,6 @@ pub const fn side_to_str(left: bool) -> &'static str { #[cfg(feature = "full")] #[cfg(test)] mod test { - use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval; use super::{commit::NoopCommit, hash::NULL_HASH, TreeNode}; use crate::tree::{ diff --git a/merk/src/tree/ops.rs b/merk/src/tree/ops.rs index 4b3a3d34..a55adbe9 100644 --- a/merk/src/tree/ops.rs +++ b/merk/src/tree/ops.rs @@ -153,7 +153,7 @@ impl Fetch for PanicSource { fn fetch( &self, _link: &Link, - value_defined_cost_fn: Option<&impl Fn(&[u8]) -> Option>, + _value_defined_cost_fn: Option<&impl Fn(&[u8]) -> Option>, ) -> CostResult { unreachable!("'fetch' should not have been called") } diff --git a/merk/src/tree/walk/mod.rs b/merk/src/tree/walk/mod.rs index 35e476f3..e5401814 100644 --- a/merk/src/tree/walk/mod.rs +++ b/merk/src/tree/walk/mod.rs @@ -36,7 +36,7 @@ mod ref_walker; #[cfg(feature = "full")] pub use fetch::Fetch; #[cfg(feature = "full")] -use grovedb_costs::{cost_return_on_error, CostContext, CostResult, CostsExt, OperationCost}; +use grovedb_costs::{cost_return_on_error, CostResult, CostsExt, OperationCost}; use grovedb_costs::{ cost_return_on_error_no_add, storage_cost::{removal::StorageRemovedBytes, StorageCost}, @@ -397,7 +397,7 @@ where #[cfg(feature = "full")] #[cfg(test)] mod test { - use grovedb_costs::{storage_cost::removal::StorageRemovedBytes::NoStorageRemoval, CostsExt}; + use grovedb_costs::CostsExt; use super::{super::NoopCommit, *}; use crate::tree::{TreeFeatureType::BasicMerkNode, TreeNode}; diff --git a/storage/src/rocksdb_storage/storage.rs b/storage/src/rocksdb_storage/storage.rs index b386ecfc..b4b1b1d4 100644 --- a/storage/src/rocksdb_storage/storage.rs +++ b/storage/src/rocksdb_storage/storage.rs @@ -40,8 +40,8 @@ use grovedb_path::SubtreePath; use integer_encoding::VarInt; use lazy_static::lazy_static; use rocksdb::{ - checkpoint::Checkpoint, ColumnFamily, ColumnFamilyDescriptor, OptimisticTransactionDB, Options, - Transaction, WriteBatchWithTransaction, DB, DEFAULT_COLUMN_FAMILY_NAME, + checkpoint::Checkpoint, ColumnFamily, ColumnFamilyDescriptor, OptimisticTransactionDB, + Transaction, WriteBatchWithTransaction, DEFAULT_COLUMN_FAMILY_NAME, }; use super::{ @@ -53,7 +53,6 @@ use crate::{ error::Error::{CostError, RocksDBError}, storage::AbstractBatchOperation, worst_case_costs::WorstKeyLength, - Error::StorageError, Storage, StorageBatch, };