From 355b87b51bf4ecb5a82a7b8a8624aa93e7f6004c Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 14 Jan 2025 15:44:24 +0700 Subject: [PATCH 1/5] reduce dependency tree --- costs/Cargo.toml | 4 +- costs/src/storage_cost/removal.rs | 8 +- grovedb-epoch-based-storage-flags/Cargo.toml | 4 +- grovedb-epoch-based-storage-flags/src/lib.rs | 70 ++++++----- grovedb-version/Cargo.toml | 2 +- grovedb/Cargo.toml | 22 ++-- grovedb/benches/insertion_benchmark.rs | 26 ++--- grovedb/src/batch/batch_structure.rs | 26 ++--- .../estimated_costs/average_case_costs.rs | 24 ++-- grovedb/src/batch/estimated_costs/mod.rs | 12 +- .../batch/estimated_costs/worst_case_costs.rs | 24 ++-- grovedb/src/batch/just_in_time_cost_tests.rs | 6 +- grovedb/src/batch/key_info.rs | 24 ++-- grovedb/src/batch/mod.rs | 4 +- grovedb/src/batch/mode.rs | 2 +- grovedb/src/batch/multi_insert_cost_tests.rs | 2 +- grovedb/src/batch/options.rs | 10 +- .../src/batch/single_deletion_cost_tests.rs | 2 +- grovedb/src/batch/single_insert_cost_tests.rs | 2 +- .../single_sum_item_deletion_cost_tests.rs | 2 +- .../single_sum_item_insert_cost_tests.rs | 2 +- grovedb/src/element/constructor.rs | 36 +++--- grovedb/src/element/delete.rs | 22 ++-- grovedb/src/element/get.rs | 24 ++-- grovedb/src/element/helpers.rs | 70 +++++------ grovedb/src/element/insert.rs | 22 ++-- grovedb/src/element/mod.rs | 50 ++++---- grovedb/src/element/query.rs | 62 +++++----- grovedb/src/element/serialize.rs | 10 +- grovedb/src/error.rs | 4 +- grovedb/src/lib.rs | 82 ++++++------- grovedb/src/operations/auxiliary.rs | 8 +- grovedb/src/operations/delete/average_case.rs | 2 +- .../src/operations/delete/delete_up_tree.rs | 8 +- grovedb/src/operations/delete/mod.rs | 28 ++--- grovedb/src/operations/delete/worst_case.rs | 4 +- grovedb/src/operations/get/average_case.rs | 8 +- grovedb/src/operations/get/mod.rs | 16 +-- grovedb/src/operations/get/query.rs | 14 +-- grovedb/src/operations/get/worst_case.rs | 8 +- grovedb/src/operations/insert/mod.rs | 20 ++-- grovedb/src/operations/is_empty_tree.rs | 8 +- grovedb/src/operations/mod.rs | 14 +-- grovedb/src/operations/proof/generate.rs | 5 +- grovedb/src/operations/proof/mod.rs | 5 +- grovedb/src/operations/proof/util.rs | 16 +-- grovedb/src/query/mod.rs | 30 ++--- grovedb/src/query_result_type.rs | 16 +-- grovedb/src/reference_path.rs | 24 ++-- grovedb/src/replication.rs | 2 +- merk/Cargo.toml | 33 ++---- merk/src/error.rs | 10 +- .../src/estimated_costs/average_case_costs.rs | 58 +++++----- merk/src/estimated_costs/mod.rs | 30 ++--- merk/src/estimated_costs/worst_case_costs.rs | 36 +++--- merk/src/lib.rs | 30 ++--- merk/src/merk/defaults.rs | 6 +- merk/src/merk/options.rs | 4 +- merk/src/proofs/chunk.rs | 4 +- merk/src/proofs/encoding.rs | 32 ++--- merk/src/proofs/mod.rs | 24 ++-- merk/src/proofs/query/common_path.rs | 2 +- merk/src/proofs/query/insert.rs | 2 +- merk/src/proofs/query/map.rs | 30 ++--- merk/src/proofs/query/merge.rs | 2 +- merk/src/proofs/query/mod.rs | 84 +++++++------- merk/src/proofs/query/query_item/merge.rs | 2 +- merk/src/proofs/query/query_item/mod.rs | 70 +++++------ merk/src/proofs/query/verify.rs | 24 ++-- merk/src/proofs/tree.rs | 56 ++++----- merk/src/test_utils/temp_merk.rs | 18 +-- merk/src/tree/commit.rs | 10 +- merk/src/tree/debug.rs | 109 +++++++++++++----- merk/src/tree/encoding.rs | 16 +-- merk/src/tree/fuzz_tests.rs | 24 ++-- merk/src/tree/hash.rs | 30 ++--- merk/src/tree/iter.rs | 14 +-- merk/src/tree/kv.rs | 26 ++--- merk/src/tree/link.rs | 26 ++--- merk/src/tree/mod.rs | 72 ++++++------ merk/src/tree/ops.rs | 24 ++-- merk/src/tree/tree_feature_type.rs | 18 +-- merk/src/tree/walk/fetch.rs | 10 +- merk/src/tree/walk/mod.rs | 22 ++-- merk/src/tree/walk/ref_walker.rs | 10 +- storage/Cargo.toml | 4 +- visualize/Cargo.toml | 2 +- 87 files changed, 952 insertions(+), 918 deletions(-) diff --git a/costs/Cargo.toml b/costs/Cargo.toml index 44a36342f..aebaab671 100644 --- a/costs/Cargo.toml +++ b/costs/Cargo.toml @@ -10,6 +10,6 @@ repository = "https://github.com/dashpay/grovedb" [dependencies] -thiserror = "1.0.59" -intmap = "2.0.0" +thiserror = "2.0.11" +intmap = "3.0.1" integer-encoding = "4.0.0" diff --git a/costs/src/storage_cost/removal.rs b/costs/src/storage_cost/removal.rs index 9fa7af991..93c4d3960 100644 --- a/costs/src/storage_cost/removal.rs +++ b/costs/src/storage_cost/removal.rs @@ -43,10 +43,10 @@ use crate::storage_cost::removal::StorageRemovedBytes::{ pub type Identifier = [u8; 32]; /// Unknown Epoch -pub const UNKNOWN_EPOCH: u64 = u64::MAX; +pub const UNKNOWN_EPOCH: u16 = u16::MAX; /// A BTreeMap mapping identities to the storage they removed by epoch -pub type StorageRemovalPerEpochByIdentifier = BTreeMap>; +pub type StorageRemovalPerEpochByIdentifier = BTreeMap>; /// Removal bytes #[derive(Debug, PartialEq, Clone, Eq, Default)] @@ -122,7 +122,7 @@ impl Add for StorageRemovedBytes { }; (k, combined) }) - .collect::>(); + .collect::>(); intersection.into_iter().chain(int_map_b).collect() } else { int_map_b @@ -193,7 +193,7 @@ impl AddAssign for StorageRemovedBytes { }; (k, combined) }) - .collect::>(); + .collect::>(); intersection.into_iter().chain(int_map_b).collect() } else { int_map_b diff --git a/grovedb-epoch-based-storage-flags/Cargo.toml b/grovedb-epoch-based-storage-flags/Cargo.toml index b2832ed84..5e3cde71e 100644 --- a/grovedb-epoch-based-storage-flags/Cargo.toml +++ b/grovedb-epoch-based-storage-flags/Cargo.toml @@ -12,5 +12,5 @@ grovedb-costs = { version = "2.1.0", path = "../costs" } hex = { version = "0.4.3" } integer-encoding = { version = "4.0.0" } -intmap = { version = "2.0.0", features = ["serde"]} -thiserror = { version = "1.0.63" } +intmap = { version = "3.0.1", features = ["serde"]} +thiserror = { version = "2.0.11" } diff --git a/grovedb-epoch-based-storage-flags/src/lib.rs b/grovedb-epoch-based-storage-flags/src/lib.rs index add8765b7..17fa19197 100644 --- a/grovedb-epoch-based-storage-flags/src/lib.rs +++ b/grovedb-epoch-based-storage-flags/src/lib.rs @@ -255,13 +255,13 @@ impl StorageFlags { sectioned_bytes .iter() .try_for_each(|(epoch, removed_bytes)| { - if *epoch == base_epoch as u64 { + if epoch == base_epoch { return Ok::<(), StorageFlagsError>(()); } - let bytes_added_in_epoch = other_epoch_bytes.get_mut(&(*epoch as u16)).ok_or( + let bytes_added_in_epoch = other_epoch_bytes.get_mut(&epoch).ok_or( StorageFlagsError::RemovingAtEpochWithNoAssociatedStorage(format!( "can not remove bytes when there is no epoch number [{}]", - *epoch + epoch )), )?; @@ -273,7 +273,7 @@ impl StorageFlags { if desired_bytes_in_epoch <= MINIMUM_NON_BASE_FLAGS_SIZE { // Collect the key to remove later - keys_to_remove.push(*epoch as u16); + keys_to_remove.push(epoch); } else { *bytes_added_in_epoch = desired_bytes_in_epoch; } @@ -735,10 +735,10 @@ impl StorageFlags { return NoStorageRemoval; } let bytes_left = removed_bytes; - let mut sectioned_storage_removal: IntMap = IntMap::default(); + let mut sectioned_storage_removal: IntMap = IntMap::default(); if bytes_left > 0 { // We need to take some from the base epoch - sectioned_storage_removal.insert(*base_epoch as u64, removed_bytes); + sectioned_storage_removal.insert(*base_epoch, removed_bytes); } let mut sectioned_storage_removal_by_identifier: StorageRemovalPerEpochByIdentifier = BTreeMap::new(); @@ -763,19 +763,17 @@ impl StorageFlags { } let mut bytes_left = removed_bytes; let mut rev_iter = other_epoch_bytes.iter().rev(); - let mut sectioned_storage_removal: IntMap = IntMap::default(); + let mut sectioned_storage_removal: IntMap = IntMap::default(); while bytes_left > 0 { if let Some((epoch_index, bytes_in_epoch)) = rev_iter.next() { if *bytes_in_epoch <= bytes_left + MINIMUM_NON_BASE_FLAGS_SIZE { - sectioned_storage_removal.insert( - *epoch_index as u64, - *bytes_in_epoch - MINIMUM_NON_BASE_FLAGS_SIZE, - ); + sectioned_storage_removal + .insert(*epoch_index, *bytes_in_epoch - MINIMUM_NON_BASE_FLAGS_SIZE); bytes_left -= *bytes_in_epoch - MINIMUM_NON_BASE_FLAGS_SIZE; } else { // Correctly take only the required bytes_left from this epoch - sectioned_storage_removal.insert(*epoch_index as u64, bytes_left); + sectioned_storage_removal.insert(*epoch_index, bytes_left); bytes_left = 0; // All required bytes have been removed, stop processing break; // Exit the loop as there's no need to process // further epochs @@ -787,7 +785,7 @@ impl StorageFlags { if bytes_left > 0 { // If there are still bytes left, take them from the base epoch - sectioned_storage_removal.insert(*base_epoch as u64, bytes_left); + sectioned_storage_removal.insert(*base_epoch, bytes_left); } let mut sectioned_storage_removal_by_identifier: StorageRemovalPerEpochByIdentifier = @@ -1184,7 +1182,7 @@ mod storage_flags_tests { fn single_epoch_removed_bytes_map( owner_id: [u8; 32], - epoch_index: u64, + epoch_index: u16, bytes_removed: u32, ) -> StorageRemovalPerEpochByIdentifier { let mut removed_bytes = StorageRemovalPerEpochByIdentifier::default(); @@ -1196,7 +1194,7 @@ mod storage_flags_tests { fn multi_epoch_removed_bytes_map( owner_id: [u8; 32], - removed_bytes_per_epoch: IntMap, + removed_bytes_per_epoch: IntMap, ) -> StorageRemovalPerEpochByIdentifier { let mut removed_bytes = StorageRemovalPerEpochByIdentifier::default(); removed_bytes.insert(owner_id, removed_bytes_per_epoch); @@ -1241,9 +1239,9 @@ mod storage_flags_tests { let mut removed_bytes = IntMap::new(); for i in 1..200 { other_epochs.insert(i, MINIMUM_NON_BASE_FLAGS_SIZE + 1); - removed_bytes.insert(i as u64, 1); // anything between 1 and - // MINIMUM_NON_BASE_FLAGS_SIZE + - // 1 would be the same + removed_bytes.insert(i, 1); // anything between 1 and + // MINIMUM_NON_BASE_FLAGS_SIZE + + // 1 would be the same } let left_flag = StorageFlags::MultiEpochOwned(left_base_index, other_epochs, owner_id); @@ -1280,7 +1278,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(default_owner_id(), IntMap::from_iter([(5u64, 100)])); + map.insert(default_owner_id(), IntMap::from_iter([(5u16, 100)])); map }) ); @@ -1288,7 +1286,7 @@ mod storage_flags_tests { value_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(default_owner_id(), IntMap::from_iter([(5u64, 200)])); + map.insert(default_owner_id(), IntMap::from_iter([(5u16, 200)])); map }) ); @@ -1305,7 +1303,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(owner_id, IntMap::from_iter([(5u64, 50)])); + map.insert(owner_id, IntMap::from_iter([(5u16, 50)])); map }) ); @@ -1313,7 +1311,7 @@ mod storage_flags_tests { value_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(owner_id, IntMap::from_iter([(5u64, 150)])); + map.insert(owner_id, IntMap::from_iter([(5u16, 150)])); map }) ); @@ -1335,7 +1333,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( default_owner_id(), - IntMap::from_iter([(7u64, 197), (6u64, 53)]), + IntMap::from_iter([(7u16, 197), (6u16, 53)]), ); map }) @@ -1356,7 +1354,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(default_owner_id(), IntMap::from_iter([(5u64, 250)])); + map.insert(default_owner_id(), IntMap::from_iter([(5u16, 250)])); map }) ); @@ -1366,7 +1364,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( default_owner_id(), - IntMap::from_iter([(7u64, 47), (6u64, 97), (5u64, 106)]), + IntMap::from_iter([(7u16, 47), (6u16, 97), (5u16, 106)]), ); map }) @@ -1387,7 +1385,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(owner_id, IntMap::from_iter([(5u64, 250)])); + map.insert(owner_id, IntMap::from_iter([(5u16, 250)])); map }) ); @@ -1397,7 +1395,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( owner_id, - IntMap::from_iter([(7u64, 47), (6u64, 97), (5u64, 106)]), + IntMap::from_iter([(7u16, 47), (6u16, 97), (5u16, 106)]), ); map }) @@ -1426,7 +1424,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(owner_id, IntMap::from_iter([(5u64, 100)])); + map.insert(owner_id, IntMap::from_iter([(5u16, 100)])); map }) ); @@ -1434,7 +1432,7 @@ mod storage_flags_tests { value_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(owner_id, IntMap::from_iter([(5u64, 50)])); + map.insert(owner_id, IntMap::from_iter([(5u16, 50)])); map }) ); @@ -1455,7 +1453,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(default_owner_id(), IntMap::from_iter([(5u64, 400)])); + map.insert(default_owner_id(), IntMap::from_iter([(5u16, 400)])); map }) ); @@ -1465,7 +1463,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( default_owner_id(), - IntMap::from_iter([(7u64, 197), (6u64, 97), (5u64, 6)]), + IntMap::from_iter([(7u16, 197), (6u16, 97), (5u16, 6)]), ); map }) @@ -1486,7 +1484,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(owner_id, IntMap::from_iter([(5u64, 450)])); + map.insert(owner_id, IntMap::from_iter([(5u16, 450)])); map }) ); @@ -1496,7 +1494,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( owner_id, - IntMap::from_iter([(7u64, 197), (6u64, 97), (5u64, 56)]), + IntMap::from_iter([(7u16, 197), (6u16, 97), (5u16, 56)]), ); map }) @@ -1550,7 +1548,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( owner_id, - IntMap::from_iter([(5u64, 6), (6u64, 297), (7u64, 397)]), + IntMap::from_iter([(5u16, 6), (6u16, 297), (7u16, 397)]), ); map }) @@ -1569,7 +1567,7 @@ mod storage_flags_tests { key_removal, StorageRemovedBytes::SectionedStorageRemoval({ let mut map = BTreeMap::new(); - map.insert(default_owner_id(), IntMap::from_iter([(5u64, 400)])); + map.insert(default_owner_id(), IntMap::from_iter([(5u16, 400)])); map }) ); @@ -1579,7 +1577,7 @@ mod storage_flags_tests { let mut map = BTreeMap::new(); map.insert( default_owner_id(), - IntMap::from_iter([(7u64, 97), (6u64, 297), (5u64, 106)]), + IntMap::from_iter([(7u16, 97), (6u16, 297), (5u16, 106)]), ); map }) diff --git a/grovedb-version/Cargo.toml b/grovedb-version/Cargo.toml index 787164164..a46cb7587 100644 --- a/grovedb-version/Cargo.toml +++ b/grovedb-version/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" repository = "https://github.com/dashpay/grovedb" [dependencies] -thiserror = "1.0.59" +thiserror = "2.0.11" versioned-feature-core = "1.0.0" [features] diff --git a/grovedb/Cargo.toml b/grovedb/Cargo.toml index f84735c05..14df208b7 100644 --- a/grovedb/Cargo.toml +++ b/grovedb/Cargo.toml @@ -19,23 +19,20 @@ grovedb-storage = { version = "2.1.0", path = "../storage", optional = true } grovedb-version = { version = "2.1.0", path = "../grovedb-version" } grovedb-visualize = { version = "2.1.0", path = "../visualize", optional = true } -axum = { version = "0.7.5", features = ["macros"], optional = true } +axum = { version = "0.8.1", features = ["macros"], optional = true } bincode = { version = "2.0.0-rc.3" } -bitvec = "1" -blake3 = "1.4.0" -derive_more = "0.99.18" +blake3 = "1.5.5" hex = "0.4.3" -indexmap = "2.2.6" +indexmap = "2.7.0" integer-encoding = { version = "4.0.0", optional = true } -intmap = { version = "2.0.0", optional = true } -itertools = { version = "0.12.1", optional = true } -nohash-hasher = { version = "0.2.0", optional = true } +intmap = { version = "3.0.1", optional = true } +itertools = { version = "0.14.0", optional = true } tempfile = { version = "3.10.1", optional = true } -thiserror = { version = "1.0.59", optional = true } +thiserror = { version = "2.0.11", optional = true } tokio-util = { version = "0.7.12", optional = true } tokio = { version = "1.40.0", features = ["rt-multi-thread", "net"], optional = true } tower-http = { version = "0.5.2", features = ["fs"], optional = true } -zip-extensions = { version ="0.6.2", optional = true } +zip-extensions = { version = "0.8.1", optional = true } serde = { version = "1.0.210", features = ["derive"], optional = true } [dev-dependencies] @@ -56,6 +53,10 @@ proof_debug = ["grovedb-merk/proof_debug"] serde = ["dep:serde", "grovedb-merk/serde", "indexmap/serde"] full = [ "grovedb-merk/full", + "minimal", +] +minimal = [ + "grovedb-merk/minimal", "thiserror", "tempfile", "grovedb-storage/rocksdb_storage", @@ -63,7 +64,6 @@ full = [ "itertools", "integer-encoding", "grovedb-costs", - "nohash-hasher", "intmap", ] visualize = [ diff --git a/grovedb/benches/insertion_benchmark.rs b/grovedb/benches/insertion_benchmark.rs index 051a32d11..6e7370150 100644 --- a/grovedb/benches/insertion_benchmark.rs +++ b/grovedb/benches/insertion_benchmark.rs @@ -28,24 +28,24 @@ //! Insertion Benchmark -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use criterion::{criterion_group, criterion_main, Criterion}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb::{Element, GroveDb}; use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use rand::Rng; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use tempfile::TempDir; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] const N_ITEMS: usize = 10_000; const EMPTY_PATH: SubtreePath<'static, [u8; 0]> = SubtreePath::empty(); /// Benchmark function to insert '''N_ITEMS''' key-values into an empty tree /// without a transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn insertion_benchmark_without_transaction(c: &mut Criterion) { let dir = TempDir::new().unwrap(); let db = GroveDb::open(dir.path()).unwrap(); @@ -82,7 +82,7 @@ pub fn insertion_benchmark_without_transaction(c: &mut Criterion) { /// Benchmark function to insert '''N_ITEMS''' key-values into an empty tree /// with a transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn insertion_benchmark_with_transaction(c: &mut Criterion) { let dir = TempDir::new().unwrap(); let db = GroveDb::open(dir.path()).unwrap(); @@ -120,7 +120,7 @@ pub fn insertion_benchmark_with_transaction(c: &mut Criterion) { } /// Benchmark function to insert 10 root leaves without a transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn root_leaf_insertion_benchmark_without_transaction(c: &mut Criterion) { let dir = TempDir::new().unwrap(); let db = GroveDb::open(dir.path()).unwrap(); @@ -145,7 +145,7 @@ pub fn root_leaf_insertion_benchmark_without_transaction(c: &mut Criterion) { } /// Benchmark function to insert 10 root leaves with a transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn root_leaf_insertion_benchmark_with_transaction(c: &mut Criterion) { let dir = TempDir::new().unwrap(); let db = GroveDb::open(dir.path()).unwrap(); @@ -173,7 +173,7 @@ pub fn root_leaf_insertion_benchmark_with_transaction(c: &mut Criterion) { /// Benchmark function to insert a subtree nested within 10 higher subtrees /// and insert key-values into it without a transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn deeply_nested_insertion_benchmark_without_transaction(c: &mut Criterion) { let dir = TempDir::new().unwrap(); let db = GroveDb::open(dir.path()).unwrap(); @@ -214,7 +214,7 @@ pub fn deeply_nested_insertion_benchmark_without_transaction(c: &mut Criterion) /// Benchmark function to insert a subtree nested within 10 higher subtrees /// and insert key-values into it with a transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn deeply_nested_insertion_benchmark_with_transaction(c: &mut Criterion) { let dir = TempDir::new().unwrap(); let db = GroveDb::open(dir.path()).unwrap(); @@ -255,7 +255,7 @@ pub fn deeply_nested_insertion_benchmark_with_transaction(c: &mut Criterion) { }); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] criterion_group!( benches, insertion_benchmark_without_transaction, @@ -265,5 +265,5 @@ criterion_group!( deeply_nested_insertion_benchmark_without_transaction, deeply_nested_insertion_benchmark_with_transaction, ); -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] criterion_main!(benches); diff --git a/grovedb/src/batch/batch_structure.rs b/grovedb/src/batch/batch_structure.rs index 9cfe03dba..036943793 100644 --- a/grovedb/src/batch/batch_structure.rs +++ b/grovedb/src/batch/batch_structure.rs @@ -1,33 +1,33 @@ //! Batch structure -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{collections::BTreeMap, fmt}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, storage_cost::{removal::StorageRemovedBytes, StorageCost}, CostResult, CostsExt, OperationCost, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_visualize::{DebugByteVectors, DebugBytes}; -#[cfg(feature = "full")] -use nohash_hasher::IntMap; +#[cfg(feature = "minimal")] +use intmap::IntMap; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ batch::{key_info::KeyInfo, GroveOp, KeyInfoPath, QualifiedGroveDbOp, TreeCache}, Element, ElementFlags, Error, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub type OpsByPath = BTreeMap>; /// Level, path, key, op -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub type OpsByLevelPath = IntMap; /// Batch structure -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub(super) struct BatchStructure { /// Operations by level path pub(super) ops_by_level_paths: OpsByLevelPath, @@ -45,7 +45,7 @@ pub(super) struct BatchStructure { pub(super) last_level: u32, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl fmt::Debug for BatchStructure { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut fmt_int_map = IntMap::default(); @@ -60,7 +60,7 @@ impl fmt::Debug for BatchStructure { } fmt_path_map.insert(DebugByteVectors(path.to_path()), fmt_key_map); } - fmt_int_map.insert(*level, fmt_path_map); + fmt_int_map.insert(level, fmt_path_map); } f.debug_struct("BatchStructure") @@ -71,7 +71,7 @@ impl fmt::Debug for BatchStructure { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl BatchStructure where C: TreeCache, @@ -146,7 +146,7 @@ where } let level = op.path.len(); - if let Some(ops_on_level) = ops_by_level_paths.get_mut(&level) { + if let Some(ops_on_level) = ops_by_level_paths.get_mut(level) { if let Some(ops_on_path) = ops_on_level.get_mut(&op.path) { ops_on_path.insert(op.key, op.op); } else { diff --git a/grovedb/src/batch/estimated_costs/average_case_costs.rs b/grovedb/src/batch/estimated_costs/average_case_costs.rs index ef64b0f4d..8d4c076a7 100644 --- a/grovedb/src/batch/estimated_costs/average_case_costs.rs +++ b/grovedb/src/batch/estimated_costs/average_case_costs.rs @@ -1,29 +1,29 @@ //! Average case costs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{ collections::{BTreeMap, HashMap}, fmt, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; use grovedb_merk::RootHashKeyAndSum; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{ estimated_costs::average_case_costs::{average_case_merk_propagate, EstimatedLayerInformation}, IsSumTree, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::RocksDbStorage; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use itertools::Itertools; use crate::Element; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ batch::{ key_info::KeyInfo, mode::BatchRunMode, BatchApplyOptions, GroveOp, KeyInfoPath, @@ -32,7 +32,7 @@ use crate::{ Error, GroveDb, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveOp { /// Get the estimated average case cost of the op. Calls a lower level /// function to calculate the estimate based on the type of op. Returns @@ -137,7 +137,7 @@ impl GroveOp { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Cache for subtree paths for average case scenario costs. #[derive(Default)] pub(in crate::batch) struct AverageCaseTreeCacheKnownPaths { @@ -145,7 +145,7 @@ pub(in crate::batch) struct AverageCaseTreeCacheKnownPaths { cached_merks: HashMap, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl AverageCaseTreeCacheKnownPaths { /// Updates the cache to the default setting with the given subtree paths pub(in crate::batch) fn new_with_estimated_layer_information( @@ -158,14 +158,14 @@ impl AverageCaseTreeCacheKnownPaths { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl fmt::Debug for AverageCaseTreeCacheKnownPaths { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TreeCacheKnownPaths").finish() } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeCache for AverageCaseTreeCacheKnownPaths { fn insert(&mut self, op: &QualifiedGroveDbOp, is_sum_tree: bool) -> CostResult<(), Error> { let mut average_case_cost = OperationCost::default(); @@ -291,7 +291,7 @@ impl TreeCache for AverageCaseTreeCacheKnownPaths { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use std::collections::HashMap; diff --git a/grovedb/src/batch/estimated_costs/mod.rs b/grovedb/src/batch/estimated_costs/mod.rs index 54fc109c1..37b909da3 100644 --- a/grovedb/src/batch/estimated_costs/mod.rs +++ b/grovedb/src/batch/estimated_costs/mod.rs @@ -1,23 +1,23 @@ //! Estimated costs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::collections::HashMap; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::estimated_costs::{ average_case_costs::EstimatedLayerInformation, worst_case_costs::WorstCaseLayerInformation, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::batch::KeyInfoPath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod average_case_costs; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod worst_case_costs; /// Estimated costs types -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub enum EstimatedCostsType { /// Average cast estimated costs type AverageCaseCostsType(HashMap), diff --git a/grovedb/src/batch/estimated_costs/worst_case_costs.rs b/grovedb/src/batch/estimated_costs/worst_case_costs.rs index 9bf9a808b..5e4f6e425 100644 --- a/grovedb/src/batch/estimated_costs/worst_case_costs.rs +++ b/grovedb/src/batch/estimated_costs/worst_case_costs.rs @@ -1,28 +1,28 @@ //! Worst case costs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{ collections::{BTreeMap, HashMap, HashSet}, fmt, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::estimated_costs::worst_case_costs::{ worst_case_merk_propagate, WorstCaseLayerInformation, }; use grovedb_merk::RootHashKeyAndSum; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::RocksDbStorage; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use itertools::Itertools; use crate::Element; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ batch::{ key_info::KeyInfo, mode::BatchRunMode, BatchApplyOptions, GroveOp, KeyInfoPath, @@ -31,7 +31,7 @@ use crate::{ Error, GroveDb, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveOp { fn worst_case_cost( &self, @@ -133,7 +133,7 @@ impl GroveOp { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Cache for subtree paths for worst case scenario costs. #[derive(Default)] pub(in crate::batch) struct WorstCaseTreeCacheKnownPaths { @@ -141,7 +141,7 @@ pub(in crate::batch) struct WorstCaseTreeCacheKnownPaths { cached_merks: HashSet, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl WorstCaseTreeCacheKnownPaths { /// Updates the cache with the default settings and the given paths pub(in crate::batch) fn new_with_worst_case_layer_information( @@ -154,14 +154,14 @@ impl WorstCaseTreeCacheKnownPaths { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl fmt::Debug for WorstCaseTreeCacheKnownPaths { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TreeCacheKnownPaths").finish() } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeCache for WorstCaseTreeCacheKnownPaths { fn insert(&mut self, op: &QualifiedGroveDbOp, _is_sum_tree: bool) -> CostResult<(), Error> { let mut worst_case_cost = OperationCost::default(); @@ -262,7 +262,7 @@ impl TreeCache for WorstCaseTreeCacheKnownPaths { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use std::collections::HashMap; diff --git a/grovedb/src/batch/just_in_time_cost_tests.rs b/grovedb/src/batch/just_in_time_cost_tests.rs index 9c45680be..3f083763b 100644 --- a/grovedb/src/batch/just_in_time_cost_tests.rs +++ b/grovedb/src/batch/just_in_time_cost_tests.rs @@ -1,7 +1,7 @@ //! This tests just in time costs //! Just in time costs modify the tree in the same batch -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod tests { use std::{collections::BTreeMap, option::Option::None}; @@ -24,7 +24,7 @@ mod tests { fn single_epoch_removed_bytes_map( owner_id: [u8; 32], - epoch_index: u64, + epoch_index: u16, bytes_removed: u32, ) -> StorageRemovalPerEpochByIdentifier { let mut removed_bytes = StorageRemovalPerEpochByIdentifier::default(); @@ -346,7 +346,7 @@ mod tests { let ops_by_root_path = left_over_ops .as_ref() .unwrap() - .get(&0) + .get(0) .expect("expected to have root path"); assert_eq!(ops_by_root_path.len(), 1); let new_ops = vec![QualifiedGroveDbOp::insert_or_replace_op( diff --git a/grovedb/src/batch/key_info.rs b/grovedb/src/batch/key_info.rs index e7dd25b5b..9c61766fe 100644 --- a/grovedb/src/batch/key_info.rs +++ b/grovedb/src/batch/key_info.rs @@ -1,21 +1,21 @@ //! Key info -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{ cmp::Ordering, hash::{Hash, Hasher}, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::worst_case_costs::WorstKeyLength; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_visualize::{Drawer, Visualize}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::batch::key_info::KeyInfo::{KnownKey, MaxKeySize}; /// Key info -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, Eq, Debug)] pub enum KeyInfo { /// Known key @@ -29,7 +29,7 @@ pub enum KeyInfo { }, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl PartialEq for KeyInfo { fn eq(&self, other: &Self) -> bool { match (self, other) { @@ -69,14 +69,14 @@ impl PartialEq<&[u8]> for KeyInfo { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl PartialOrd for KeyInfo { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Ord for KeyInfo { fn cmp(&self, other: &Self) -> Ordering { match self.as_slice().cmp(other.as_slice()) { @@ -90,7 +90,7 @@ impl Ord for KeyInfo { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Hash for KeyInfo { fn hash(&self, state: &mut H) { match self { @@ -106,7 +106,7 @@ impl Hash for KeyInfo { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl WorstKeyLength for KeyInfo { fn max_length(&self) -> u8 { match self { @@ -116,7 +116,7 @@ impl WorstKeyLength for KeyInfo { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl KeyInfo { /// Return self as slice pub fn as_slice(&self) -> &[u8] { @@ -143,7 +143,7 @@ impl KeyInfo { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Visualize for KeyInfo { fn visualize(&self, mut drawer: Drawer) -> std::io::Result> { match self { diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 2767ab2b1..7f73fea07 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -1741,7 +1741,7 @@ impl GroveDb { let stop_level = batch_apply_options.batch_pause_height.unwrap_or_default() as u32; // We will update up the tree - while let Some(ops_at_level) = ops_by_level_paths.remove(¤t_level) { + while let Some(ops_at_level) = ops_by_level_paths.remove(current_level) { for (path, ops_at_path) in ops_at_level.into_iter() { if current_level == 0 { // execute the ops at this path @@ -1794,7 +1794,7 @@ impl GroveDb { // operations up for the level above if let Some((key, parent_path)) = path.split_last() { if let Some(ops_at_level_above) = - ops_by_level_paths.get_mut(&(current_level - 1)) + ops_by_level_paths.get_mut(current_level - 1) { // todo: fix this hack let parent_path = KeyInfoPath(parent_path.to_vec()); diff --git a/grovedb/src/batch/mode.rs b/grovedb/src/batch/mode.rs index 897d15f2c..2cc2e3074 100644 --- a/grovedb/src/batch/mode.rs +++ b/grovedb/src/batch/mode.rs @@ -11,7 +11,7 @@ use grovedb_merk::estimated_costs::{ #[cfg(feature = "estimated_costs")] use crate::batch::KeyInfoPath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Batch Running Mode #[derive(Clone, PartialEq, Eq)] pub enum BatchRunMode { diff --git a/grovedb/src/batch/multi_insert_cost_tests.rs b/grovedb/src/batch/multi_insert_cost_tests.rs index 666de224f..370aac91c 100644 --- a/grovedb/src/batch/multi_insert_cost_tests.rs +++ b/grovedb/src/batch/multi_insert_cost_tests.rs @@ -1,6 +1,6 @@ //! Multi insert cost tests -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod tests { use std::{ops::Add, option::Option::None}; diff --git a/grovedb/src/batch/options.rs b/grovedb/src/batch/options.rs index 1f60aeb4c..b21a20679 100644 --- a/grovedb/src/batch/options.rs +++ b/grovedb/src/batch/options.rs @@ -1,13 +1,13 @@ //! Options -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::MerkOptions; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::operations::{delete::DeleteOptions, insert::InsertOptions}; /// Batch apply options -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Debug, Clone)] pub struct BatchApplyOptions { /// Validate insertion does not override @@ -27,7 +27,7 @@ pub struct BatchApplyOptions { pub batch_pause_height: Option, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for BatchApplyOptions { fn default() -> Self { BatchApplyOptions { @@ -42,7 +42,7 @@ impl Default for BatchApplyOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl BatchApplyOptions { /// As insert options pub(crate) fn as_insert_options(&self) -> InsertOptions { diff --git a/grovedb/src/batch/single_deletion_cost_tests.rs b/grovedb/src/batch/single_deletion_cost_tests.rs index e2b3d9a9c..c84a2e472 100644 --- a/grovedb/src/batch/single_deletion_cost_tests.rs +++ b/grovedb/src/batch/single_deletion_cost_tests.rs @@ -1,6 +1,6 @@ //! Tests -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod tests { use grovedb_costs::storage_cost::removal::{ diff --git a/grovedb/src/batch/single_insert_cost_tests.rs b/grovedb/src/batch/single_insert_cost_tests.rs index d86a2bf29..b3750ecae 100644 --- a/grovedb/src/batch/single_insert_cost_tests.rs +++ b/grovedb/src/batch/single_insert_cost_tests.rs @@ -1,6 +1,6 @@ //! Tests -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod tests { use grovedb_costs::{ storage_cost::{ diff --git a/grovedb/src/batch/single_sum_item_deletion_cost_tests.rs b/grovedb/src/batch/single_sum_item_deletion_cost_tests.rs index c0be9a082..7db03b7fa 100644 --- a/grovedb/src/batch/single_sum_item_deletion_cost_tests.rs +++ b/grovedb/src/batch/single_sum_item_deletion_cost_tests.rs @@ -1,6 +1,6 @@ //! Tests -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod tests { use grovedb_version::version::GroveVersion; diff --git a/grovedb/src/batch/single_sum_item_insert_cost_tests.rs b/grovedb/src/batch/single_sum_item_insert_cost_tests.rs index d58e7327b..ae16eaa2b 100644 --- a/grovedb/src/batch/single_sum_item_insert_cost_tests.rs +++ b/grovedb/src/batch/single_sum_item_insert_cost_tests.rs @@ -1,6 +1,6 @@ //! Tests -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod tests { use grovedb_costs::{ storage_cost::{removal::StorageRemovedBytes::NoStorageRemoval, StorageCost}, diff --git a/grovedb/src/element/constructor.rs b/grovedb/src/element/constructor.rs index 91143ec87..1d5049cd2 100644 --- a/grovedb/src/element/constructor.rs +++ b/grovedb/src/element/constructor.rs @@ -1,7 +1,7 @@ //! Constructor //! Functions for setting an element's type -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ element::{MaxReferenceHop, SumValue}, reference_path::ReferencePathType, @@ -9,62 +9,62 @@ use crate::{ }; impl Element { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to default empty tree without flags // TODO: improve API to avoid creation of Tree elements with uncertain state pub fn empty_tree() -> Self { Element::new_tree(Default::default()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to default empty tree with flags pub fn empty_tree_with_flags(flags: Option) -> Self { Element::new_tree_with_flags(Default::default(), flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to default empty sum tree without flags pub fn empty_sum_tree() -> Self { Element::new_sum_tree(Default::default()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to default empty sum tree with flags pub fn empty_sum_tree_with_flags(flags: Option) -> Self { Element::new_sum_tree_with_flags(Default::default(), flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to an item without flags pub fn new_item(item_value: Vec) -> Self { Element::Item(item_value, None) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to an item with flags pub fn new_item_with_flags(item_value: Vec, flags: Option) -> Self { Element::Item(item_value, flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a sum item without flags pub fn new_sum_item(value: i64) -> Self { Element::SumItem(value, None) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a sum item with flags pub fn new_sum_item_with_flags(value: i64, flags: Option) -> Self { Element::SumItem(value, flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a reference without flags pub fn new_reference(reference_path: ReferencePathType) -> Self { Element::Reference(reference_path, None, None) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a reference with flags pub fn new_reference_with_flags( reference_path: ReferencePathType, @@ -73,7 +73,7 @@ impl Element { Element::Reference(reference_path, None, flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a reference with hops, no flags pub fn new_reference_with_hops( reference_path: ReferencePathType, @@ -82,7 +82,7 @@ impl Element { Element::Reference(reference_path, max_reference_hop, None) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a reference with max hops and flags pub fn new_reference_with_max_hops_and_flags( reference_path: ReferencePathType, @@ -92,13 +92,13 @@ impl Element { Element::Reference(reference_path, max_reference_hop, flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a tree without flags pub fn new_tree(maybe_root_key: Option>) -> Self { Element::Tree(maybe_root_key, None) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a tree with flags pub fn new_tree_with_flags( maybe_root_key: Option>, @@ -107,13 +107,13 @@ impl Element { Element::Tree(maybe_root_key, flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a sum tree without flags pub fn new_sum_tree(maybe_root_key: Option>) -> Self { Element::SumTree(maybe_root_key, 0, None) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a sum tree with flags pub fn new_sum_tree_with_flags( maybe_root_key: Option>, @@ -122,7 +122,7 @@ impl Element { Element::SumTree(maybe_root_key, 0, flags) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Set element to a sum tree with flags and sum value pub fn new_sum_tree_with_flags_and_sum_value( maybe_root_key: Option>, diff --git a/grovedb/src/element/delete.rs b/grovedb/src/element/delete.rs index ced24e273..8c9b3511c 100644 --- a/grovedb/src/element/delete.rs +++ b/grovedb/src/element/delete.rs @@ -1,26 +1,26 @@ //! Delete //! Implements functions in Element for deleting -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::OperationCost; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{storage_cost::removal::StorageRemovedBytes, CostResult, CostsExt}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{BatchEntry, Error as MerkError, Merk, MerkOptions, Op}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::StorageContext; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::check_grovedb_v0_with_cost; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::error::GroveVersionError; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{Element, Error}; impl Element { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Delete an element from Merk under a key pub fn delete<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( merk: &mut Merk, @@ -53,7 +53,7 @@ impl Element { .map_err(|e| Error::CorruptedData(e.to_string())) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Delete an element from Merk under a key pub fn delete_with_sectioned_removal_bytes<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( merk: &mut Merk, @@ -103,7 +103,7 @@ impl Element { .map_err(|e| Error::CorruptedData(e.to_string())) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Delete an element from Merk under a key to batch operations pub fn delete_into_batch_operations>( key: K, diff --git a/grovedb/src/element/get.rs b/grovedb/src/element/get.rs index ded859d36..3c66b049d 100644 --- a/grovedb/src/element/get.rs +++ b/grovedb/src/element/get.rs @@ -1,16 +1,16 @@ //! Get //! Implements functions in Element for getting -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; use grovedb_merk::tree::kv::KV; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::Merk; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{ed::Decode, tree::TreeNodeInner}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::StorageContext; use grovedb_version::{ check_grovedb_v0_with_cost, error::GroveVersionError, version::GroveVersion, @@ -18,11 +18,11 @@ use grovedb_version::{ use integer_encoding::VarInt; use crate::element::{SUM_ITEM_COST_SIZE, SUM_TREE_COST_SIZE, TREE_COST_SIZE}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{Element, Error, Hash}; impl Element { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get an element from Merk under a key; path should be resolved and proper /// Merk should be loaded by this moment pub fn get<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( @@ -47,7 +47,7 @@ impl Element { }) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get an element from Merk under a key; path should be resolved and proper /// Merk should be loaded by this moment pub fn get_optional<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( @@ -86,7 +86,7 @@ impl Element { Ok(element).wrap_with_cost(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get an element directly from storage under a key /// Merk does not need to be loaded /// Errors if element doesn't exist @@ -110,7 +110,7 @@ impl Element { }) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get an element directly from storage under a key /// Merk does not need to be loaded pub fn get_optional_from_storage<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( @@ -198,7 +198,7 @@ impl Element { Ok(element).wrap_with_cost(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get an element from Merk under a key; path should be resolved and proper /// Merk should be loaded by this moment pub fn get_with_absolute_refs<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( @@ -230,7 +230,7 @@ impl Element { Ok(absolute_element).wrap_with_cost(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get an element's value hash from Merk under a key pub fn get_value_hash<'db, K: AsRef<[u8]>, S: StorageContext<'db>>( merk: &Merk, @@ -259,7 +259,7 @@ impl Element { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use grovedb_path::SubtreePath; diff --git a/grovedb/src/element/helpers.rs b/grovedb/src/element/helpers.rs index 5b3662dff..af74c6f8e 100644 --- a/grovedb/src/element/helpers.rs +++ b/grovedb/src/element/helpers.rs @@ -1,36 +1,36 @@ //! Helpers //! Implements helper functions in Element -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::tree::kv::{ ValueDefinedCostType, ValueDefinedCostType::{LayeredValueDefinedCost, SpecializedValueDefinedCost}, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{ tree::{kv::KV, TreeNode}, TreeFeatureType, TreeFeatureType::{BasicMerkNode, SummedMerkNode}, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::{check_grovedb_v0, error::GroveVersionError, version::GroveVersion}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::reference_path::path_from_reference_path_type; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::reference_path::ReferencePathType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ element::{SUM_ITEM_COST_SIZE, SUM_TREE_COST_SIZE, TREE_COST_SIZE}, ElementFlags, }; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::{Element, Error}; impl Element { - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Decoded the integer value in the SumItem element type, returns 0 for /// everything else pub fn sum_value_or_default(&self) -> i64 { @@ -40,7 +40,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Decoded the integer value in the SumItem element type pub fn as_sum_item_value(&self) -> Result { match self { @@ -49,7 +49,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Decoded the integer value in the SumItem element type pub fn into_sum_item_value(self) -> Result { match self { @@ -58,7 +58,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Decoded the integer value in the SumTree element type pub fn as_sum_tree_value(&self) -> Result { match self { @@ -67,7 +67,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Decoded the integer value in the SumTree element type pub fn into_sum_tree_value(self) -> Result { match self { @@ -76,7 +76,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Gives the item value in the Item element type pub fn as_item_bytes(&self) -> Result<&[u8], Error> { match self { @@ -85,7 +85,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Gives the item value in the Item element type pub fn into_item_bytes(self) -> Result, Error> { match self { @@ -94,7 +94,7 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Gives the reference path type in the Reference element type pub fn into_reference_path_type(self) -> Result { match self { @@ -103,49 +103,49 @@ impl Element { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is a sum tree pub fn is_sum_tree(&self) -> bool { matches!(self, Element::SumTree(..)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is a tree but not a sum tree pub fn is_basic_tree(&self) -> bool { matches!(self, Element::Tree(..)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is a tree pub fn is_any_tree(&self) -> bool { matches!(self, Element::SumTree(..) | Element::Tree(..)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is a reference pub fn is_reference(&self) -> bool { matches!(self, Element::Reference(..)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is an item pub fn is_any_item(&self) -> bool { matches!(self, Element::Item(..) | Element::SumItem(..)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is an item pub fn is_basic_item(&self) -> bool { matches!(self, Element::Item(..)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Check if the element is a sum item pub fn is_sum_item(&self) -> bool { matches!(self, Element::SumItem(..)) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get the tree feature type pub fn get_feature_type(&self, parent_is_sum_tree: bool) -> Result { match parent_is_sum_tree { @@ -154,7 +154,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Grab the optional flag stored in an element pub fn get_flags(&self) -> &Option { match self { @@ -166,7 +166,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Grab the optional flag stored in an element pub fn get_flags_owned(self) -> Option { match self { @@ -178,7 +178,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Grab the optional flag stored in an element as mutable pub fn get_flags_mut(&mut self) -> &mut Option { match self { @@ -190,7 +190,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Sets the optional flag stored in an element pub fn set_flags(&mut self, new_flags: Option) { match self { @@ -202,7 +202,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get the required item space pub fn required_item_space( len: u32, @@ -216,7 +216,7 @@ impl Element { Ok(len + len.required_space() as u32 + flag_len + flag_len.required_space() as u32 + 1) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Convert the reference to an absolute reference pub(crate) fn convert_if_reference_to_absolute_reference( self, @@ -247,7 +247,7 @@ impl Element { }) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get tree costs for a key value pub fn specialized_costs_for_key_value( key: &Vec, @@ -305,7 +305,7 @@ impl Element { Ok(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get tree cost for the element pub fn get_specialized_cost(&self, grove_version: &GroveVersion) -> Result { check_grovedb_v0!( @@ -322,7 +322,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get the value defined cost for a serialized value pub fn value_defined_cost(&self, grove_version: &GroveVersion) -> Option { let Some(value_cost) = self.get_specialized_cost(grove_version).ok() else { @@ -342,7 +342,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get the value defined cost for a serialized value pub fn value_defined_cost_for_serialized_value( value: &[u8], @@ -353,7 +353,7 @@ impl Element { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Decode from bytes pub fn raw_decode(bytes: &[u8], grove_version: &GroveVersion) -> Result { let tree = TreeNode::decode_raw( diff --git a/grovedb/src/element/insert.rs b/grovedb/src/element/insert.rs index ce0144a2b..5b47acc45 100644 --- a/grovedb/src/element/insert.rs +++ b/grovedb/src/element/insert.rs @@ -15,7 +15,7 @@ use integer_encoding::VarInt; use crate::{Element, Element::SumItem, Error, Hash}; impl Element { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Insert an element in Merk under a key; path should be resolved and /// proper Merk should be loaded by this moment /// If transaction is not passed, the batch will be written immediately. @@ -71,7 +71,7 @@ impl Element { .map_err(|e| Error::CorruptedData(e.to_string())) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Add to batch operations a "Put" op with key and serialized element. /// Return CostResult. pub fn insert_into_batch_operations>( @@ -114,7 +114,7 @@ impl Element { Ok(()).wrap_with_cost(Default::default()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Insert an element in Merk under a key if it doesn't yet exist; path /// should be resolved and proper Merk should be loaded by this moment /// If transaction is not passed, the batch will be written immediately. @@ -145,7 +145,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Adds a "Put" op to batch operations with the element and key if it /// doesn't exist yet. Returns CostResult. pub fn insert_if_not_exists_into_batch_operations< @@ -189,7 +189,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Insert an element in Merk under a key if the value is different from /// what already exists; path should be resolved and proper Merk should /// be loaded by this moment If transaction is not passed, the batch @@ -229,7 +229,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Adds a "Put" op to batch operations with the element and key if the /// value is different from what already exists; Returns CostResult. /// The bool represents if we indeed inserted. @@ -279,7 +279,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Insert a reference element in Merk under a key; path should be resolved /// and proper Merk should be loaded by this moment /// If transaction is not passed, the batch will be written immediately. @@ -329,7 +329,7 @@ impl Element { .map_err(|e| Error::CorruptedData(e.to_string())) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Adds a "Put" op to batch operations with reference and key. Returns /// CostResult. pub fn insert_reference_into_batch_operations>( @@ -361,7 +361,7 @@ impl Element { Ok(()).wrap_with_cost(Default::default()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Insert a tree element in Merk under a key; path should be resolved /// and proper Merk should be loaded by this moment /// If transaction is not passed, the batch will be written immediately. @@ -416,7 +416,7 @@ impl Element { .map_err(|e| Error::CorruptedData(e.to_string())) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Adds a "Put" op to batch operations for a subtree and key pub fn insert_subtree_into_batch_operations>( &self, @@ -465,7 +465,7 @@ impl Element { } } -#[cfg(feature = "full")] +#[cfg(all(feature = "minimal", feature = "test_utils"))] #[cfg(test)] mod tests { use grovedb_merk::test_utils::{empty_path_merk, empty_path_merk_read_only, TempMerk}; diff --git a/grovedb/src/element/mod.rs b/grovedb/src/element/mod.rs index 9986c6244..c8ecbbc84 100644 --- a/grovedb/src/element/mod.rs +++ b/grovedb/src/element/mod.rs @@ -2,75 +2,75 @@ //! Subtrees handling is isolated so basically this module is about adapting //! Merk API to GroveDB needs. -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod constructor; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod delete; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod exists; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod get; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub(crate) mod helpers; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod insert; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod query; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use query::QueryOptions; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod serialize; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use std::fmt; use bincode::{Decode, Encode}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use grovedb_merk::estimated_costs::SUM_VALUE_EXTRA_COST; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::estimated_costs::{LAYER_COST_SIZE, SUM_LAYER_COST_SIZE}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_visualize::visualize_to_vec; use crate::operations::proof::util::hex_to_ascii; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::reference_path::ReferencePathType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::OperationCost; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Optional meta-data to be stored per element pub type ElementFlags = Vec; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Optional single byte to represent the maximum number of reference hop to /// base element pub type MaxReferenceHop = Option; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// The cost of a tree pub const TREE_COST_SIZE: u32 = LAYER_COST_SIZE; // 3 -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// The cost of a sum item /// /// It is 11 because we have 9 bytes for the sum value /// 1 byte for the item type /// 1 byte for the flags option pub const SUM_ITEM_COST_SIZE: u32 = SUM_VALUE_EXTRA_COST + 2; // 11 -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// The cost of a sum tree pub const SUM_TREE_COST_SIZE: u32 = SUM_LAYER_COST_SIZE; // 12 -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// int 64 sum value pub type SumValue = i64; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Variants of GroveDB stored entities /// /// ONLY APPEND TO THIS LIST!!! Because /// of how serialization works. #[derive(Clone, Encode, Decode, PartialEq, Eq, Hash)] -#[cfg_attr(not(any(feature = "full", feature = "visualize")), derive(Debug))] +#[cfg_attr(not(any(feature = "minimal", feature = "visualize")), derive(Debug))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Element { /// An ordinary value @@ -157,7 +157,7 @@ impl Element { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub(crate) fn value_hash( &self, grove_version: &grovedb_version::version::GroveVersion, @@ -167,7 +167,7 @@ impl Element { } } -#[cfg(any(feature = "full", feature = "visualize"))] +#[cfg(any(feature = "minimal", feature = "visualize"))] impl fmt::Debug for Element { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut v = Vec::new(); diff --git a/grovedb/src/element/query.rs b/grovedb/src/element/query.rs index 7226db553..f1975aadc 100644 --- a/grovedb/src/element/query.rs +++ b/grovedb/src/element/query.rs @@ -3,31 +3,31 @@ use std::fmt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostContext, CostResult, CostsExt, OperationCost, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::proofs::query::query_item::QueryItem; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::proofs::query::SubqueryBranch; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::proofs::Query; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::{rocksdb_storage::RocksDbStorage, RawIterator, StorageContext}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::{ check_grovedb_v0, check_grovedb_v0_with_cost, error::GroveVersionError, version::GroveVersion, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::operations::proof::util::hex_to_ascii; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::Element; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ element::helpers::raw_decode, query_result_type::{ @@ -40,10 +40,10 @@ use crate::{ util::{merk_optional_tx, merk_optional_tx_internal_error, storage_context_optional_tx}, Error, PathQuery, TransactionArg, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{query_result_type::Path, SizedQuery}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Copy, Clone, Debug)] pub struct QueryOptions { pub allow_get_raw: bool, @@ -58,7 +58,7 @@ pub struct QueryOptions { pub error_if_intermediate_path_tree_not_present: bool, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for QueryOptions { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "QueryOptions {{")?; @@ -78,7 +78,7 @@ impl fmt::Display for QueryOptions { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Default for QueryOptions { fn default() -> Self { QueryOptions { @@ -90,7 +90,7 @@ impl Default for QueryOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Path query push arguments pub struct PathQueryPushArgs<'db, 'ctx, 'a> where @@ -111,7 +111,7 @@ where pub offset: &'a mut Option, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] fn format_query(query: &Query, indent: usize) -> String { let indent_str = " ".repeat(indent); let mut output = format!("{}Query {{\n", indent_str); @@ -147,7 +147,7 @@ fn format_query(query: &Query, indent: usize) -> String { output } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] fn format_subquery_branch(branch: &SubqueryBranch, indent: usize) -> String { let indent_str = " ".repeat(indent); let mut output = "SubqueryBranch {{\n".to_string(); @@ -169,7 +169,7 @@ fn format_subquery_branch(branch: &SubqueryBranch, indent: usize) -> String { output } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'db, 'ctx, 'a> fmt::Display for PathQueryPushArgs<'db, 'ctx, 'a> where 'db: 'ctx, @@ -230,7 +230,7 @@ where } impl Element { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Returns a vector of result elements based on given query pub fn get_query( storage: &RocksDbStorage, @@ -259,7 +259,7 @@ impl Element { .map_ok(|(elements, _)| elements) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Get values of result elements coming from given query pub fn get_query_values( storage: &RocksDbStorage, @@ -297,7 +297,7 @@ impl Element { }) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Returns a vector of result elements and the number of skipped items /// based on given query pub fn get_query_apply_function( @@ -382,7 +382,7 @@ impl Element { Ok((QueryResultElements::from_elements(results), skipped)).wrap_with_cost(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Returns a vector of elements excluding trees, and the number of skipped /// elements pub fn get_path_query( @@ -415,7 +415,7 @@ impl Element { ) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Returns a vector of elements, and the number of skipped elements pub fn get_sized_query( storage: &RocksDbStorage, @@ -443,7 +443,7 @@ impl Element { ) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Push arguments to path query fn path_query_push( args: PathQueryPushArgs, @@ -684,7 +684,7 @@ impl Element { Ok(()).wrap_with_cost(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Takes a sized query and a key and returns subquery key and subquery as /// tuple fn subquery_paths_and_value_for_sized_query( @@ -725,7 +725,7 @@ impl Element { /// trees where the sub elements have no matches, hence the limit would /// not decrease and hence we would continue on the increasingly /// expensive query. - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] // TODO: refactor fn query_item( storage: &RocksDbStorage, @@ -894,7 +894,7 @@ impl Element { .wrap_with_cost(cost) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] fn basic_push(args: PathQueryPushArgs, grove_version: &GroveVersion) -> Result<(), Error> { check_grovedb_v0!( "basic_push", @@ -950,7 +950,7 @@ impl Element { Ok(()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Iterator pub fn iterator(mut raw_iter: I) -> CostContext> { let mut cost = OperationCost::default(); @@ -959,7 +959,7 @@ impl Element { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use grovedb_merk::proofs::Query; @@ -1687,12 +1687,12 @@ mod tests { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub struct ElementsIterator { raw_iter: I, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl ElementsIterator { pub fn new(raw_iter: I) -> Self { ElementsIterator { raw_iter } diff --git a/grovedb/src/element/serialize.rs b/grovedb/src/element/serialize.rs index 395fea8dd..d0974cc93 100644 --- a/grovedb/src/element/serialize.rs +++ b/grovedb/src/element/serialize.rs @@ -4,11 +4,11 @@ use bincode::config; use grovedb_version::{check_grovedb_v0, error::GroveVersionError, version::GroveVersion}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::{Element, Error}; impl Element { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Serializes self. Returns vector of u8s. pub fn serialize(&self, grove_version: &GroveVersion) -> Result, Error> { check_grovedb_v0!( @@ -20,7 +20,7 @@ impl Element { .map_err(|e| Error::CorruptedData(format!("unable to serialize element {}", e))) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Serializes self. Returns usize. pub fn serialized_size(&self, grove_version: &GroveVersion) -> Result { check_grovedb_v0!( @@ -31,7 +31,7 @@ impl Element { .map(|serialized| serialized.len()) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Deserializes given bytes and sets as self pub fn deserialize(bytes: &[u8], grove_version: &GroveVersion) -> Result { check_grovedb_v0!( @@ -45,7 +45,7 @@ impl Element { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use integer_encoding::VarInt; diff --git a/grovedb/src/error.rs b/grovedb/src/error.rs index 923439352..4618e6ac4 100644 --- a/grovedb/src/error.rs +++ b/grovedb/src/error.rs @@ -3,7 +3,7 @@ use std::convert::Infallible; /// GroveDB Errors -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, thiserror::Error)] pub enum Error { #[error("infallible")] @@ -80,7 +80,7 @@ pub enum Error { /// Invalid parameter InvalidParameter(&'static str), - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] // Irrecoverable errors #[error("storage_cost error: {0}")] /// Storage error diff --git a/grovedb/src/lib.rs b/grovedb/src/lib.rs index f3b2dcc4e..8e0b088a0 100644 --- a/grovedb/src/lib.rs +++ b/grovedb/src/lib.rs @@ -125,45 +125,45 @@ //! [Architectural Decision Records](https://github.com/dashpay/grovedb/tree/master/adr) or //! [Tutorial](https://www.grovedb.org/tutorials.html) -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod batch; #[cfg(feature = "grovedbg")] pub mod debugger; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod element; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod error; #[cfg(feature = "estimated_costs")] mod estimated_costs; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod operations; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod query; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod query_result_type; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod reference_path; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod replication; -#[cfg(all(test, feature = "full"))] +#[cfg(all(test, feature = "minimal"))] mod tests; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod util; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod visualize; #[cfg(feature = "grovedbg")] use std::sync::Arc; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{collections::HashMap, option::Option::None, path::Path}; #[cfg(feature = "grovedbg")] use debugger::start_visualizer; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use element::Element; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use element::ElementFlags; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; @@ -174,77 +174,77 @@ pub use grovedb_merk::estimated_costs::{ }, worst_case_costs::WorstCaseLayerInformation, }; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use grovedb_merk::proofs::query::query_item::QueryItem; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use grovedb_merk::proofs::Query; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{ self, tree::{combine_hash, value_hash}, BatchEntry, CryptoHash, KVIterator, Merk, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::PrefixedRocksDbImmediateStorageContext; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::RocksDbStorage; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::{ rocksdb_storage::{PrefixedRocksDbStorageContext, PrefixedRocksDbTransactionContext}, StorageBatch, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::{Storage, StorageContext}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_visualize::DebugByteVectors; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use query::{PathQuery, SizedQuery}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use reference_path::path_from_reference_path_type; #[cfg(feature = "grovedbg")] use tokio::net::ToSocketAddrs; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::element::helpers::raw_decode; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use crate::error::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::operations::proof::util::hex_to_ascii; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::util::{root_merk_optional_tx, storage_context_optional_tx}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::Error::MerkError; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] type Hash = [u8; 32]; /// GroveDb pub struct GroveDb { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] db: RocksDbStorage, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub(crate) type SubtreePrefix = [u8; blake3::OUT_LEN]; /// Transaction -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub type Transaction<'db> = >::Transaction; /// TransactionArg -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub type TransactionArg<'db, 'a> = Option<&'a Transaction<'db>>; /// Type alias for the return type of the `verify_merk_and_submerks` and /// `verify_grovedb` functions. It represents a mapping of paths (as vectors of /// vectors of bytes) to a tuple of three cryptographic hashes: the root hash, /// the combined value hash, and the expected value hash. -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] type VerificationIssues = HashMap>, (CryptoHash, CryptoHash, CryptoHash)>; /// Type alias for the return type of the `open_merk_for_replication` function. @@ -252,14 +252,14 @@ type VerificationIssues = HashMap>, (CryptoHash, CryptoHash, CryptoH /// - A `Merk` instance with a prefixed RocksDB immediate storage context. /// - An optional `root_key`, represented as a vector of bytes. /// - A boolean indicating whether the Merk is a sum tree. -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] type OpenedMerkForReplication<'tx> = ( Merk>, Option>, bool, ); -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Opens a given path pub fn open>(path: P) -> Result { diff --git a/grovedb/src/operations/auxiliary.rs b/grovedb/src/operations/auxiliary.rs index 516796ed5..493e6e747 100644 --- a/grovedb/src/operations/auxiliary.rs +++ b/grovedb/src/operations/auxiliary.rs @@ -28,22 +28,22 @@ //! Auxiliary operations -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, storage_cost::key_value_cost::KeyValueStorageCost, CostResult, CostsExt, OperationCost, }; use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::StorageContext; use grovedb_storage::{Storage, StorageBatch}; use grovedb_version::version::GroveVersion; use crate::util::storage_context_optional_tx; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{util::meta_storage_context_optional_tx, Element, Error, GroveDb, TransactionArg}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Put op for aux storage pub fn put_aux>( diff --git a/grovedb/src/operations/delete/average_case.rs b/grovedb/src/operations/delete/average_case.rs index 986f2b90a..c60de1014 100644 --- a/grovedb/src/operations/delete/average_case.rs +++ b/grovedb/src/operations/delete/average_case.rs @@ -32,7 +32,7 @@ impl GroveDb { key: &KeyInfo, stop_path_height: Option, validate: bool, - estimated_layer_info: IntMap, + estimated_layer_info: IntMap, grove_version: &GroveVersion, ) -> CostResult, Error> { check_grovedb_v0_with_cost!( diff --git a/grovedb/src/operations/delete/delete_up_tree.rs b/grovedb/src/operations/delete/delete_up_tree.rs index 7ecfce83e..2255f29de 100644 --- a/grovedb/src/operations/delete/delete_up_tree.rs +++ b/grovedb/src/operations/delete/delete_up_tree.rs @@ -15,7 +15,7 @@ use crate::{ TransactionArg, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone)] /// Delete up tree options pub struct DeleteUpTreeOptions { @@ -31,7 +31,7 @@ pub struct DeleteUpTreeOptions { pub stop_path_height: Option, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for DeleteUpTreeOptions { fn default() -> Self { DeleteUpTreeOptions { @@ -44,7 +44,7 @@ impl Default for DeleteUpTreeOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl DeleteUpTreeOptions { fn to_delete_options(&self) -> DeleteOptions { DeleteOptions { @@ -56,7 +56,7 @@ impl DeleteUpTreeOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Delete up tree while empty will delete nodes while they are empty up a /// tree. diff --git a/grovedb/src/operations/delete/mod.rs b/grovedb/src/operations/delete/mod.rs index 9244c60be..9e24ad3ee 100644 --- a/grovedb/src/operations/delete/mod.rs +++ b/grovedb/src/operations/delete/mod.rs @@ -2,27 +2,27 @@ #[cfg(feature = "estimated_costs")] mod average_case; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod delete_up_tree; #[cfg(feature = "estimated_costs")] mod worst_case; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::collections::{BTreeSet, HashMap}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use delete_up_tree::DeleteUpTreeOptions; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, storage_cost::removal::{StorageRemovedBytes, StorageRemovedBytes::BasicStorageRemoval}, CostResult, CostsExt, OperationCost, }; use grovedb_merk::{proofs::Query, KVIterator}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{Error as MerkError, Merk, MerkOptions}; use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::{ rocksdb_storage::{PrefixedRocksDbStorageContext, PrefixedRocksDbTransactionContext}, Storage, StorageBatch, StorageContext, @@ -31,7 +31,7 @@ use grovedb_version::{ check_grovedb_v0_with_cost, error::GroveVersionError, version::GroveVersion, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ batch::{GroveOp, QualifiedGroveDbOp}, util::storage_context_with_parent_optional_tx, @@ -39,7 +39,7 @@ use crate::{ }; use crate::{raw_decode, util::merk_optional_tx_path_not_empty}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone)] /// Clear options pub struct ClearOptions { @@ -52,7 +52,7 @@ pub struct ClearOptions { pub trying_to_clear_with_subtrees_returns_error: bool, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for ClearOptions { fn default() -> Self { ClearOptions { @@ -63,7 +63,7 @@ impl Default for ClearOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone)] /// Delete options pub struct DeleteOptions { @@ -77,7 +77,7 @@ pub struct DeleteOptions { pub validate_tree_at_path_exists: bool, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for DeleteOptions { fn default() -> Self { DeleteOptions { @@ -89,7 +89,7 @@ impl Default for DeleteOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl DeleteOptions { fn as_merk_options(&self) -> MerkOptions { MerkOptions { @@ -98,7 +98,7 @@ impl DeleteOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Delete an element at a specified subtree path and key. pub fn delete<'b, B, P>( @@ -994,7 +994,7 @@ impl GroveDb { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use grovedb_costs::{ diff --git a/grovedb/src/operations/delete/worst_case.rs b/grovedb/src/operations/delete/worst_case.rs index 8533cde55..effcb5fec 100644 --- a/grovedb/src/operations/delete/worst_case.rs +++ b/grovedb/src/operations/delete/worst_case.rs @@ -18,7 +18,7 @@ use crate::{ Error, GroveDb, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Worst case costs for delete operations for delete up tree while empty pub fn worst_case_delete_operations_for_delete_up_tree_while_empty<'db, S: Storage<'db>>( @@ -26,7 +26,7 @@ impl GroveDb { key: &KeyInfo, stop_path_height: Option, validate: bool, - intermediate_tree_info: IntMap<(bool, u32)>, + intermediate_tree_info: IntMap, max_element_size: u32, grove_version: &GroveVersion, ) -> CostResult, Error> { diff --git a/grovedb/src/operations/get/average_case.rs b/grovedb/src/operations/get/average_case.rs index aca4426df..0cb44462d 100644 --- a/grovedb/src/operations/get/average_case.rs +++ b/grovedb/src/operations/get/average_case.rs @@ -1,19 +1,19 @@ //! Average case get costs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::OperationCost; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::RocksDbStorage; use grovedb_version::{check_grovedb_v0, error::GroveVersionError, version::GroveVersion}; use crate::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ batch::{key_info::KeyInfo, KeyInfoPath}, GroveDb, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Get the Operation Cost for a has query that doesn't follow /// references with the following parameters diff --git a/grovedb/src/operations/get/mod.rs b/grovedb/src/operations/get/mod.rs index b62896996..4b1d0ccdf 100644 --- a/grovedb/src/operations/get/mod.rs +++ b/grovedb/src/operations/get/mod.rs @@ -2,38 +2,38 @@ #[cfg(feature = "estimated_costs")] mod average_case; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod query; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use query::QueryItemOrSumReturnType; #[cfg(feature = "estimated_costs")] mod worst_case; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::collections::HashSet; use grovedb_costs::cost_return_on_error_no_add; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{cost_return_on_error, CostResult, CostsExt, OperationCost}; use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::StorageContext; use grovedb_version::{ check_grovedb_v0_with_cost, error::GroveVersionError, version::GroveVersion, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ reference_path::{path_from_reference_path_type, path_from_reference_qualified_path_type}, util::storage_context_optional_tx, Element, Error, GroveDb, Transaction, TransactionArg, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Limit of possible indirections pub const MAX_REFERENCE_HOPS: usize = 10; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Get an element from the backing store /// Merk Caching is on by default diff --git a/grovedb/src/operations/get/query.rs b/grovedb/src/operations/get/query.rs index 81046dbfc..0e97f7fbc 100644 --- a/grovedb/src/operations/get/query.rs +++ b/grovedb/src/operations/get/query.rs @@ -1,30 +1,30 @@ //! Query operations use grovedb_costs::cost_return_on_error_default; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; use grovedb_version::{ check_grovedb_v0, check_grovedb_v0_with_cost, error::GroveVersionError, version::GroveVersion, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::element::SumValue; use crate::{ element::QueryOptions, operations::proof::ProveOptions, query_result_type::PathKeyOptionalElementTrio, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ query_result_type::{QueryResultElement, QueryResultElements, QueryResultType}, reference_path::ReferencePathType, Element, Error, GroveDb, PathQuery, TransactionArg, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Debug, Eq, PartialEq, Clone)] /// A return type for query_item_value_or_sum pub enum QueryItemOrSumReturnType { @@ -34,7 +34,7 @@ pub enum QueryItemOrSumReturnType { SumValue(SumValue), } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Encoded query for multiple path queries pub fn query_encoded_many( @@ -688,7 +688,7 @@ where { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use std::collections::HashMap; diff --git a/grovedb/src/operations/get/worst_case.rs b/grovedb/src/operations/get/worst_case.rs index 7554a9111..591d6150c 100644 --- a/grovedb/src/operations/get/worst_case.rs +++ b/grovedb/src/operations/get/worst_case.rs @@ -1,19 +1,19 @@ //! Worst case get costs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::OperationCost; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::RocksDbStorage; use grovedb_version::{check_grovedb_v0, error::GroveVersionError, version::GroveVersion}; use crate::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ batch::{key_info::KeyInfo, KeyInfoPath}, GroveDb, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Worst case cost for has raw pub fn worst_case_for_has_raw( diff --git a/grovedb/src/operations/insert/mod.rs b/grovedb/src/operations/insert/mod.rs index 5926fedd2..57a593806 100644 --- a/grovedb/src/operations/insert/mod.rs +++ b/grovedb/src/operations/insert/mod.rs @@ -1,16 +1,16 @@ //! Insert operations -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{collections::HashMap, option::Option::None}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_merk::{tree::NULL_HASH, Merk, MerkOptions}; use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::rocksdb_storage::{ PrefixedRocksDbStorageContext, PrefixedRocksDbTransactionContext, }; @@ -19,13 +19,13 @@ use grovedb_version::{ check_grovedb_v0_with_cost, error::GroveVersionError, version::GroveVersion, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ reference_path::path_from_reference_path_type, Element, Error, GroveDb, Transaction, TransactionArg, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone)] /// Insert options pub struct InsertOptions { @@ -37,7 +37,7 @@ pub struct InsertOptions { pub base_root_storage_is_free: bool, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for InsertOptions { fn default() -> Self { InsertOptions { @@ -48,7 +48,7 @@ impl Default for InsertOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl InsertOptions { fn checks_for_override(&self) -> bool { self.validate_insertion_does_not_override_tree || self.validate_insertion_does_not_override @@ -61,7 +61,7 @@ impl InsertOptions { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Insert a GroveDB element given a path to the subtree and the key to /// insert at @@ -640,7 +640,7 @@ impl GroveDb { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use grovedb_costs::{ diff --git a/grovedb/src/operations/is_empty_tree.rs b/grovedb/src/operations/is_empty_tree.rs index 07c349991..a007d219f 100644 --- a/grovedb/src/operations/is_empty_tree.rs +++ b/grovedb/src/operations/is_empty_tree.rs @@ -1,16 +1,16 @@ //! Check if empty tree operations -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{cost_return_on_error, CostResult, CostsExt, OperationCost}; use grovedb_path::SubtreePath; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::error::GroveVersionError; use grovedb_version::{check_grovedb_v0_with_cost, version::GroveVersion}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{util::merk_optional_tx, Element, Error, GroveDb, TransactionArg}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { /// Check if it's an empty tree pub fn is_empty_tree<'b, B, P>( diff --git a/grovedb/src/operations/mod.rs b/grovedb/src/operations/mod.rs index ba9b85999..08f0918d9 100644 --- a/grovedb/src/operations/mod.rs +++ b/grovedb/src/operations/mod.rs @@ -1,18 +1,18 @@ //! Operations for the manipulation of GroveDB state -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub(crate) mod auxiliary; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod delete; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub(crate) mod get; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod insert; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub(crate) mod is_empty_tree; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod proof; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use get::{QueryItemOrSumReturnType, MAX_REFERENCE_HOPS}; diff --git a/grovedb/src/operations/proof/generate.rs b/grovedb/src/operations/proof/generate.rs index 6e814f67f..d8bfc2094 100644 --- a/grovedb/src/operations/proof/generate.rs +++ b/grovedb/src/operations/proof/generate.rs @@ -173,11 +173,10 @@ impl GroveDb { ) ); - Ok(GroveDBProofV0 { + Ok(GroveDBProof::V0(GroveDBProofV0 { root_layer, prove_options, - } - .into()) + })) .wrap_with_cost(cost) } diff --git a/grovedb/src/operations/proof/mod.rs b/grovedb/src/operations/proof/mod.rs index c90e176be..cadc60326 100644 --- a/grovedb/src/operations/proof/mod.rs +++ b/grovedb/src/operations/proof/mod.rs @@ -1,6 +1,6 @@ //! Proof operations -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod generate; pub mod util; mod verify; @@ -8,7 +8,6 @@ mod verify; use std::{collections::BTreeMap, fmt}; use bincode::{Decode, Encode}; -use derive_more::From; use grovedb_merk::{ proofs::{ query::{Key, VerifyOptions}, @@ -64,7 +63,7 @@ pub struct LayerProof { pub lower_layers: BTreeMap, } -#[derive(Encode, Decode, From)] +#[derive(Encode, Decode)] pub enum GroveDBProof { V0(GroveDBProofV0), } diff --git a/grovedb/src/operations/proof/util.rs b/grovedb/src/operations/proof/util.rs index a33954d1f..1f7104906 100644 --- a/grovedb/src/operations/proof/util.rs +++ b/grovedb/src/operations/proof/util.rs @@ -8,20 +8,20 @@ use grovedb_version::version::GroveVersion; use crate::Element; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub type ProvedKeyValues = Vec; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub type ProvedKeyOptionalValues = Vec; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub type ProvedPathKeyValues = Vec; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub type ProvedPathKeyOptionalValues = Vec; /// Proved path-key-value -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, PartialEq, Eq)] pub struct ProvedPathKeyOptionalValue { /// Path @@ -34,7 +34,7 @@ pub struct ProvedPathKeyOptionalValue { pub proof: CryptoHash, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for ProvedPathKeyOptionalValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "ProvedPathKeyValue {{")?; @@ -59,7 +59,7 @@ impl fmt::Display for ProvedPathKeyOptionalValue { } /// Proved path-key-value -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, PartialEq, Eq)] pub struct ProvedPathKeyValue { /// Path @@ -72,7 +72,7 @@ pub struct ProvedPathKeyValue { pub proof: CryptoHash, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for ProvedPathKeyValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "ProvedPathKeyValue {{")?; diff --git a/grovedb/src/query/mod.rs b/grovedb/src/query/mod.rs index 07930c4ed..890da1dbc 100644 --- a/grovedb/src/query/mod.rs +++ b/grovedb/src/query/mod.rs @@ -7,21 +7,21 @@ use std::{ }; use bincode::{Decode, Encode}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use grovedb_merk::proofs::query::query_item::QueryItem; use grovedb_merk::proofs::query::{Key, SubqueryBranch}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use grovedb_merk::proofs::Query; use grovedb_version::{check_grovedb_v0, error::GroveVersionError, version::GroveVersion}; use indexmap::IndexMap; use crate::operations::proof::util::hex_to_ascii; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::query_result_type::PathKey; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::Error; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, Clone, PartialEq, Encode, Decode)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Path query @@ -35,7 +35,7 @@ pub struct PathQuery { pub query: SizedQuery, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for PathQuery { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "PathQuery {{ path: [")?; @@ -49,7 +49,7 @@ impl fmt::Display for PathQuery { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, Clone, PartialEq, Encode, Decode)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Holds a query to apply to a tree and an optional limit/offset value. @@ -63,7 +63,7 @@ pub struct SizedQuery { pub offset: Option, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for SizedQuery { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "SizedQuery {{ query: {}", self.query)?; @@ -77,7 +77,7 @@ impl fmt::Display for SizedQuery { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl SizedQuery { /// New sized query pub const fn new(query: Query, limit: Option, offset: Option) -> Self { @@ -107,7 +107,7 @@ impl SizedQuery { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl PathQuery { /// New path query pub const fn new(path: Vec>, query: SizedQuery) -> Self { @@ -455,7 +455,7 @@ impl PathQuery { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, Clone, PartialEq)] pub enum HasSubquery<'a> { NoSubquery, @@ -463,7 +463,7 @@ pub enum HasSubquery<'a> { Conditionally(Cow<'a, IndexMap>), } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl<'a> fmt::Display for HasSubquery<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -495,7 +495,7 @@ impl<'a> HasSubquery<'a> { /// This represents a query where the items might be borrowed, it is used to get /// subquery information -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, Clone, PartialEq)] pub struct SinglePathSubquery<'a> { /// Items @@ -508,7 +508,7 @@ pub struct SinglePathSubquery<'a> { pub in_path: Option>, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl<'a> fmt::Display for SinglePathSubquery<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "InternalCowItemsQuery {{")?; @@ -582,7 +582,7 @@ impl<'a> SinglePathSubquery<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use std::{borrow::Cow, ops::RangeFull}; diff --git a/grovedb/src/query_result_type.rs b/grovedb/src/query_result_type.rs index 1850544e7..a8d329f7b 100644 --- a/grovedb/src/query_result_type.rs +++ b/grovedb/src/query_result_type.rs @@ -462,7 +462,7 @@ impl fmt::Display for QueryResultElement { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl QueryResultElement { /// Map element pub fn map_element( @@ -487,23 +487,23 @@ impl QueryResultElement { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for key-element common pattern. pub type KeyElementPair = (Key, Element); -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for key optional_element common pattern. pub type KeyOptionalElementPair = (Key, Option); -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for path-key-element common pattern. pub type PathKeyElementTrio = (Path, Key, Element); -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for path - key - optional_element common pattern. pub type PathKeyOptionalElementTrio = (Path, Key, Option); -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl TryFromVersioned for PathKeyOptionalElementTrio { type Error = Error; @@ -520,7 +520,7 @@ impl TryFromVersioned for PathKeyOptionalElementTrio { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl TryFromVersioned for PathKeyOptionalElementTrio { type Error = Error; @@ -540,7 +540,7 @@ impl TryFromVersioned for PathKeyOptionalElementTrio } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use grovedb_version::{version::GroveVersion, TryIntoVersioned}; diff --git a/grovedb/src/reference_path.rs b/grovedb/src/reference_path.rs index fcfeee6ed..afd852600 100644 --- a/grovedb/src/reference_path.rs +++ b/grovedb/src/reference_path.rs @@ -1,19 +1,19 @@ //! Space efficient methods for referencing other elements in GroveDB -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use std::fmt; use bincode::{Decode, Encode}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_visualize::visualize_to_vec; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::Error; -#[cfg(any(feature = "full", feature = "verify"))] -#[cfg_attr(not(any(feature = "full", feature = "visualize")), derive(Debug))] +#[cfg(any(feature = "minimal", feature = "verify"))] +#[cfg_attr(not(any(feature = "minimal", feature = "visualize")), derive(Debug))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Reference path variants #[derive(Hash, Eq, PartialEq, Encode, Decode, Clone)] @@ -110,7 +110,7 @@ impl fmt::Display for ReferencePathType { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl ReferencePathType { /// Given the reference path type and the current qualified path (path+key), /// this computes the absolute path of the item the reference is pointing @@ -134,7 +134,7 @@ impl ReferencePathType { } } -#[cfg(any(feature = "full", feature = "visualize"))] +#[cfg(any(feature = "minimal", feature = "visualize"))] impl fmt::Debug for ReferencePathType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut v = Vec::new(); @@ -144,7 +144,7 @@ impl fmt::Debug for ReferencePathType { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Given the reference path type and the current qualified path (path+key), /// this computes the absolute path of the item the reference is pointing to. pub fn path_from_reference_qualified_path_type>( @@ -161,7 +161,7 @@ pub fn path_from_reference_qualified_path_type>( } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Given the reference path type, the current path and the terminal key, this /// computes the absolute path of the item the reference is pointing to. pub fn path_from_reference_path_type>( @@ -285,7 +285,7 @@ pub fn path_from_reference_path_type>( } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl ReferencePathType { /// Serialized size pub fn serialized_size(&self) -> usize { @@ -320,7 +320,7 @@ impl ReferencePathType { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use grovedb_merk::proofs::Query; diff --git a/grovedb/src/replication.rs b/grovedb/src/replication.rs index 1cd505192..0996c324c 100644 --- a/grovedb/src/replication.rs +++ b/grovedb/src/replication.rs @@ -20,7 +20,7 @@ pub type ChunkIdentifier = (crate::SubtreePrefix, Option>, bool, Vec pub const CURRENT_STATE_SYNC_VERSION: u16 = 1; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl GroveDb { pub fn start_syncing_session(&self, app_hash: [u8; 32]) -> Pin> { MultiStateSyncSession::new(self.start_transaction(), app_hash) diff --git a/merk/Cargo.toml b/merk/Cargo.toml index cdb47bdf4..40510f6bc 100644 --- a/merk/Cargo.toml +++ b/merk/Cargo.toml @@ -18,56 +18,45 @@ grovedb-version = { version = "2.1.0", path = "../grovedb-version" } grovedb-visualize = { version = "2.1.0", path = "../visualize" } bincode = { version = "2.0.0-rc.3" } -failure = "0.1.8" hex = "0.4.3" indexmap = "2.2.6" integer-encoding = "4.0.0" -thiserror = "1.0.58" +thiserror = "2.0.11" serde = { version = "1.0.210", features = ["derive"], optional = true } - -[dependencies.time] -version = "0.3.34" -optional = true +rand = { version = "0.8.5", features = ["small_rng"], optional = true } [dependencies.colored] -version = "2.1.0" +version = "3.0.0" optional = true [dependencies.num_cpus] version = "1.16.0" optional = true -[dependencies.byteorder] -version = "1.5.0" -optional = true - [dependencies.ed] version = "0.2.2" optional = true [dependencies.blake3] -version = "1.5.1" -optional = true - -[dependencies.rand] -version = "0.8.5" -features = ["small_rng"] +version = "1.5.5" optional = true [features] default = ["full"] proof_debug = [] serde = ["dep:serde", "indexmap/serde"] -full = ["rand", - "time", - "colored", - "num_cpus", - "byteorder", +minimal = ["num_cpus", "ed", "blake3", "grovedb-storage", "grovedb-storage/rocksdb_storage" ] +full = ["minimal", + "test_utils", + "colored_debug", +] +test_utils = ["rand"] +colored_debug = ["colored"] verify = [ "ed", "blake3" diff --git a/merk/src/error.rs b/merk/src/error.rs index c365b898e..8fdc1cfca 100644 --- a/merk/src/error.rs +++ b/merk/src/error.rs @@ -1,8 +1,8 @@ //! Errors -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::proofs::chunk::error::ChunkError; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, thiserror::Error)] /// Errors pub enum Error { @@ -36,7 +36,7 @@ pub enum Error { CorruptedState(&'static str), /// Chunking error - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] #[error("chunking error {0}")] ChunkingError(ChunkError), @@ -46,7 +46,7 @@ pub enum Error { OldChunkingError(&'static str), /// Chunk restoring error - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] #[error("chunk restoring error {0}")] ChunkRestoringError(ChunkError), @@ -99,7 +99,7 @@ pub enum Error { #[error("client corruption error {0}")] ClientCorruptionError(String), - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Storage error #[error("storage error {0}")] StorageError(grovedb_storage::Error), diff --git a/merk/src/estimated_costs/average_case_costs.rs b/merk/src/estimated_costs/average_case_costs.rs index fc08ab45d..6e877efe1 100644 --- a/merk/src/estimated_costs/average_case_costs.rs +++ b/merk/src/estimated_costs/average_case_costs.rs @@ -1,11 +1,11 @@ //! Average case costs for Merk -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{CostResult, CostsExt, OperationCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ error::Error, estimated_costs::LAYER_COST_SIZE, @@ -13,20 +13,20 @@ use crate::{ HASH_BLOCK_SIZE, HASH_BLOCK_SIZE_U32, HASH_LENGTH, HASH_LENGTH_U32, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Average key size pub type AverageKeySize = u8; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Average value size pub type AverageValueSize = u32; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Average flags size pub type AverageFlagsSize = u32; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Weight pub type Weight = u8; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, Copy, PartialEq, Eq, Debug)] /// Estimated number of sum trees #[derive(Default)] @@ -45,8 +45,8 @@ pub enum EstimatedSumTrees { AllSumTrees, } -#[cfg(feature = "full")] -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] +#[cfg(feature = "minimal")] impl EstimatedSumTrees { fn estimated_size(&self) -> Result { match self { @@ -62,7 +62,7 @@ impl EstimatedSumTrees { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, Copy, PartialEq, Eq, Debug)] /// Estimated layer sizes pub enum EstimatedLayerSizes { @@ -98,7 +98,7 @@ pub enum EstimatedLayerSizes { }, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl EstimatedLayerSizes { /// Return average flags size for layer pub fn layered_flags_size(&self) -> Result<&Option, Error> { @@ -220,17 +220,17 @@ impl EstimatedLayerSizes { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Approximate element count pub type ApproximateElementCount = u32; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Estimated level number pub type EstimatedLevelNumber = u32; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Estimated to be empty pub type EstimatedToBeEmpty = bool; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, Copy, PartialEq, Eq, Debug)] /// Information on an estimated layer pub struct EstimatedLayerInformation { @@ -242,10 +242,10 @@ pub struct EstimatedLayerInformation { pub estimated_layer_sizes: EstimatedLayerSizes, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl EstimatedLayerInformation {} -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, Copy, PartialEq, Eq, Debug)] /// Estimated elements and level number of a layer pub enum EstimatedLayerCount { @@ -257,7 +257,7 @@ pub enum EstimatedLayerCount { EstimatedLevel(EstimatedLevelNumber, EstimatedToBeEmpty), } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl EstimatedLayerCount { /// Returns true if the tree is estimated to be empty. pub fn estimated_to_be_empty(&self) -> bool { @@ -285,7 +285,7 @@ impl EstimatedLayerCount { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeNode { /// Return estimate of average encoded tree size pub fn average_case_encoded_tree_size( @@ -301,7 +301,7 @@ impl TreeNode { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for getting a merk node pub fn add_average_case_get_merk_node( cost: &mut OperationCost, @@ -323,7 +323,7 @@ pub fn add_average_case_get_merk_node( Ok(()) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for getting a merk tree pub fn add_average_case_merk_has_value( cost: &mut OperationCost, @@ -334,7 +334,7 @@ pub fn add_average_case_merk_has_value( cost.storage_loaded_bytes += (not_prefixed_key_len + estimated_element_size) as u64; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for insertion into merk pub fn add_average_case_merk_replace_layered( cost: &mut OperationCost, @@ -357,7 +357,7 @@ pub fn add_average_case_merk_replace_layered( cost.hash_node_calls += 2; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add average case for deletion from merk pub fn add_average_case_merk_delete_layered( cost: &mut OperationCost, @@ -369,7 +369,7 @@ pub fn add_average_case_merk_delete_layered( cost.hash_node_calls += 1 + ((value_len - 1) / HASH_BLOCK_SIZE_U32); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add average case for deletion from merk pub fn add_average_case_merk_delete(cost: &mut OperationCost, _key_len: u32, value_len: u32) { // todo: verify this @@ -377,7 +377,7 @@ pub fn add_average_case_merk_delete(cost: &mut OperationCost, _key_len: u32, val cost.hash_node_calls += 1 + ((value_len - 1) / HASH_BLOCK_SIZE_U32); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] const fn node_hash_update_count() -> u32 { // It's a hash of node hash, left and right let bytes = HASH_LENGTH * 3; @@ -386,20 +386,20 @@ const fn node_hash_update_count() -> u32 { 1 + ((bytes - 1) / HASH_BLOCK_SIZE) as u32 } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for getting a merk tree root hash pub fn add_average_case_merk_root_hash(cost: &mut OperationCost) { cost.hash_node_calls += node_hash_update_count(); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Average case cost of propagating a merk pub fn average_case_merk_propagate(input: &EstimatedLayerInformation) -> CostResult<(), Error> { let mut cost = OperationCost::default(); add_average_case_merk_propagate(&mut cost, input).wrap_with_cost(cost) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add average case cost for propagating a merk pub fn add_average_case_merk_propagate( cost: &mut OperationCost, diff --git a/merk/src/estimated_costs/mod.rs b/merk/src/estimated_costs/mod.rs index bd669db12..7648246bc 100644 --- a/merk/src/estimated_costs/mod.rs +++ b/merk/src/estimated_costs/mod.rs @@ -1,20 +1,20 @@ //! Estimated costs for Merk -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::OperationCost; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{tree::kv::KV, HASH_BLOCK_SIZE_U32, HASH_LENGTH_U32}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod average_case_costs; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod worst_case_costs; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// The cost of a subtree layer /// It is 3 because we have: /// 1 byte for the element type @@ -22,16 +22,16 @@ pub mod worst_case_costs; /// 1 byte for the flag option pub const LAYER_COST_SIZE: u32 = 3; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// The cost of a sum value pub const SUM_VALUE_EXTRA_COST: u32 = 9; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// The cost of a summed subtree layer /// This is the layer size + 9 for the encoded value pub const SUM_LAYER_COST_SIZE: u32 = LAYER_COST_SIZE + SUM_VALUE_EXTRA_COST; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl KV { fn encoded_kv_node_size(element_size: u32, is_sum_node: bool) -> u32 { // We always charge 8 bytes for the sum node (even though @@ -45,7 +45,7 @@ impl KV { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add cost case for insertion into merk pub fn add_cost_case_merk_insert( cost: &mut OperationCost, @@ -69,7 +69,7 @@ pub fn add_cost_case_merk_insert( cost.hash_node_calls += 2; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add cost case for insertion into merk pub fn add_cost_case_merk_insert_layered( cost: &mut OperationCost, @@ -95,7 +95,7 @@ pub fn add_cost_case_merk_insert_layered( cost.hash_node_calls += 2; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add cost case for insertion into merk pub fn add_cost_case_merk_replace( cost: &mut OperationCost, @@ -117,7 +117,7 @@ pub fn add_cost_case_merk_replace( cost.hash_node_calls += 2; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add cost case for replacement in merk when the value size is known to not /// change pub fn add_cost_case_merk_replace_same_size( @@ -142,7 +142,7 @@ pub fn add_cost_case_merk_replace_same_size( cost.hash_node_calls += 2; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add cost case for insertion into merk pub fn add_cost_case_merk_replace_layered( cost: &mut OperationCost, @@ -168,7 +168,7 @@ pub fn add_cost_case_merk_replace_layered( cost.hash_node_calls += 2; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add cost case for replacement in merk when the value size is known to not /// change pub fn add_cost_case_merk_patch( diff --git a/merk/src/estimated_costs/worst_case_costs.rs b/merk/src/estimated_costs/worst_case_costs.rs index 9ae6c2b3c..3cbd63997 100644 --- a/merk/src/estimated_costs/worst_case_costs.rs +++ b/merk/src/estimated_costs/worst_case_costs.rs @@ -30,10 +30,10 @@ use std::cmp::Ordering; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{CostResult, CostsExt, OperationCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ error::Error, merk::defaults::MAX_PREFIXED_KEY_SIZE, @@ -41,7 +41,7 @@ use crate::{ HASH_BLOCK_SIZE, HASH_BLOCK_SIZE_U32, HASH_LENGTH, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, PartialEq, Eq, Debug)] /// Worst case layer info pub enum WorstCaseLayerInformation { @@ -51,7 +51,7 @@ pub enum WorstCaseLayerInformation { NumberOfLevels(u32), } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeNode { /// Return worst case size of encoded tree pub fn worst_case_encoded_tree_size( @@ -67,7 +67,7 @@ impl TreeNode { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for getting a merk node pub fn add_worst_case_get_merk_node( cost: &mut OperationCost, @@ -87,7 +87,7 @@ pub fn add_worst_case_get_merk_node( Ok(()) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for getting a merk tree pub fn add_worst_case_merk_has_value( cost: &mut OperationCost, @@ -98,7 +98,7 @@ pub fn add_worst_case_merk_has_value( cost.storage_loaded_bytes += not_prefixed_key_len as u64 + max_element_size as u64; } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for insertion into merk pub fn add_worst_case_merk_insert( cost: &mut OperationCost, @@ -113,7 +113,7 @@ pub fn add_worst_case_merk_insert( cost.hash_node_calls += 1 + ((value_len - 1) / HASH_BLOCK_SIZE_U32); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for insertion into merk pub fn add_worst_case_merk_replace_layered( cost: &mut OperationCost, @@ -128,7 +128,7 @@ pub fn add_worst_case_merk_replace_layered( // 37 + 35 + key_len } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add average case for deletion from merk pub fn add_worst_case_merk_delete_layered(cost: &mut OperationCost, _key_len: u32, value_len: u32) { // todo: verify this @@ -136,7 +136,7 @@ pub fn add_worst_case_merk_delete_layered(cost: &mut OperationCost, _key_len: u3 cost.hash_node_calls += 1 + ((value_len - 1) / HASH_BLOCK_SIZE_U32); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add average case for deletion from merk pub fn add_worst_case_merk_delete(cost: &mut OperationCost, _key_len: u32, value_len: u32) { // todo: verify this @@ -144,7 +144,7 @@ pub fn add_worst_case_merk_delete(cost: &mut OperationCost, _key_len: u32, value cost.hash_node_calls += 1 + ((value_len - 1) / HASH_BLOCK_SIZE_U32); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] const fn node_hash_update_count() -> u32 { // It's a hash of node hash, left and right let bytes = HASH_LENGTH * 3; @@ -153,27 +153,27 @@ const fn node_hash_update_count() -> u32 { 1 + ((bytes - 1) / HASH_BLOCK_SIZE) as u32 } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case for getting a merk tree root hash pub fn add_worst_case_merk_root_hash(cost: &mut OperationCost) { cost.hash_node_calls += node_hash_update_count(); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Merk biggest value size pub const MERK_BIGGEST_VALUE_SIZE: u32 = u16::MAX as u32; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Merk biggest key size pub const MERK_BIGGEST_KEY_SIZE: u32 = 256; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Worst case cost of a merk propagation pub fn worst_case_merk_propagate(input: &WorstCaseLayerInformation) -> CostResult<(), Error> { let mut cost = OperationCost::default(); add_worst_case_merk_propagate(&mut cost, input).wrap_with_cost(cost) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case cost of a merk propagation pub fn add_worst_case_merk_propagate( cost: &mut OperationCost, @@ -216,7 +216,7 @@ pub fn add_worst_case_merk_propagate( Ok(()) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Add worst case cost for is_empty_tree_except pub fn add_worst_case_cost_for_is_empty_tree_except( cost: &mut OperationCost, @@ -227,7 +227,7 @@ pub fn add_worst_case_cost_for_is_empty_tree_except( } /// Add average case cost for is_empty_tree_except -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub fn add_average_case_cost_for_is_empty_tree_except( cost: &mut OperationCost, except_keys_count: u16, diff --git a/merk/src/lib.rs b/merk/src/lib.rs index d746a885a..0291314b1 100644 --- a/merk/src/lib.rs +++ b/merk/src/lib.rs @@ -31,60 +31,60 @@ // #![deny(missing_docs)] /// The top-level store API. -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod merk; #[cfg(feature = "grovedbg")] pub mod debugger; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use crate::merk::{chunks::ChunkProducer, options::MerkOptions, restore::Restorer}; /// Provides a container type that allows temporarily taking ownership of a /// value. // TODO: move this into its own crate -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod owner; /// Algorithms for generating and verifying Merkle proofs. -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod proofs; /// Various helpers useful for tests or benchmarks. -#[cfg(feature = "full")] +#[cfg(feature = "test_utils")] pub mod test_utils; /// The core tree data structure. -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod tree; /// Errors -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod error; /// Estimated costs -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod estimated_costs; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod visualize; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use ed; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use error::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use tree::{ BatchEntry, Link, MerkBatch, Op, PanicSource, HASH_BLOCK_SIZE, HASH_BLOCK_SIZE_U32, HASH_LENGTH, HASH_LENGTH_U32, HASH_LENGTH_U32_X2, }; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use tree::{CryptoHash, TreeFeatureType}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use crate::merk::{ defaults::ROOT_KEY_KEY, prove::{ProofConstructionResult, ProofWithoutEncodingResult}, IsSumTree, KVIterator, Merk, MerkType, RootHashKeyAndSum, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use crate::visualize::VisualizeableMerk; diff --git a/merk/src/merk/defaults.rs b/merk/src/merk/defaults.rs index 87734e9b0..5cda65522 100644 --- a/merk/src/merk/defaults.rs +++ b/merk/src/merk/defaults.rs @@ -28,10 +28,10 @@ //! Default values -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Root key key pub const ROOT_KEY_KEY: &[u8] = b"r"; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const MAX_UPDATE_VALUE_BASED_ON_COSTS_TIMES: u8 = 8; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const MAX_PREFIXED_KEY_SIZE: u64 = 288; diff --git a/merk/src/merk/options.rs b/merk/src/merk/options.rs index bfd78e0ee..507354f82 100644 --- a/merk/src/merk/options.rs +++ b/merk/src/merk/options.rs @@ -28,14 +28,14 @@ //! Merk options -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Merk options pub struct MerkOptions { /// Base root storage is free? pub base_root_storage_is_free: bool, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for MerkOptions { fn default() -> Self { Self { diff --git a/merk/src/proofs/chunk.rs b/merk/src/proofs/chunk.rs index 063a35754..7ba02c883 100644 --- a/merk/src/proofs/chunk.rs +++ b/merk/src/proofs/chunk.rs @@ -1,9 +1,9 @@ //! Chunk proofs mod binary_range; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod chunk; pub mod chunk_op; pub mod error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod util; diff --git a/merk/src/proofs/encoding.rs b/merk/src/proofs/encoding.rs index eb1c055b2..5996e388b 100644 --- a/merk/src/proofs/encoding.rs +++ b/merk/src/proofs/encoding.rs @@ -1,19 +1,19 @@ //! Proofs encoding -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use std::io::{Read, Write}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use ed::Terminated; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use ed::{Decode, Encode, Error as EdError}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use super::{Node, Op}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::{error::Error, tree::HASH_LENGTH, TreeFeatureType}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Encode for Op { fn encode_into(&self, dest: &mut W) -> ed::Result<()> { match self { @@ -178,7 +178,7 @@ impl Encode for Op { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Decode for Op { fn decode(mut input: R) -> ed::Result { let variant: u8 = Decode::decode(&mut input)?; @@ -352,11 +352,11 @@ impl Decode for Op { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Terminated for Op {} impl Op { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] fn encode_into(&self, dest: &mut W) -> Result<(), Error> { Encode::encode_into(self, dest).map_err(|e| match e { EdError::UnexpectedByte(byte) => Error::ProofCreationError(format!( @@ -368,12 +368,12 @@ impl Op { }) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] fn encoding_length(&self) -> usize { Encode::encoding_length(self).unwrap() } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Decode pub fn decode(bytes: &[u8]) -> Result { Decode::decode(bytes).map_err(|e| match e { @@ -387,7 +387,7 @@ impl Op { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Encode into pub fn encode_into<'a, T: Iterator>(ops: T, output: &mut Vec) { for op in ops { @@ -395,14 +395,14 @@ pub fn encode_into<'a, T: Iterator>(ops: T, output: &mut Vec) } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Decoder pub struct Decoder<'a> { offset: usize, bytes: &'a [u8], } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl<'a> Decoder<'a> { /// New decoder pub const fn new(proof_bytes: &'a [u8]) -> Self { @@ -413,7 +413,7 @@ impl<'a> Decoder<'a> { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl<'a> Iterator for Decoder<'a> { type Item = Result; @@ -431,7 +431,7 @@ impl<'a> Iterator for Decoder<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use super::super::{Node, Op}; diff --git a/merk/src/proofs/mod.rs b/merk/src/proofs/mod.rs index 45f4b2e9d..62ad2fdb8 100644 --- a/merk/src/proofs/mod.rs +++ b/merk/src/proofs/mod.rs @@ -1,27 +1,27 @@ //! Merk proofs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod chunk; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod encoding; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod query; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod tree; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use encoding::encode_into; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use encoding::Decoder; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use query::Query; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use tree::Tree; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::{tree::CryptoHash, TreeFeatureType}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// A proof operator, executed to verify the data in a Merkle proof. #[derive(Debug, Clone, PartialEq, Eq)] pub enum Op { @@ -54,7 +54,7 @@ pub enum Op { ChildInverted, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// A selected piece of data about a single tree node, to be contained in a /// `Push` operator in a proof. #[derive(Clone, Debug, PartialEq, Eq)] @@ -86,7 +86,7 @@ pub enum Node { use std::fmt; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for Node { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let node_string = match self { diff --git a/merk/src/proofs/query/common_path.rs b/merk/src/proofs/query/common_path.rs index b9c9453dd..b660da0fb 100644 --- a/merk/src/proofs/query/common_path.rs +++ b/merk/src/proofs/query/common_path.rs @@ -1,6 +1,6 @@ use crate::proofs::query::Path; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// CommonPathResult is the result of trying to find the common path between two /// paths #[derive(Debug, Default, Clone, PartialEq, Eq)] diff --git a/merk/src/proofs/query/insert.rs b/merk/src/proofs/query/insert.rs index 02b87866f..8b76fd6eb 100644 --- a/merk/src/proofs/query/insert.rs +++ b/merk/src/proofs/query/insert.rs @@ -2,7 +2,7 @@ use std::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToIncl use crate::proofs::{query::query_item::QueryItem, Query}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Query { /// Adds an individual key to the query, so that its value (or its absence) /// in the tree will be included in the resulting proof. diff --git a/merk/src/proofs/query/map.rs b/merk/src/proofs/query/map.rs index 9e741ceab..8c3b56525 100644 --- a/merk/src/proofs/query/map.rs +++ b/merk/src/proofs/query/map.rs @@ -2,30 +2,30 @@ #![allow(unstable_name_collisions)] -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{ collections::{btree_map, btree_map::Iter, BTreeMap}, ops::{Bound, RangeBounds}, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::super::Node; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::error::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// `MapBuilder` allows a consumer to construct a `Map` by inserting the nodes /// contained in a proof, in key-order. pub struct MapBuilder(Map); -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for MapBuilder { fn default() -> Self { MapBuilder::new() } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl MapBuilder { /// Creates a new `MapBuilder` with an empty internal `Map`. pub fn new() -> Self { @@ -65,7 +65,7 @@ impl MapBuilder { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// `Map` stores data extracted from a proof (which has already been verified /// against a known root hash), and allows a consumer to access the data by /// looking up individual keys using the `get` method, or iterating over ranges @@ -76,7 +76,7 @@ pub struct Map { right_edge: bool, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Map { /// Gets the value for a single key, or `None` if the key was proven to not /// exist in the tree. If the proof does not include the data and also does @@ -120,7 +120,7 @@ impl Map { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Returns `None` for `Bound::Unbounded`, or the inner key value for /// `Bound::Included` and `Bound::Excluded`. fn bound_to_inner(bound: Bound) -> Option { @@ -130,7 +130,7 @@ fn bound_to_inner(bound: Bound) -> Option { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] fn bound_to_vec(bound: Bound<&&[u8]>) -> Bound> { match bound { Bound::Unbounded => Bound::Unbounded, @@ -139,7 +139,7 @@ fn bound_to_vec(bound: Bound<&&[u8]>) -> Bound> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] fn bounds_to_vec<'a, R: RangeBounds<&'a [u8]>>(bounds: R) -> impl RangeBounds> { ( bound_to_vec(bounds.start_bound()), @@ -147,7 +147,7 @@ fn bounds_to_vec<'a, R: RangeBounds<&'a [u8]>>(bounds: R) -> impl RangeBounds { prev_key: Option>, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> Range<'a> { /// Returns an error if the proof does not properly prove the end of the /// range. @@ -195,7 +195,7 @@ impl<'a> Range<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> Iterator for Range<'a> { type Item = Result<(&'a [u8], &'a [u8]), Error>; @@ -236,7 +236,7 @@ impl<'a> Iterator for Range<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use super::*; diff --git a/merk/src/proofs/query/merge.rs b/merk/src/proofs/query/merge.rs index f44dd66b7..56af059f9 100644 --- a/merk/src/proofs/query/merge.rs +++ b/merk/src/proofs/query/merge.rs @@ -238,7 +238,7 @@ impl SubqueryBranch { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Query { fn merge_default_subquerys_branch_subquery( &mut self, diff --git a/merk/src/proofs/query/mod.rs b/merk/src/proofs/query/mod.rs index b15431532..bd33d4b09 100644 --- a/merk/src/proofs/query/mod.rs +++ b/merk/src/proofs/query/mod.rs @@ -1,73 +1,73 @@ //! Query proofs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod map; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod common_path; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod insert; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod merge; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod query_item; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod verify; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::cmp::Ordering; use std::{collections::HashSet, fmt, ops::RangeFull}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use bincode::{ enc::write::Writer, error::{DecodeError, EncodeError}, BorrowDecode, Decode, Encode, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{cost_return_on_error, CostContext, CostResult, CostsExt, OperationCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::version::GroveVersion; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use indexmap::IndexMap; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use map::*; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use query_item::intersect::QueryItemIntersectionResult; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use query_item::QueryItem; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use verify::ProofAbsenceLimit; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use verify::VerifyOptions; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use verify::{ProofVerificationResult, ProvedKeyOptionalValue, ProvedKeyValue}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use {super::Op, std::collections::LinkedList}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::Node; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::error::Error; use crate::proofs::hex_to_ascii; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::tree::{Fetch, Link, RefWalker}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for a path. pub type Path = Vec>; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for a Key. pub type Key = Vec; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Type alias for path-key common pattern. pub type PathKey = (Path, Key); -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Subquery branch @@ -108,7 +108,7 @@ impl SubqueryBranch { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// `Query` represents one or more keys or ranges of keys, which can be used to /// resolve a proof which will include all the requested values. #[derive(Debug, Default, Clone, PartialEq)] @@ -124,7 +124,7 @@ pub struct Query { pub left_to_right: bool, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Encode for Query { fn encode(&self, encoder: &mut E) -> Result<(), EncodeError> { // Encode the items vector @@ -158,7 +158,7 @@ impl Encode for Query { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Decode for Query { fn decode(decoder: &mut D) -> Result { // Decode the items vector @@ -193,7 +193,7 @@ impl Decode for Query { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl<'de> BorrowDecode<'de> for Query { fn borrow_decode>( decoder: &mut D, @@ -230,7 +230,7 @@ impl<'de> BorrowDecode<'de> for Query { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for SubqueryBranch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "SubqueryBranch {{ ")?; @@ -255,7 +255,7 @@ impl fmt::Display for SubqueryBranch { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for Query { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "Query {{")?; @@ -281,7 +281,7 @@ impl fmt::Display for Query { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Query { /// Creates a new query which contains no items. pub fn new() -> Self { @@ -650,7 +650,7 @@ impl Query { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl> From> for Query { fn from(other: Vec) -> Self { let items = other.into_iter().map(Into::into).collect(); @@ -666,14 +666,14 @@ impl> From> for Query { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl From for Vec { fn from(q: Query) -> Self { q.into_iter().collect() } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl IntoIterator for Query { type IntoIter = as IntoIterator>::IntoIter; type Item = QueryItem; @@ -683,11 +683,11 @@ impl IntoIterator for Query { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Link { /// Creates a `Node::Hash` from this link. Panics if the link is of variant /// `Link::Modified` since its hash has not yet been computed. - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] const fn to_hash_node(&self) -> Node { let hash = match self { Link::Reference { hash, .. } => hash, @@ -701,7 +701,7 @@ impl Link { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a, S> RefWalker<'a, S> where S: Fetch + Sized + Clone, @@ -758,7 +758,7 @@ where /// right edge, respectively. /// /// TODO: Generalize logic and get code to better represent logic - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub(crate) fn create_proof( &mut self, query: &[QueryItem], @@ -965,7 +965,7 @@ where /// Similar to `create_proof`. Recurses into the child on the given side and /// generates a proof for the queried keys. - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] fn create_child_proof( &mut self, left: bool, @@ -1001,7 +1001,7 @@ where } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[allow(deprecated)] #[cfg(test)] mod test { diff --git a/merk/src/proofs/query/query_item/merge.rs b/merk/src/proofs/query/query_item/merge.rs index 9f36cb54d..4799fc9ae 100644 --- a/merk/src/proofs/query/query_item/merge.rs +++ b/merk/src/proofs/query/query_item/merge.rs @@ -5,7 +5,7 @@ use std::{ use crate::proofs::query::query_item::QueryItem; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl QueryItem { pub(crate) fn merge(&self, other: &Self) -> Self { let lower_unbounded = self.lower_unbounded() || other.lower_unbounded(); diff --git a/merk/src/proofs/query/query_item/mod.rs b/merk/src/proofs/query/query_item/mod.rs index d4f7fd8b8..65c6640fd 100644 --- a/merk/src/proofs/query/query_item/mod.rs +++ b/merk/src/proofs/query/query_item/mod.rs @@ -1,5 +1,5 @@ pub mod intersect; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod merge; use std::{ @@ -11,20 +11,20 @@ use std::{ }; use bincode::{enc::write::Writer, error::DecodeError, BorrowDecode, Decode, Encode}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{CostContext, CostsExt, OperationCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::RawIterator; #[cfg(feature = "serde")] use serde::de::VariantAccess; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::error::Error; use crate::proofs::hex_to_ascii; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// A `QueryItem` represents a key or range of keys to be included in a proof. #[derive(Clone, Debug)] pub enum QueryItem { @@ -183,7 +183,7 @@ impl<'de> Deserialize<'de> for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Encode for QueryItem { fn encode( &self, @@ -238,7 +238,7 @@ impl Encode for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Decode for QueryItem { fn decode(decoder: &mut D) -> Result { let variant_id = u8::decode(decoder)?; @@ -294,7 +294,7 @@ impl Decode for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl<'de> BorrowDecode<'de> for QueryItem { fn borrow_decode>( decoder: &mut D, @@ -352,7 +352,7 @@ impl<'de> BorrowDecode<'de> for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for QueryItem { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -396,7 +396,7 @@ impl fmt::Display for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Hash for QueryItem { fn hash(&self, state: &mut H) { self.enum_value().hash(state); @@ -405,7 +405,7 @@ impl Hash for QueryItem { } impl QueryItem { - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn processing_footprint(&self) -> u32 { match self { QueryItem::Key(key) => key.len() as u32, @@ -417,7 +417,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn lower_bound(&self) -> (Option<&[u8]>, bool) { match self { QueryItem::Key(key) => (Some(key.as_slice()), false), @@ -433,7 +433,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub const fn lower_unbounded(&self) -> bool { match self { QueryItem::Key(_) => false, @@ -449,7 +449,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn upper_bound(&self) -> (Option<&[u8]>, bool) { match self { QueryItem::Key(key) => (Some(key.as_slice()), true), @@ -465,7 +465,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub const fn upper_unbounded(&self) -> bool { match self { QueryItem::Key(_) => false, @@ -481,7 +481,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn contains(&self, key: &[u8]) -> bool { let (lower_bound, lower_bound_non_inclusive) = self.lower_bound(); let (upper_bound, upper_bound_inclusive) = self.upper_bound(); @@ -493,7 +493,7 @@ impl QueryItem { || (Some(key) == upper_bound && upper_bound_inclusive)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] fn enum_value(&self) -> u32 { match self { QueryItem::Key(_) => 0, @@ -509,7 +509,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] fn value_hash(&self, state: &mut H) { match self { QueryItem::Key(key) => key.hash(state), @@ -525,17 +525,17 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub const fn is_key(&self) -> bool { matches!(self, QueryItem::Key(_)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub const fn is_range(&self) -> bool { !matches!(self, QueryItem::Key(_)) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub const fn is_unbounded_range(&self) -> bool { !matches!( self, @@ -543,7 +543,7 @@ impl QueryItem { ) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn keys(&self) -> Result>, Error> { match self { QueryItem::Key(key) => Ok(vec![key.clone()]), @@ -593,7 +593,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn keys_consume(self) -> Result>, Error> { match self { QueryItem::Key(key) => Ok(vec![key]), @@ -643,7 +643,7 @@ impl QueryItem { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub fn seek_for_iter( &self, iter: &mut I, @@ -743,7 +743,7 @@ impl QueryItem { } } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn compare(a: &[u8], b: &[u8]) -> cmp::Ordering { for (ai, bi) in a.iter().zip(b.iter()) { match ai.cmp(bi) { @@ -756,7 +756,7 @@ impl QueryItem { a.len().cmp(&b.len()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub fn iter_is_valid_for_type( &self, iter: &I, @@ -833,30 +833,30 @@ impl QueryItem { is_valid.wrap_with_cost(cost) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn collides_with(&self, other: &Self) -> bool { self.intersect(other).in_both.is_some() } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl PartialEq for QueryItem { fn eq(&self, other: &Self) -> bool { self.cmp(other) == Ordering::Equal } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl PartialEq<&[u8]> for QueryItem { fn eq(&self, other: &&[u8]) -> bool { matches!(self.partial_cmp(other), Some(Ordering::Equal)) } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Eq for QueryItem {} -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Ord for QueryItem { fn cmp(&self, other: &Self) -> Ordering { let self_as_range_set = self.to_range_set(); @@ -874,14 +874,14 @@ impl Ord for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl PartialOrd for QueryItem { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl PartialOrd<&[u8]> for QueryItem { fn partial_cmp(&self, other: &&[u8]) -> Option { let other = Self::Key(other.to_vec()); @@ -889,14 +889,14 @@ impl PartialOrd<&[u8]> for QueryItem { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl From> for QueryItem { fn from(key: Vec) -> Self { Self::Key(key) } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use crate::proofs::query::query_item::QueryItem; diff --git a/merk/src/proofs/query/verify.rs b/merk/src/proofs/query/verify.rs index 726145cfb..de41006d0 100644 --- a/merk/src/proofs/query/verify.rs +++ b/merk/src/proofs/query/verify.rs @@ -1,10 +1,10 @@ -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::collections::LinkedList; use std::fmt; use grovedb_costs::{cost_return_on_error, CostResult, CostsExt, OperationCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::proofs::{ query::{Map, MapBuilder}, Op, @@ -16,10 +16,10 @@ use crate::{ CryptoHash as MerkHash, CryptoHash, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub type ProofAbsenceLimit = (LinkedList, (bool, bool), Option); -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Verify proof against expected hash #[deprecated] #[allow(unused)] @@ -65,7 +65,7 @@ impl Default for VerifyOptions { } impl Query { - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Verifies the encoded proof with the given query /// /// Every key in `keys` is checked to either have a key/value pair in the @@ -361,7 +361,7 @@ impl Query { .wrap_with_cost(cost) } - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] /// Verifies the encoded proof with the given query and expected hash pub fn verify_proof( &self, @@ -385,7 +385,7 @@ impl Query { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(PartialEq, Eq, Debug)] /// Proved key-value pub struct ProvedKeyOptionalValue { @@ -422,7 +422,7 @@ impl TryFrom for ProvedKeyValue { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for ProvedKeyOptionalValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let key_string = if self.key.len() == 1 && self.key[0] < b"0"[0] { @@ -444,7 +444,7 @@ impl fmt::Display for ProvedKeyOptionalValue { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(PartialEq, Eq, Debug)] /// Proved key-value pub struct ProvedKeyValue { @@ -456,7 +456,7 @@ pub struct ProvedKeyValue { pub proof: CryptoHash, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for ProvedKeyValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -469,7 +469,7 @@ impl fmt::Display for ProvedKeyValue { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(PartialEq, Eq, Debug)] /// Proof verification result pub struct ProofVerificationResult { @@ -479,7 +479,7 @@ pub struct ProofVerificationResult { pub limit: Option, } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl fmt::Display for ProofVerificationResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "ProofVerificationResult {{")?; diff --git a/merk/src/proofs/tree.rs b/merk/src/proofs/tree.rs index 16655a6dc..4b2037fe4 100644 --- a/merk/src/proofs/tree.rs +++ b/merk/src/proofs/tree.rs @@ -1,28 +1,28 @@ //! Tree proofs -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::fmt::Debug; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostContext, CostResult, CostsExt, OperationCost, }; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use super::{Node, Op}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::tree::{combine_hash, kv_digest_to_kv_hash, kv_hash, node_hash, value_hash, NULL_HASH}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::{error::Error, tree::CryptoHash}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ proofs::chunk::chunk::{LEFT, RIGHT}, Link, TreeFeatureType::SummedMerkNode, }; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Contains a tree's child node and its hash. The hash can always be assumed to /// be up-to-date. #[derive(Debug)] @@ -34,7 +34,7 @@ pub struct Child { } impl Child { - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub fn as_link(&self) -> Link { let (key, sum) = match &self.tree.node { Node::KV(key, _) | Node::KVValueHash(key, ..) => (key.as_slice(), None), @@ -63,7 +63,7 @@ impl Child { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// A binary tree data structure used to represent a select subset of a tree /// when verifying Merkle proofs. #[derive(Debug)] @@ -80,7 +80,7 @@ pub struct Tree { pub child_heights: (usize, usize), } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl From for Tree { /// Creates a childless tree with the target node as the `node` field. fn from(node: Node) -> Self { @@ -94,7 +94,7 @@ impl From for Tree { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl PartialEq for Tree { /// Checks equality for the root hashes of the two trees. fn eq(&self, other: &Self) -> bool { @@ -104,7 +104,7 @@ impl PartialEq for Tree { impl Tree { /// Gets or computes the hash for this tree node. - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub fn hash(&self) -> CostContext { fn compute_hash(tree: &Tree, kv_hash: CryptoHash) -> CostContext { node_hash(&kv_hash, &tree.child_hash(true), &tree.child_hash(false)) @@ -138,14 +138,14 @@ impl Tree { /// Creates an iterator that yields the in-order traversal of the nodes at /// the given depth. - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub fn layer(&self, depth: usize) -> LayerIter { LayerIter::new(self, depth) } /// Consumes the `Tree` and does an in-order traversal over all the nodes in /// the tree, calling `visit_node` for each. - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub fn visit_nodes(mut self, visit_node: &mut F) { if let Some(child) = self.left.take() { child.tree.visit_nodes(visit_node); @@ -161,7 +161,7 @@ impl Tree { /// Does an in-order traversal over references to all the nodes in the tree, /// calling `visit_node` for each. - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub fn visit_refs Result<(), Error>>( &self, visit_node: &mut F, @@ -178,7 +178,7 @@ impl Tree { Ok(()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] /// Does an in-order traversal over references to all the nodes in the tree, /// calling `visit_node` for each with the current traversal path. pub fn visit_refs_track_traversal_and_parent< @@ -215,7 +215,7 @@ impl Tree { } /// Returns an immutable reference to the child on the given side, if any. - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub const fn child(&self, left: bool) -> Option<&Child> { if left { self.left.as_ref() @@ -225,7 +225,7 @@ impl Tree { } /// Returns a mutable reference to the child on the given side, if any. - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub(crate) fn child_mut(&mut self, left: bool) -> &mut Option { if left { &mut self.left @@ -236,7 +236,7 @@ impl Tree { /// Attaches the child to the `Tree`'s given side. Panics if there is /// already a child attached to this side. - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] pub(crate) fn attach(&mut self, left: bool, child: Self) -> CostResult<(), Error> { let mut cost = OperationCost::default(); @@ -266,7 +266,7 @@ impl Tree { /// Returns the already-computed hash for this tree node's child on the /// given side, if any. If there is no child, returns the null hash /// (zero-filled). - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] #[inline] const fn child_hash(&self, left: bool) -> CryptoHash { match self.child(left) { @@ -277,12 +277,12 @@ impl Tree { /// Consumes the tree node, calculates its hash, and returns a `Node::Hash` /// variant. - #[cfg(any(feature = "full", feature = "verify"))] + #[cfg(any(feature = "minimal", feature = "verify"))] fn into_hash(self) -> CostContext { self.hash().map(|hash| Node::Hash(hash).into()) } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub(crate) fn key(&self) -> &[u8] { match self.node { Node::KV(ref key, _) @@ -293,7 +293,7 @@ impl Tree { } } - #[cfg(feature = "full")] + #[cfg(feature = "minimal")] pub(crate) fn sum(&self) -> Option { match self.node { Node::KVValueHashFeatureType(.., feature_type) => match feature_type { @@ -305,7 +305,7 @@ impl Tree { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// `LayerIter` iterates over the nodes in a `Tree` at a given depth. Nodes are /// visited in order. pub struct LayerIter<'a> { @@ -313,7 +313,7 @@ pub struct LayerIter<'a> { depth: usize, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> LayerIter<'a> { /// Creates a new `LayerIter` that iterates over `tree` at the given depth. fn new(tree: &'a Tree, depth: usize) -> Self { @@ -327,7 +327,7 @@ impl<'a> LayerIter<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> Iterator for LayerIter<'a> { type Item = &'a Tree; @@ -349,7 +349,7 @@ impl<'a> Iterator for LayerIter<'a> { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Executes a proof by stepping through its operators, modifying the /// verification stack as it goes. The resulting stack item is returned. /// @@ -523,7 +523,7 @@ where Ok(tree).wrap_with_cost(cost) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use super::{super::*, Tree as ProofTree, *}; diff --git a/merk/src/test_utils/temp_merk.rs b/merk/src/test_utils/temp_merk.rs index 69e5b5550..9a059712f 100644 --- a/merk/src/test_utils/temp_merk.rs +++ b/merk/src/test_utils/temp_merk.rs @@ -28,12 +28,12 @@ //! Temp merk test utils -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::ops::{Deref, DerefMut}; use grovedb_path::SubtreePath; use grovedb_storage::StorageBatch; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::{ rocksdb_storage::{test_utils::TempStorage, PrefixedRocksDbStorageContext}, Storage, @@ -41,10 +41,10 @@ use grovedb_storage::{ use grovedb_version::version::GroveVersion; use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::Merk; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Wraps a Merk instance and deletes it from disk it once it goes out of scope. pub struct TempMerk { storage: &'static TempStorage, @@ -52,7 +52,7 @@ pub struct TempMerk { merk: Merk>, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TempMerk { /// Opens a `TempMerk` at the given file path, creating a new one if it /// does not exist. @@ -102,7 +102,7 @@ impl TempMerk { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Drop for TempMerk { fn drop(&mut self) { unsafe { @@ -113,14 +113,14 @@ impl Drop for TempMerk { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Default for TempMerk { fn default() -> Self { Self::new(GroveVersion::latest()) } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Deref for TempMerk { type Target = Merk>; @@ -129,7 +129,7 @@ impl Deref for TempMerk { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl DerefMut for TempMerk { fn deref_mut(&mut self) -> &mut Merk> { &mut self.merk diff --git a/merk/src/tree/commit.rs b/merk/src/tree/commit.rs index 31b0df5c6..6390d6e31 100644 --- a/merk/src/tree/commit.rs +++ b/merk/src/tree/commit.rs @@ -1,11 +1,11 @@ //! Merk tree commit -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::TreeNode; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::error::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// To be used when committing a tree (writing it to a store after applying the /// changes). pub trait Commit { @@ -26,12 +26,12 @@ pub trait Commit { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// A `Commit` implementation which does not write to a store and does not prune /// any nodes from the Tree. Useful when only keeping a tree in memory. pub struct NoopCommit {} -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Commit for NoopCommit { fn write( &mut self, diff --git a/merk/src/tree/debug.rs b/merk/src/tree/debug.rs index 3e88c60b9..d6e3738a4 100644 --- a/merk/src/tree/debug.rs +++ b/merk/src/tree/debug.rs @@ -1,40 +1,13 @@ -// 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. - //! Merk tree debug use std::fmt::{Debug, Formatter, Result}; +#[cfg(feature = "colored")] use colored::Colorize; use super::{Link, TreeNode}; -#[cfg(feature = "full")] +#[cfg(all(feature = "minimal", feature = "colored"))] impl Debug for TreeNode { // TODO: unwraps should be results that bubble up fn fmt(&self, f: &mut Formatter) -> Result { @@ -55,7 +28,6 @@ impl Debug for TreeNode { } let depth = stack.len(); - if depth > 0 { // draw ancestor's vertical lines for (low, high) in stack.iter().take(depth - 1) { @@ -127,3 +99,80 @@ impl Debug for TreeNode { writeln!(f) } } + +#[cfg(all(feature = "minimal", not(feature = "colored")))] +impl Debug for TreeNode { + fn fmt(&self, f: &mut Formatter) -> Result { + fn traverse( + f: &mut Formatter, + cursor: &TreeNode, + stack: &mut Vec<(Vec, Vec)>, + left: bool, + ) { + if let Some(child_link) = cursor.link(true) { + stack.push((child_link.key().to_vec(), cursor.key().to_vec())); + if let Some(child_tree) = child_link.tree() { + traverse(f, child_tree, stack, true); + } else { + traverse_pruned(f, child_link, stack, true); + } + stack.pop(); + } + + let depth = stack.len(); + if depth > 0 { + for (low, high) in stack.iter().take(depth - 1) { + let draw_line = cursor.key() > low && cursor.key() < high; + write!(f, "{}", if draw_line { " │ " } else { " " }).unwrap(); + } + } + + let prefix = if depth == 0 { + "" + } else if left { + " ┌-" + } else { + " └-" + }; + writeln!(f, "{}{:?}", prefix, cursor.key()).unwrap(); + + if let Some(child_link) = cursor.link(false) { + stack.push((cursor.key().to_vec(), child_link.key().to_vec())); + if let Some(child_tree) = child_link.tree() { + traverse(f, child_tree, stack, false); + } else { + traverse_pruned(f, child_link, stack, false); + } + stack.pop(); + } + } + + fn traverse_pruned( + f: &mut Formatter, + link: &Link, + stack: &mut [(Vec, Vec)], + left: bool, + ) { + let depth = stack.len(); + if depth > 0 { + for (low, high) in stack.iter().take(depth - 1) { + let draw_line = link.key() > low && link.key() < high; + write!(f, "{}", if draw_line { " │ " } else { " " }).unwrap(); + } + } + + let prefix = if depth == 0 { + "" + } else if left { + " ┌-" + } else { + " └-" + }; + writeln!(f, "{}{:?}", prefix, link.key()).unwrap(); + } + + let mut stack = vec![]; + traverse(f, self, &mut stack, false); + writeln!(f) + } +} diff --git a/merk/src/tree/encoding.rs b/merk/src/tree/encoding.rs index cd10937d9..1e1a3beaf 100644 --- a/merk/src/tree/encoding.rs +++ b/merk/src/tree/encoding.rs @@ -1,26 +1,26 @@ //! Merk tree encoding -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use ed::{Decode, Encode}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_storage::StorageContext; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::TreeNode; use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ error::{Error, Error::EdError}, tree::TreeNodeInner, Error::StorageError, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeNode { /// Decode given bytes and set as Tree fields. Set key to value of given /// key. @@ -67,7 +67,7 @@ impl TreeNode { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeNode { #[inline] /// Encode @@ -143,7 +143,7 @@ impl TreeNode { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod tests { use super::{super::Link, *}; diff --git a/merk/src/tree/fuzz_tests.rs b/merk/src/tree/fuzz_tests.rs index eb026f56a..cb74280a0 100644 --- a/merk/src/tree/fuzz_tests.rs +++ b/merk/src/tree/fuzz_tests.rs @@ -2,21 +2,21 @@ #![cfg(tests)] -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{cell::RefCell, collections::BTreeMap}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use rand::prelude::*; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{test_utils::*, tree::*}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] const ITERATIONS: usize = 2_000; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] type Map = BTreeMap, Vec>; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[test] fn fuzz() { let mut rng = thread_rng(); @@ -27,19 +27,19 @@ fn fuzz() { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[test] fn fuzz_17391518417409062786() { fuzz_case(17391518417409062786); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[test] fn fuzz_396148930387069749() { fuzz_case(396148930387069749); } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] fn fuzz_case(seed: u64, using_sum_trees: bool) { let mut rng: SmallRng = SeedableRng::seed_from_u64(seed); let initial_size = (rng.gen::() % 10) + 1; @@ -72,7 +72,7 @@ fn fuzz_case(seed: u64, using_sum_trees: bool) { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] fn make_batch(maybe_tree: Option<&TreeNode>, size: u64, seed: u64) -> Vec { let rng: RefCell = RefCell::new(SeedableRng::seed_from_u64(seed)); let mut batch = Vec::with_capacity(size as usize); @@ -133,7 +133,7 @@ fn make_batch(maybe_tree: Option<&TreeNode>, size: u64, seed: u64) -> Vec, map: &Map) { if map.is_empty() { assert!(maybe_tree.is_none(), "expected tree to be None"); diff --git a/merk/src/tree/hash.rs b/merk/src/tree/hash.rs index e23566a9a..8e6647d4d 100644 --- a/merk/src/tree/hash.rs +++ b/merk/src/tree/hash.rs @@ -1,38 +1,38 @@ //! Merk tree hash -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use grovedb_costs::{CostContext, CostsExt, OperationCost}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use integer_encoding::*; /// The length of a `Hash` (in bytes). -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub const HASH_LENGTH: usize = 32; /// 2x length of a `Hash` -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const HASH_LENGTH_X2: usize = 64; /// Length of a `Hash` as u32 -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const HASH_LENGTH_U32: u32 = 32; /// 2x length of a `Hash` as u32 -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const HASH_LENGTH_U32_X2: u32 = 64; /// Hash block size -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const HASH_BLOCK_SIZE: usize = 64; /// Hash block size as u32 -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub const HASH_BLOCK_SIZE_U32: u32 = 64; /// A zero-filled `Hash`. -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub const NULL_HASH: CryptoHash = [0; HASH_LENGTH]; /// A cryptographic hash digest. -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub type CryptoHash = [u8; HASH_LENGTH]; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Hashes a value pub fn value_hash(value: &[u8]) -> CostContext { // TODO: make generic to allow other hashers @@ -53,7 +53,7 @@ pub fn value_hash(value: &[u8]) -> CostContext { }) } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Hashes a key/value pair. /// /// The result is Hash(key_len, key, Hash(value_len, value)) @@ -80,7 +80,7 @@ pub fn kv_hash(key: &[u8], value: &[u8]) -> CostContext { hash.wrap_with_cost(cost) } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Computes the kv hash given a kv digest pub fn kv_digest_to_kv_hash(key: &[u8], value_hash: &CryptoHash) -> CostContext { let mut hasher = blake3::Hasher::new(); @@ -102,7 +102,7 @@ pub fn kv_digest_to_kv_hash(key: &[u8], value_hash: &CryptoHash) -> CostContext< }) } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Hashes a node based on the hash of its key/value pair, the hash of its left /// child (if any), and the hash of its right child (if any). pub fn node_hash( @@ -128,7 +128,7 @@ pub fn node_hash( }) } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] /// Combines two hash values into one pub fn combine_hash(hash_one: &CryptoHash, hash_two: &CryptoHash) -> CostContext { let mut hasher = blake3::Hasher::new(); diff --git a/merk/src/tree/iter.rs b/merk/src/tree/iter.rs index 03cca6eaf..96c04e29b 100644 --- a/merk/src/tree/iter.rs +++ b/merk/src/tree/iter.rs @@ -1,9 +1,9 @@ //! Merk tree iterator -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::TreeNode; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// An entry stored on an `Iter`'s stack, containing a reference to a `Tree`, /// and its traversal state. /// @@ -14,7 +14,7 @@ struct StackItem<'a> { traversed: (bool, bool, bool), } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> StackItem<'a> { /// Creates a new `StackItem` for the given tree. The `traversed` state will /// be `false` since the children and self have not been visited yet, but @@ -39,14 +39,14 @@ impl<'a> StackItem<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// An iterator which yields the key/value pairs of the tree, in order, skipping /// any parts of the tree which are pruned (not currently retained in memory). pub struct Iter<'a> { stack: Vec>, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> Iter<'a> { /// Creates a new iterator for the given tree. pub fn new(tree: &'a TreeNode) -> Self { @@ -55,7 +55,7 @@ impl<'a> Iter<'a> { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> TreeNode { /// Creates an iterator which yields `(key, value)` tuples for all of the /// tree's nodes which are retained in memory (skipping pruned subtrees). @@ -64,7 +64,7 @@ impl<'a> TreeNode { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a> Iterator for Iter<'a> { type Item = (Vec, Vec); diff --git a/merk/src/tree/kv.rs b/merk/src/tree/kv.rs index f4a0e2248..7de707dbe 100644 --- a/merk/src/tree/kv.rs +++ b/merk/src/tree/kv.rs @@ -1,19 +1,19 @@ //! Merk tree key-values -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::io::{Read, Write}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use ed::{Decode, Encode, Result, Terminated}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{CostContext, CostsExt, OperationCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::hash::{CryptoHash, HASH_LENGTH, NULL_HASH}; use crate::tree::kv::ValueDefinedCostType::{LayeredValueDefinedCost, SpecializedValueDefinedCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{ tree::{ hash::{combine_hash, kv_digest_to_kv_hash, value_hash, HASH_LENGTH_X2}, @@ -28,7 +28,7 @@ use crate::{ // field and value field. /// It is possible to predefine the value cost of specific types -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[derive(Clone, Debug, PartialEq, Eq)] pub enum ValueDefinedCostType { /// There is a predefined cost used to remove the root key from a sub tree @@ -40,7 +40,7 @@ pub enum ValueDefinedCostType { SpecializedValueDefinedCost(u32), } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Contains a key/value pair, and the hash of the key/value pair. #[derive(Clone, Debug, PartialEq, Eq)] pub struct KV { @@ -54,7 +54,7 @@ pub struct KV { pub(super) value_hash: CryptoHash, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl KV { /// Creates a new `KV` with the given key and value and computes its hash. #[inline] @@ -456,7 +456,7 @@ impl KV { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] // TODO: Fix encoding and decoding of kv impl Encode for KV { #[inline] @@ -475,7 +475,7 @@ impl Encode for KV { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Decode for KV { #[inline] fn decode(input: R) -> Result { @@ -506,10 +506,10 @@ impl Decode for KV { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Terminated for KV {} -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use super::*; diff --git a/merk/src/tree/link.rs b/merk/src/tree/link.rs index f445dd11b..6c372d870 100644 --- a/merk/src/tree/link.rs +++ b/merk/src/tree/link.rs @@ -1,21 +1,21 @@ //! Merk tree link -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::io::{Read, Write}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use ed::{Decode, Encode, Result, Terminated}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::{VarInt, VarIntReader, VarIntWriter}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::{hash::CryptoHash, TreeNode}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::HASH_LENGTH_U32; // TODO: optimize memory footprint -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Represents a reference to a child tree node. Links may or may not contain /// the child's `Tree` instance (storing its key if not). #[derive(Clone, Debug, PartialEq)] @@ -75,7 +75,7 @@ pub enum Link { }, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Link { /// Creates a `Link::Modified` from the given `Tree`. #[inline] @@ -295,7 +295,7 @@ impl Link { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Encode for Link { #[inline] fn encode_into(&self, out: &mut W) -> Result<()> { @@ -376,7 +376,7 @@ impl Encode for Link { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Link { #[inline] fn default_reference() -> Self { @@ -389,7 +389,7 @@ impl Link { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Decode for Link { #[inline] fn decode(input: R) -> Result { @@ -440,10 +440,10 @@ impl Decode for Link { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Terminated for Link {} -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[inline] fn read_u8(mut input: R) -> Result { let mut length = [0]; @@ -451,7 +451,7 @@ fn read_u8(mut input: R) -> Result { Ok(length[0]) } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use super::{ diff --git a/merk/src/tree/mod.rs b/merk/src/tree/mod.rs index 91eebf52a..e87865a2c 100644 --- a/merk/src/tree/mod.rs +++ b/merk/src/tree/mod.rs @@ -1,38 +1,38 @@ //! Merk trees -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod commit; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod debug; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod encoding; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod fuzz_tests; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub mod hash; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod iter; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod just_in_time_value_update; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub mod kv; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod link; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod ops; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] mod tree_feature_type; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod walk; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::cmp::{max, Ordering}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use commit::{Commit, NoopCommit}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use ed::{Decode, Encode, Terminated}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_default, cost_return_on_error_no_add, storage_cost::{ @@ -42,40 +42,40 @@ use grovedb_costs::{ }, CostContext, CostResult, CostsExt, OperationCost, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_version::version::GroveVersion; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use hash::{ combine_hash, kv_digest_to_kv_hash, kv_hash, node_hash, value_hash, CryptoHash, HASH_LENGTH, NULL_HASH, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use hash::{HASH_BLOCK_SIZE, HASH_BLOCK_SIZE_U32, HASH_LENGTH_U32, HASH_LENGTH_U32_X2}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use kv::KV; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use link::Link; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use ops::{AuxMerkBatch, BatchEntry, MerkBatch, Op, PanicSource}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] pub use tree_feature_type::TreeFeatureType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use walk::{Fetch, RefWalker, Walker}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::tree::hash::HASH_LENGTH_X2; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::tree::kv::ValueDefinedCostType::{LayeredValueDefinedCost, SpecializedValueDefinedCost}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{error::Error, Error::Overflow}; // TODO: remove need for `TreeInner`, and just use `Box` receiver for // relevant methods -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// The fields of the `Tree` type, stored on the heap. #[derive(Clone, Encode, Decode, Debug, PartialEq)] pub struct TreeNodeInner { @@ -84,7 +84,7 @@ pub struct TreeNodeInner { pub(crate) kv: KV, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeNodeInner { /// Get the value as owned of the key value struct pub fn value_as_owned(self) -> Vec { @@ -107,10 +107,10 @@ impl TreeNodeInner { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Terminated for Box {} -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// A binary AVL tree data structure, with Merkle hashes. /// /// Trees' inner fields are stored on the heap so that nodes can recursively @@ -123,7 +123,7 @@ pub struct TreeNode { pub(crate) known_storage_cost: Option, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeNode { /// Creates a new `Tree` with the given key and value, and no children. /// @@ -1027,7 +1027,7 @@ impl TreeNode { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Convert side (left or right) to string pub const fn side_to_str(left: bool) -> &'static str { if left { @@ -1037,7 +1037,7 @@ pub const fn side_to_str(left: bool) -> &'static str { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { diff --git a/merk/src/tree/ops.rs b/merk/src/tree/ops.rs index 3e10b2c81..66fcb7164 100644 --- a/merk/src/tree/ops.rs +++ b/merk/src/tree/ops.rs @@ -1,12 +1,12 @@ //! Merk tree ops -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use std::{ collections::{BTreeSet, LinkedList}, fmt, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{ cost_return_on_error, cost_return_on_error_no_add, storage_cost::{ @@ -17,21 +17,21 @@ use grovedb_costs::{ CostContext, CostResult, CostsExt, OperationCost, }; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use integer_encoding::VarInt; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use Op::*; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::{Fetch, Link, TreeNode, Walker}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{error::Error, tree::tree_feature_type::TreeFeatureType, CryptoHash, HASH_LENGTH_U32}; use crate::{ merk::KeyUpdates, tree::kv::{ValueDefinedCostType, ValueDefinedCostType::SpecializedValueDefinedCost}, }; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// An operation to be applied to a key in the store. #[derive(PartialEq, Clone, Eq)] pub enum Op { @@ -70,7 +70,7 @@ pub enum Op { DeleteLayeredMaybeSpecialized, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl fmt::Debug for Op { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!( @@ -115,13 +115,13 @@ pub type MerkBatch = [BatchEntry]; /// and unique. pub type AuxMerkBatch = [AuxBatchEntry]; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// A source of data which panics when called. Useful when creating a store /// which always keeps the state in memory. #[derive(Clone)] pub struct PanicSource {} -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Fetch for PanicSource { fn fetch( &self, @@ -135,7 +135,7 @@ impl Fetch for PanicSource { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Walker where S: Fetch + Sized + Clone, @@ -1045,7 +1045,7 @@ where } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use super::*; diff --git a/merk/src/tree/tree_feature_type.rs b/merk/src/tree/tree_feature_type.rs index c47fb0d60..bb815dcaf 100644 --- a/merk/src/tree/tree_feature_type.rs +++ b/merk/src/tree/tree_feature_type.rs @@ -1,19 +1,19 @@ //! Merk tree feature type -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use std::io::{Read, Write}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use ed::Terminated; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use ed::{Decode, Encode}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use integer_encoding::{VarInt, VarIntReader, VarIntWriter}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] use crate::tree::tree_feature_type::TreeFeatureType::{BasicMerkNode, SummedMerkNode}; -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] #[derive(Copy, Clone, PartialEq, Eq, Debug)] /// Basic or summed pub enum TreeFeatureType { @@ -23,7 +23,7 @@ pub enum TreeFeatureType { SummedMerkNode(i64), } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl TreeFeatureType { #[inline] /// Get length of encoded SummedMerk @@ -50,7 +50,7 @@ impl TreeFeatureType { } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Terminated for TreeFeatureType {} impl Encode for TreeFeatureType { @@ -83,7 +83,7 @@ impl Encode for TreeFeatureType { } } -#[cfg(any(feature = "full", feature = "verify"))] +#[cfg(any(feature = "minimal", feature = "verify"))] impl Decode for TreeFeatureType { #[inline] fn decode(mut input: R) -> ed::Result { diff --git a/merk/src/tree/walk/fetch.rs b/merk/src/tree/walk/fetch.rs index 0ba657f2e..5b43d9fe4 100644 --- a/merk/src/tree/walk/fetch.rs +++ b/merk/src/tree/walk/fetch.rs @@ -1,17 +1,17 @@ //! Walk -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::CostResult; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::super::{Link, TreeNode}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::error::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// A source of data to be used by the tree when encountering a pruned node. /// This typically means fetching the tree node from a backing store by its key, /// but could also implement an in-memory cache for example. diff --git a/merk/src/tree/walk/mod.rs b/merk/src/tree/walk/mod.rs index 4b67bb609..3a1998c96 100644 --- a/merk/src/tree/walk/mod.rs +++ b/merk/src/tree/walk/mod.rs @@ -1,29 +1,29 @@ //! Merk tree walk -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod fetch; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] mod ref_walker; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use fetch::Fetch; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{cost_return_on_error, CostResult, CostsExt, OperationCost}; use grovedb_costs::{ cost_return_on_error_no_add, storage_cost::{removal::StorageRemovedBytes, StorageCost}, }; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] pub use ref_walker::RefWalker; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::{Link, TreeNode}; use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::{owner::Owner, tree::tree_feature_type::TreeFeatureType, CryptoHash, Error}; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Allows traversal of a `Tree`, fetching from the given source when traversing /// to a pruned node, detaching children as they are traversed. pub struct Walker @@ -34,7 +34,7 @@ where source: S, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl Walker where S: Fetch + Sized + Clone, @@ -386,7 +386,7 @@ where } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl From> for TreeNode where S: Fetch + Sized + Clone, @@ -396,7 +396,7 @@ where } } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] #[cfg(test)] mod test { use grovedb_costs::CostsExt; diff --git a/merk/src/tree/walk/ref_walker.rs b/merk/src/tree/walk/ref_walker.rs index 189bc7eeb..7f363ba4e 100644 --- a/merk/src/tree/walk/ref_walker.rs +++ b/merk/src/tree/walk/ref_walker.rs @@ -1,19 +1,19 @@ //! Merk reference walker -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use grovedb_costs::{CostResult, CostsExt, OperationCost}; use grovedb_version::version::GroveVersion; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use super::{ super::{Link, TreeNode}, Fetch, }; use crate::tree::kv::ValueDefinedCostType; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] use crate::Error; -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] /// Allows read-only traversal of a `Tree`, fetching from the given source when /// traversing to a pruned node. The fetched nodes are then retained in memory /// until they (possibly) get pruned on the next commit. @@ -28,7 +28,7 @@ where source: S, } -#[cfg(feature = "full")] +#[cfg(feature = "minimal")] impl<'a, S> RefWalker<'a, S> where S: Fetch + Sized + Clone, diff --git a/storage/Cargo.toml b/storage/Cargo.toml index 654ddb350..a493aa53f 100644 --- a/storage/Cargo.toml +++ b/storage/Cargo.toml @@ -18,10 +18,10 @@ hex = "0.4.3" integer-encoding = { version = "4.0.0", optional = true } lazy_static = { version = "1.4.0", optional = true } num_cpus = { version = "1.16.0", optional = true } -rocksdb = { version = "0.22.0", optional = true } +rocksdb = { version = "0.23.0", optional = true } strum = { version = "0.26.2", features = ["derive"] } tempfile = { version = "3.10.1", optional = true } -thiserror = "1.0.59" +thiserror = "2.0.11" [features] rocksdb_storage = ["rocksdb", "num_cpus", "lazy_static", "tempfile", "blake3", "integer-encoding"] diff --git a/visualize/Cargo.toml b/visualize/Cargo.toml index 4530f1daf..e7a0d2b84 100644 --- a/visualize/Cargo.toml +++ b/visualize/Cargo.toml @@ -10,4 +10,4 @@ repository = "https://github.com/dashpay/grovedb" [dependencies] hex = "0.4.3" -itertools = "0.12.1" +itertools = "0.14.0" From eb2e1673139d273b01c8ab59828d073cdc140ca6 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 14 Jan 2025 15:55:02 +0700 Subject: [PATCH 2/5] downgraded axum --- grovedb/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grovedb/Cargo.toml b/grovedb/Cargo.toml index 14df208b7..71b1e1b67 100644 --- a/grovedb/Cargo.toml +++ b/grovedb/Cargo.toml @@ -19,7 +19,7 @@ grovedb-storage = { version = "2.1.0", path = "../storage", optional = true } grovedb-version = { version = "2.1.0", path = "../grovedb-version" } grovedb-visualize = { version = "2.1.0", path = "../visualize", optional = true } -axum = { version = "0.8.1", features = ["macros"], optional = true } +axum = { version = "0.7.9", features = ["macros"], optional = true } bincode = { version = "2.0.0-rc.3" } blake3 = "1.5.5" hex = "0.4.3" From f6d3c2346f10f468510a7e49515248918472a6aa Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 14 Jan 2025 15:57:25 +0700 Subject: [PATCH 3/5] downgraded axum --- grovedb/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grovedb/Cargo.toml b/grovedb/Cargo.toml index 71b1e1b67..e45f4c659 100644 --- a/grovedb/Cargo.toml +++ b/grovedb/Cargo.toml @@ -19,7 +19,7 @@ grovedb-storage = { version = "2.1.0", path = "../storage", optional = true } grovedb-version = { version = "2.1.0", path = "../grovedb-version" } grovedb-visualize = { version = "2.1.0", path = "../visualize", optional = true } -axum = { version = "0.7.9", features = ["macros"], optional = true } +axum = { version = "0.7.5", features = ["macros"], optional = true } bincode = { version = "2.0.0-rc.3" } blake3 = "1.5.5" hex = "0.4.3" From 5000049a25ae2a11da9f18a4f6bfb2c60df2a0fe Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 14 Jan 2025 16:06:01 +0700 Subject: [PATCH 4/5] downgraded axum --- grovedb/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grovedb/Cargo.toml b/grovedb/Cargo.toml index e45f4c659..de616e55e 100644 --- a/grovedb/Cargo.toml +++ b/grovedb/Cargo.toml @@ -19,7 +19,7 @@ grovedb-storage = { version = "2.1.0", path = "../storage", optional = true } grovedb-version = { version = "2.1.0", path = "../grovedb-version" } grovedb-visualize = { version = "2.1.0", path = "../visualize", optional = true } -axum = { version = "0.7.5", features = ["macros"], optional = true } +axum = { version = "=0.7.5", features = ["macros"], optional = true } bincode = { version = "2.0.0-rc.3" } blake3 = "1.5.5" hex = "0.4.3" From cac043e42853e5ae018cca9285b58616c749ad55 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 14 Jan 2025 16:22:51 +0700 Subject: [PATCH 5/5] a fix --- grovedb/src/operations/delete/average_case.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grovedb/src/operations/delete/average_case.rs b/grovedb/src/operations/delete/average_case.rs index c60de1014..b828ce0c6 100644 --- a/grovedb/src/operations/delete/average_case.rs +++ b/grovedb/src/operations/delete/average_case.rs @@ -32,7 +32,7 @@ impl GroveDb { key: &KeyInfo, stop_path_height: Option, validate: bool, - estimated_layer_info: IntMap, + estimated_layer_info: IntMap, grove_version: &GroveVersion, ) -> CostResult, Error> { check_grovedb_v0_with_cost!( @@ -69,7 +69,7 @@ impl GroveDb { ) = cost_return_on_error_no_add!( &cost, if height == path_len - 1 { - if let Some(layer_info) = estimated_layer_info.get(height as u64) { + if let Some(layer_info) = estimated_layer_info.get(height) { let estimated_value_len = cost_return_on_error_no_add!( &cost, layer_info @@ -94,7 +94,7 @@ impl GroveDb { } else { let (last_key, smaller_path) = used_path.split_last().unwrap(); used_path = smaller_path; - if let Some(layer_info) = estimated_layer_info.get(height as u64) { + if let Some(layer_info) = estimated_layer_info.get(height) { let estimated_value_len = cost_return_on_error_no_add!( &cost, layer_info