Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jan 8, 2025
1 parent 1483e18 commit cac1b37
Show file tree
Hide file tree
Showing 51 changed files with 1,022 additions and 449 deletions.
11 changes: 10 additions & 1 deletion grovedb-version/src/version/merk_versions.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
use versioned_feature_core::FeatureVersion;

#[derive(Clone, Debug, Default)]
pub struct MerkVersions {}
pub struct MerkVersions {
pub average_case_costs: MerkAverageCaseCostsVersions,
}

#[derive(Clone, Debug, Default)]
pub struct MerkAverageCaseCostsVersions {
pub add_average_case_merk_propagate: FeatureVersion,
}
8 changes: 7 additions & 1 deletion grovedb-version/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod v2;
pub use versioned_feature_core::*;

use crate::version::{
grovedb_versions::GroveDBVersions, merk_versions::MerkVersions, v1::GROVE_V1, v2::GROVE_V2
grovedb_versions::GroveDBVersions, merk_versions::MerkVersions, v1::GROVE_V1, v2::GROVE_V2,
};

#[derive(Clone, Debug, Default)]
Expand All @@ -17,6 +17,12 @@ pub struct GroveVersion {
}

impl GroveVersion {
pub fn first<'a>() -> &'a Self {
GROVE_VERSIONS
.first()
.expect("expected to have a platform version")
}

pub fn latest<'a>() -> &'a Self {
GROVE_VERSIONS
.last()
Expand Down
8 changes: 6 additions & 2 deletions grovedb-version/src/version/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::version::{
GroveDBOperationsWorstCaseVersions, GroveDBPathQueryMethodVersions,
GroveDBReplicationVersions, GroveDBVersions,
},
merk_versions::MerkVersions,
merk_versions::{MerkAverageCaseCostsVersions, MerkVersions},
GroveVersion,
};

Expand Down Expand Up @@ -184,5 +184,9 @@ pub const GROVE_V1: GroveVersion = GroveVersion {
apply_chunk: 0,
},
},
merk_versions: MerkVersions {},
merk_versions: MerkVersions {
average_case_costs: MerkAverageCaseCostsVersions {
add_average_case_merk_propagate: 0,
},
},
};
10 changes: 7 additions & 3 deletions grovedb-version/src/version/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::version::{
GroveDBOperationsWorstCaseVersions, GroveDBPathQueryMethodVersions,
GroveDBReplicationVersions, GroveDBVersions,
},
merk_versions::MerkVersions,
merk_versions::{MerkAverageCaseCostsVersions, MerkVersions},
GroveVersion,
};

Expand Down Expand Up @@ -144,7 +144,7 @@ pub const GROVE_V2: GroveVersion = GroveVersion {
},
average_case: GroveDBOperationsAverageCaseVersions {
add_average_case_get_merk_at_path: 0,
average_case_merk_replace_tree: 1, //changed
average_case_merk_replace_tree: 1, // changed
average_case_merk_insert_tree: 0,
average_case_merk_delete_tree: 0,
average_case_merk_insert_element: 0,
Expand Down Expand Up @@ -184,5 +184,9 @@ pub const GROVE_V2: GroveVersion = GroveVersion {
apply_chunk: 0,
},
},
merk_versions: MerkVersions {},
merk_versions: MerkVersions {
average_case_costs: MerkAverageCaseCostsVersions {
add_average_case_merk_propagate: 1,
},
},
};
6 changes: 3 additions & 3 deletions grovedb/src/batch/batch_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ where
}
Ok(())
}
GroveOp::RefreshReference { .. }
| GroveOp::Delete
| GroveOp::DeleteTree(_) => Ok(()),
GroveOp::RefreshReference { .. } | GroveOp::Delete | GroveOp::DeleteTree(_) => {
Ok(())
}
GroveOp::ReplaceTreeRootKey { .. } | GroveOp::InsertTreeWithRootHash { .. } => {
Err(Error::InvalidBatchOperation(
"replace and insert tree hash are internal operations only",
Expand Down
93 changes: 50 additions & 43 deletions grovedb/src/batch/estimated_costs/average_case_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ use std::{
use grovedb_costs::{
cost_return_on_error, cost_return_on_error_no_add, CostResult, CostsExt, OperationCost,
};
use grovedb_merk::RootHashKeyAndAggregateData;
#[cfg(feature = "full")]
use grovedb_merk::{
estimated_costs::average_case_costs::{average_case_merk_propagate, EstimatedLayerInformation},
IsSumTree,

Check warning on line 16 in grovedb/src/batch/estimated_costs/average_case_costs.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `IsSumTree`

warning: unused import: `IsSumTree` --> grovedb/src/batch/estimated_costs/average_case_costs.rs:16:5 | 16 | IsSumTree, | ^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
};
use grovedb_merk::{merk::TreeType, tree::AggregateData, RootHashKeyAndAggregateData};
#[cfg(feature = "full")]
use grovedb_storage::rocksdb_storage::RocksDbStorage;
use grovedb_version::version::GroveVersion;
#[cfg(feature = "full")]
use itertools::Itertools;
use grovedb_merk::merk::TreeType;

use crate::Element;
#[cfg(feature = "full")]
use crate::{
Expand Down Expand Up @@ -53,28 +53,32 @@ impl GroveOp {
}
};
match self {
GroveOp::ReplaceTreeRootKey { aggregate_data, .. } => GroveDb::average_case_merk_replace_tree(
key,
layer_element_estimates,
aggregate_data,
propagate,
grove_version,
),
GroveOp::InsertTreeWithRootHash { flags, sum, .. } => {
GroveDb::average_case_merk_insert_tree(
GroveOp::ReplaceTreeRootKey { aggregate_data, .. } => {
GroveDb::average_case_merk_replace_tree(
key,
flags,
sum.is_some(),
in_tree_using_sums,
propagate_if_input(),
layer_element_estimates,
aggregate_data.parent_tree_type(),
propagate,
grove_version,
)
}
GroveOp::InsertTreeWithRootHash {
flags,
aggregate_data,
..
} => GroveDb::average_case_merk_insert_tree(
key,
flags,
aggregate_data.parent_tree_type(),
in_tree_type,
propagate_if_input(),
grove_version,
),
GroveOp::InsertOrReplace { element } | GroveOp::InsertOnly { element } => {
GroveDb::average_case_merk_insert_element(
key,
element,
in_tree_using_sums,
in_tree_type,
propagate_if_input(),
grove_version,
)
Expand All @@ -91,14 +95,14 @@ impl GroveOp {
*max_reference_hop,
flags.clone(),
),
in_tree_using_sums,
in_tree_type,
propagate_if_input(),
grove_version,
),
GroveOp::Replace { element } => GroveDb::average_case_merk_replace_element(
key,
element,
in_tree_using_sums,
in_tree_type,
propagate_if_input(),
grove_version,
),
Expand All @@ -109,7 +113,7 @@ impl GroveOp {
key,
element,
*change_in_bytes,
in_tree_using_sums,
in_tree_type,
propagate_if_input(),
grove_version,
),
Expand All @@ -121,7 +125,7 @@ impl GroveOp {
),
GroveOp::DeleteTree(tree_type) => GroveDb::average_case_merk_delete_tree(
key,
tree_type,
*tree_type,
layer_element_estimates,
propagate,
grove_version,
Expand Down Expand Up @@ -231,12 +235,11 @@ impl<G, SR> TreeCache<G, SR> for AverageCaseTreeCacheKnownPaths {
&mut cost,
path,
layer_should_be_empty,
layer_info.is_sum_tree,
layer_info.tree_type,
grove_version,
)
);
self.cached_merks
.insert(path.clone(), layer_info.is_sum_tree);
self.cached_merks.insert(path.clone(), layer_info.tree_type);
}

for (key, op) in ops_at_path_by_key.into_iter() {
Expand All @@ -248,9 +251,10 @@ impl<G, SR> TreeCache<G, SR> for AverageCaseTreeCacheKnownPaths {

cost_return_on_error!(
&mut cost,
average_case_merk_propagate(layer_element_estimates).map_err(Error::MerkError)
average_case_merk_propagate(layer_element_estimates, grove_version)
.map_err(Error::MerkError)
);
Ok(([0u8; 32], None, None)).wrap_with_cost(cost)
Ok(([0u8; 32], None, AggregateData::NoAggregateData)).wrap_with_cost(cost)
}

fn update_base_merk_root_key(
Expand All @@ -272,12 +276,12 @@ impl<G, SR> TreeCache<G, SR> for AverageCaseTreeCacheKnownPaths {
estimated_layer_info
.estimated_layer_count
.estimated_to_be_empty(),
estimated_layer_info.is_sum_tree,
estimated_layer_info.tree_type,
grove_version
)
);
self.cached_merks
.insert(base_path, estimated_layer_info.is_sum_tree);
.insert(base_path, estimated_layer_info.tree_type);
}
}
Ok(()).wrap_with_cost(cost)
Expand All @@ -293,11 +297,14 @@ mod tests {
storage_cost::{removal::StorageRemovedBytes::NoStorageRemoval, StorageCost},
OperationCost,
};
use grovedb_merk::estimated_costs::average_case_costs::{
EstimatedLayerCount::{ApproximateElements, EstimatedLevel, PotentiallyAtMaxElements},
EstimatedLayerInformation,
EstimatedLayerSizes::{AllItems, AllSubtrees},
EstimatedSumTrees::{NoSumTrees, SomeSumTrees},
use grovedb_merk::{
estimated_costs::average_case_costs::{
EstimatedLayerCount::{ApproximateElements, EstimatedLevel, PotentiallyAtMaxElements},
EstimatedLayerInformation,
EstimatedLayerSizes::{AllItems, AllSubtrees},
EstimatedSumTrees::{NoSumTrees, SomeSumTrees},
},
merk::TreeType,
};
use grovedb_version::version::GroveVersion;

Expand Down Expand Up @@ -325,7 +332,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: ApproximateElements(0),
estimated_layer_sizes: AllSubtrees(4, NoSumTrees, None),
},
Expand Down Expand Up @@ -394,15 +401,15 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(0, true),
estimated_layer_sizes: AllSubtrees(4, NoSumTrees, Some(3)),
},
);
paths.insert(
KeyInfoPath(vec![KeyInfo::KnownKey(b"key1".to_vec())]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(0, true),
estimated_layer_sizes: AllSubtrees(4, NoSumTrees, None),
},
Expand Down Expand Up @@ -461,7 +468,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(0, true),
estimated_layer_sizes: AllItems(4, 3, None),
},
Expand Down Expand Up @@ -534,7 +541,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(1, false),
estimated_layer_sizes: AllSubtrees(1, NoSumTrees, None),
},
Expand Down Expand Up @@ -620,7 +627,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(0, false),
estimated_layer_sizes: AllSubtrees(1, NoSumTrees, None),
},
Expand All @@ -629,7 +636,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![KeyInfo::KnownKey(b"0".to_vec())]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(0, true),
estimated_layer_sizes: AllSubtrees(4, NoSumTrees, None),
},
Expand Down Expand Up @@ -700,7 +707,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(1, false),
estimated_layer_sizes: AllSubtrees(
1,
Expand All @@ -715,7 +722,7 @@ mod tests {
paths.insert(
KeyInfoPath::from_known_owned_path(vec![vec![7]]),
EstimatedLayerInformation {
is_sum_tree: true,
tree_type: TreeType::SumTree,
estimated_layer_count: PotentiallyAtMaxElements,
estimated_layer_sizes: AllItems(32, 8, None),
},
Expand Down Expand Up @@ -778,7 +785,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(1, false),
estimated_layer_sizes: AllSubtrees(4, NoSumTrees, None),
},
Expand All @@ -787,7 +794,7 @@ mod tests {
paths.insert(
KeyInfoPath(vec![KeyInfo::KnownKey(b"0".to_vec())]),
EstimatedLayerInformation {
is_sum_tree: false,
tree_type: TreeType::NormalTree,
estimated_layer_count: EstimatedLevel(0, true),
estimated_layer_sizes: AllSubtrees(4, NoSumTrees, None),
},
Expand Down
Loading

0 comments on commit cac1b37

Please sign in to comment.