Repository navigation
fix(estimated-costs): price a private document store's creation as the apply does (GROVE_V4) - #1026
Conversation
…e apply does (GROVE_V4) Creating a PrivateDocumentStore checks that no store exists at the key (a store is write-once) and derives its empty root with two blake3 calls. The v1 average- and worst-case insert estimators priced a store like any other element, missing the check and the two hashes, and the worst case priced it as an item at its serialized size instead of the layered tree the apply writes. Both now charge the existence check (priced as InsertIfNotExists prices its own) and EMPTY_PRIVATE_DOCUMENT_STORE_STATE_ROOT_HASH_CALLS, and the worst case takes the layered arm for a store. Stores exist from GROVE_V4 only, so v0 is untouched; estimates of every other element do not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Add creation costs to insert estimates grovedb-private-document-store/src/lib.rs, grovedb-version/src/version/v4.rs, grovedb/src/estimated_costs/average_case_costs/merk_insert_element/*, grovedb/src/estimated_costs/worst_case_costs/merk_insert_element/*, CHANGELOG.md |
Average- and worst-case estimators include an existence check and two empty-root hash calls for private document store creation. The worst-case estimator uses layered-tree insertion sizing. Documentation describes the estimates and notes that they apply from Grove V4. |
Check estimate headroom grovedb/src/tests/append_family_cost_bound_tests.rs |
Tests compare average- and worst-case estimates with actual apply costs for private document store and plain-tree creation across four insert variants and two chunk powers. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Merge Risk: 
Minimal · up to b3686
-
No merge-blocking issue is established by the supplied evidence.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 7 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit b368636) · triage: low · Phase 2 only (no Phase 1 for this repository) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1026 +/- ##
===========================================
- Coverage 93.21% 93.21% -0.01%
===========================================
Files 356 356
Lines 108953 108970 +17
===========================================
+ Hits 101558 101573 +15
- Misses 7395 7397 +2
🚀 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)
Verified the Phase-2 review claims against head b368636 and found no actionable in-scope issues: both estimators account for the store-specific existence check and empty-root hashes, and worst-case pricing now uses the applied layered representation while historical v0 implementations remain unchanged. The regression test isolates store-specific costs across all four supported creation operations and two chunk powers. Validation was static only; current CI reports all three Ubuntu test shards, linting, formatting, security audit, and coverage checks passing, with PR Hygiene 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 diff makes small, contained estimator corrections for one element type, adds a hash-count constant and focused regression tests, and does not change applied storage or cryptographic behavior. - 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 |
…re's creation as its apply dashpay/grovedb#1026, the only GroveDB commit since 2128ea18: the v1 insert estimators charge a store's existence check and the two hashes deriving its empty root, and the worst case prices the store as a layered tree. Only the estimate of creating a store moves (339,400 credits of processing for a registration's store, 336,440 before); applied costs are unchanged. Cargo.lock changes only the GroveDB source lines. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tes on GROVE_V5, not V4 GroveDB 6.1.1 shipped GROVE_V4, and Dash Platform 5.0 runs it. #1027 (a store's position-range read and V1 range proofs) and #1026 (the insert estimators pricing a store's creation as the apply does) landed after 6.1.1 and changed V4 in place. They move to GROVE_V5: - private_document_store.get_range and range_proof are 0 in GROVE_V4, as 6.1.1 had no such read or proof, and 1 in GROVE_V5. At V4 the range read fails closed and a V1 proof neither carries nor accepts a lower layer under a store, as 6.1.1 refused them. - The average- and worst-case merk_insert_element v1 estimators are back to their 6.1.1 bytes. The store pricing is v2, selected by the new values average_case_merk_insert_element: 1 and worst_case_merk_insert_element: 1 in GROVE_V5. Average v2 runs v1 and adds the existence check and the empty root's two hashes; worst v2 prices a store as a layered tree with those charges and hands every other element to v1. Verifier hardening from #1027 that refuses a mistyped lower layer at every version stays as it is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tes on GROVE_V5, not V4 (#1029) GroveDB 6.1.1 shipped GROVE_V4, and Dash Platform 5.0 runs it. #1027 (a store's position-range read and V1 range proofs) and #1026 (the insert estimators pricing a store's creation as the apply does) landed after 6.1.1 and changed V4 in place. They move to GROVE_V5: - private_document_store.get_range and range_proof are 0 in GROVE_V4, as 6.1.1 had no such read or proof, and 1 in GROVE_V5. At V4 the range read fails closed and a V1 proof neither carries nor accepts a lower layer under a store, as 6.1.1 refused them. - The average- and worst-case merk_insert_element v1 estimators are back to their 6.1.1 bytes. The store pricing is v2, selected by the new values average_case_merk_insert_element: 1 and worst_case_merk_insert_element: 1 in GROVE_V5. Average v2 runs v1 and adds the existence check and the empty root's two hashes; worst v2 prices a store as a layered tree with those charges and hands every other element to v1. Verifier hardening from #1027 that refuses a mistyped lower layer at every version stays as it is. Co-authored-by: Claude Opus 5.5 <[email protected]>
Brings in #1026, #1027 and #1028. #1028 added GROVE_V5 identical to GROVE_V4, so this branch now builds on that shared version instead of adding its own: - v5.rs keeps this branch's three slots (element.path_query_push 2, path_query_methods.merge 2, path_query_methods.per_instance_query_offsets 1) under #1028's doc block, which records why changes after 6.1.1 go in V5. - grovedb-version tests keep local_offsets_only_change_the_v5_query_slots, which already compares V5 with V4 slot by slot, in place of #1028's v5_matches_v4_apart_from_protocol_version. - CHANGELOG keeps both sides; this branch's latest() entry replaces #1028's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Basic explanation
What this does: creating a
PrivateDocumentStorecosts more than creating a plain tree. Before writing it, GroveDB checks that no store already exists at the key (a store is write-once), and it derives the store's empty root with two blake3 calls. The insert estimators priced the store like any other element: the average case missed the check and the two hashes, and the worst case also priced the store as an item at its serialized size instead of the layered tree the apply writes, one hash fewer still. FromGROVE_V4, both estimators charge a store's creation as the apply does.Value: Dash Platform checks a write's fee against this estimate before applying it, so the estimate must not come in below the real cost. Platform's protocol version 15 creates a store when a contract registers a private document type (dashpay/platform#5703, whose review asked for this). A whole registration was still covered, because the batch estimate's propagation leaves headroom, but the store's own work was priced below its apply and only that headroom hid it.
Risks: low. Only the v1 insert estimators change (
GROVE_V4), only for a store element, and only upwards. Applied costs, stored data, proofs and every other element's estimate are unchanged. The change is in place inGROVE_V4: no released consumer creates a store yet (Dash Platform starts at its unreleased protocol version 15), so no recorded estimate changes.What a store's creation costs over a plain tree's, one insert at the root (
InsertOrReplace, chunk power 4), and what each estimator charged for it:Issue being fixed or feature implemented
Raised in the review of dashpay/platform#5703. At 2128ea1 the batch apply creates a store (
InsertOrReplace, itsDontCheckForBackwardsReferencestwin,InsertWithKnownToNotAlreadyExist,InsertIfNotExists) with an existence check (element_at_key_already_exists) andhash_node_calls += 2forempty_private_document_store_state_root, as the direct insert does.average_case_merk_insert_elementandworst_case_merk_insert_element(v1, whichGROVE_V4selects) charged neither, and the worst case's layered arm listed onlyTree,SumTree,BigSumTreeandCountTree, so a store fell to the item arm.What was done?
grovedb-private-document-store:EMPTY_PRIVATE_DOCUMENT_STORE_STATE_ROOT_HASH_CALLS(2), the blake3 callsempty_private_document_store_state_rootmakes.average_case_merk_insert_elementv1: for a store, the existence check priced as the batch estimator pricesInsertIfNotExists's (add_average_case_merk_has_valueat the element's serialized size) and the two hashes.worst_case_merk_insert_elementv1: a store takes the layered arm, then the existence check (add_worst_case_merk_has_valueatMERK_BIGGEST_VALUE_SIZE, asInsertIfNotExists's) and the two hashes.GROVE_V4only.GROVE_V4doc, andCHANGELOG.md.Not in this PR: the worst-case item arm still prices the other tree kinds it does not list (
CountSumTree, the provable trees, the append-only family) at their serialized size.How Has This Been Tested?
test_private_document_store_creation_is_estimated_as_its_apply_costs(inappend_family_cost_bound_tests): for each insert op a store can be created with, at chunk powers 4 and 11, both estimators must leave at least as much headroom over a store's creation as over a plain tree's, in seeks, added bytes, loaded bytes and hashes. Comparing against a tree isolates the store's own work from the propagation the batch estimate adds. It fails on 2128ea1 (the average-case estimate leaves 16 seeks of headroom over a store's creation, 17 over a tree's) and passes with the fix.cargo test -p grovedb --lib -- append_family_cost_bound estimated_costs private_document_store: 182 passed.cargo clippy -p grovedb -p grovedb-private-document-store -p grovedb-version --features grovedb/full,grovedb/estimated_costs --tests -- -D warnings.Breaking Changes
None in the API.
GROVE_V4estimates of a store's creation go up as described.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
b368636/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