Repository navigation
fix(batch)!: size aggregating trees as themselves in average-case batch estimates (GROVE_V4) - #1018
Conversation
…ch estimates (GROVE_V4) A level of an average-case batch estimate reported an aggregate to the op writing its tree element in the parent only for indexed trees. A sum, big sum, count or count-sum tree inserted in the same batch as its contents became an InsertTreeWithRootHash carrying no aggregate, so the estimator sized it as a plain tree and the estimate's added bytes came in below the applied ones by the aggregate's bytes (9 per axis, 16 for a big sum). A replaced root key of such a tree was under-sized the same way in replaced bytes. From GROVE_V4 every level reports the aggregate of its own tree type, through the new operations.average_case.average_case_propagated_aggregate_kind slot (0 in V1..V3, 1 in V4). Older grove versions estimate exactly as before. BREAKING CHANGE: GroveDBOperationsAverageCaseVersions gains the public field average_case_propagated_aggregate_kind. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No actionable issue remains from this review; the PR is mergeable after normal checks. Pre-merge checks |
|
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit b51f2b3) · triage: low · Phase 2 only (no Phase 1 for this repository) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1018 +/- ##
===========================================
- Coverage 93.22% 93.22% -0.01%
===========================================
Files 340 340
Lines 107628 107777 +149
===========================================
+ Hits 100338 100475 +137
- Misses 7290 7302 +12
🚀 New features to boost your workflow:
|
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
Independently verified the complete diff at b51f2b3 and the aggregate conversion, batch propagation, and parent-element sizing paths; no in-scope defects were found. The new feature slot preserves V1–V3 behavior, enables corrected aggregate sizing only in V4, and retains accumulated costs on unsupported-version errors; regression tests cover all eight aggregating Merk tree types, historical sizing, and version rejection. Validation was static only: the supplied exact-head CI snapshot reports passing test shards, formatting, linting, security audit, and coverage checks, with PR Hygiene still pending.
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.1-sol(effort low) — The change is a small, contained correction to aggregate-type propagation in average-case cost estimates with an explicit version gate and regression tests, not a large or intricate change to a critical surface. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort medium); agentphase2-reviewer
|
Bots are done — your move: post |
… (PV14) dashpay/grovedb#1018 merged (99c0f4fb6f), followed by #1019 and #1020, which size inserted sum items (and replaced ItemWithSumItem) at the fixed width the apply charges in the average- and worst-case estimators, from GROVE_V4. Pin develop's head; the lockfile changes only the grovedb rev. PV14 note 93 now covers the sum item sizing too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tinuation-dd8070 develop's #1021 landed this branch's two GROVE_V4 fixes (same-batch reference prediction and the Unchanged re-measure) with later review fixes of its own, so those now exist once, in develop's form. What this branch adds over develop is the settlement mode: - the prediction keeps develop's runs_value_update and post-apply check; a settling batch uses version 1 on every grove version - CHANGELOG: the fixes stay under develop's entries in 6.1.0, and the settlement entries move to Unreleased - same_batch_reference_prediction_tests is develop's file with the settling modes added, its helpers shared with settle_test_support - the option-off estimate pins are retaken from develop at 0ea327d: 18 of the 66 latest-version rows moved with #1018..#1020 and none of the 66 grove v3 rows did - a settled tree's lookup comment says why it is still needed after #1018 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Basic explanation
What this does: GroveDB can estimate what a batch of writes will cost without running it. Sum trees and count trees store a few more bytes than plain trees (their running total). When a batch creates one of these trees together with its first contents, the estimate counted it as a plain tree and missed those bytes. From
GROVE_V4, the estimate counts the tree as what it is. Older grove versions estimate exactly as before.Value: Dash Platform uses this estimate as the fee bound a write is checked against before it is applied, so the estimate must be at least the real cost. For a document under a summable index, the estimate was 18 bytes (486,000 credits) below the real storage fee; with this change it is not below it. Count, count-sum and big-sum trees get the same correction.
Risks: Low. Only
GROVE_V4estimates change, and they only go up: by 9 bytes per aggregate axis (16 for a big sum) for each such tree created with its contents, and by the same amount in replaced bytes when such a tree's root key is replaced. Applied costs, stored data and proofs do not change. Code that buildsGroveDBOperationsAverageCaseVersionsby hand must set one new field.Issue being fixed or feature implemented
In an average-case batch estimate, each level hands an aggregate up to the op that writes its tree element in the parent, and that op sizes the element by the aggregate's tree type.
AverageCaseTreeCacheKnownPaths::execute_ops_on_pathreturned an aggregate only for the three indexed tree types andNoAggregateDatafor every other one. When a tree is inserted in the same batch as its contents, the insert becomesInsertTreeWithRootHash { aggregate_data, .. }, andaverage_case_merk_insert_treesizes it withaggregate_data.parent_tree_type().cost_size():TREE_COST_SIZE(3) instead ofSUM_TREE_COST_SIZE(12),COUNT_SUM_TREE_COST_SIZE(21) and so on. The apply sizes the same element by its real type, so the estimate'sadded_bytescame in below the applied ones.Seen from Dash Platform: inserting one document into a type with an index
{ properties: [tier], summable: "weight" }(u8andi8properties) creates aSumTreevalue tree and aSumTree[0]bucket in the same batch as the document's reference.Before (
GROVE_V4, Platform protocol version 14):After:
In GroveDB alone, one batch inserting an empty tree and one item inside it (
added_bytes):Before this change
GROVE_V4gave theGROVE_V3figures.What was done?
execute_ops_on_path(average case) returnsAggregateData::from(tree_type.empty_tree_feature_type())under the new slot value 1: the aggregate kind of the level's own tree type (values zero, only the variant drives sizing). The three indexed types map exactly as before; non-Merk trees and plain trees still reportNoAggregateData.GroveDBOperationsAverageCaseVersions::average_case_propagated_aggregate_kind:0inGROVE_V1..GROVE_V3(indexed trees only, the old behaviour),1inGROVE_V4. Any other value is aVersionError.ReplaceTreeRootKey, whichaverage_case_merk_replace_treev1 sizes byreplacing_tree_type: replacing a sum tree's root key now charges its 12 bytes, not 3, as replaced bytes.WorstCaseLayerInformationcarries no tree type to derive an aggregate from.CHANGELOG.mdentry and aGROVE_V4module doc entry.Not in this PR: inserting a
SumItemis estimated by its serialized length (3 bytes for a small value) while the apply charges the fixedSUM_ITEM_COST_SIZE(11), so an estimate can still come in under an apply that writes sum items. The new tests use plain items as children to keep that case separate.How Has This Been Tested?
New tests in
grovedb/src/batch/estimated_costs/average_case_costs.rs, each over all eight aggregating Merk tree types (sum, big sum, count, count-sum, provable count, provable count-sum, provable sum, provable count provable sum):test_batch_aggregate_tree_created_with_contents_average_case_added_bytes_match_actual: one batch creating the tree with an item inside; theGROVE_V4estimate'sadded_bytesequal the applied ones. With the slot at 0 this fails for every type.test_batch_aggregate_tree_created_with_contents_average_case_pinned_before_v4:GROVE_V4minusGROVE_V3estimatedadded_bytesis exactly the aggregate bytes (9 / 16 / 18), so V1..V3 output is unchanged.test_average_case_propagated_aggregate_kind_unknown_version_is_refused: slot value 9 is aVersionError.test_batch_root_one_sum_item_replace_op_average_case_costsnow pins both versions:GROVE_V3keeps 5,594 replaced bytes,GROVE_V4gives 5,603 (the replaced sum tree root key, +9).Runs:
cargo test -p grovedb --lib: 3,610 passed, 8 ignored, run before the unknown-version test was added and the bound test tightened to equality; those four tests pass on the final commit.cargo test -p grovedb-version: 56 passed.cargo clippy -p grovedb -p grovedb-version --all-targets -- -D warningsandcargo fmt --all -- --checkare clean.Breaking Changes
GroveDBOperationsAverageCaseVersionsgains a public field,average_case_propagated_aggregate_kind, so code that builds the struct by hand must set it. Estimates underGROVE_V1..GROVE_V3do not change;GROVE_V4average-case estimates rise as described above.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
b51f2b3/self-reviewedWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit