Skip to content

fix(estimated-costs): price a private document store's creation as the apply does (GROVE_V4) - #1026

Merged
QuantumExplorer merged 1 commit into
developfrom
fix/private-document-store-create-estimate
Nov 1, 2026
Merged

QuantumExplorer merged 1 commit into
developfrom
fix/private-document-store-create-estimate

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: creating a PrivateDocumentStore costs 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. From GROVE_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 in GROVE_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:

store minus tree      seeks   hashes   added bytes
applied                 +1      +2        +14
average case before      0       0        +14
average case after      +1      +2        +14
worst case before        0      -1        +33
worst case after        +1      +2        +14

Issue being fixed or feature implemented

Raised in the review of dashpay/platform#5703. At 2128ea1 the batch apply creates a store (InsertOrReplace, its DontCheckForBackwardsReferences twin, InsertWithKnownToNotAlreadyExist, InsertIfNotExists) with an existence check (element_at_key_already_exists) and hash_node_calls += 2 for empty_private_document_store_state_root, as the direct insert does. average_case_merk_insert_element and worst_case_merk_insert_element (v1, which GROVE_V4 selects) charged neither, and the worst case's layered arm listed only Tree, SumTree, BigSumTree and CountTree, 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 calls empty_private_document_store_state_root makes.
  • average_case_merk_insert_element v1: for a store, the existence check priced as the batch estimator prices InsertIfNotExists's (add_average_case_merk_has_value at the element's serialized size) and the two hashes.
  • worst_case_merk_insert_element v1: a store takes the layered arm, then the existence check (add_worst_case_merk_has_value at MERK_BIGGEST_VALUE_SIZE, as InsertIfNotExists's) and the two hashes.
  • v0 is untouched: stores exist from GROVE_V4 only.
  • Module docs of both dispatchers and both v1 files, the GROVE_V4 doc, and CHANGELOG.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 (in append_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_V4 estimates of a store's creation go up as described.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · b368636

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Build green
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Improved average- and worst-case cost estimates for creating private document stores, accounting for the work involved in checking for an existing store and calculating its initial root.
    • Worst-case estimates now reflect the store’s layered-tree structure rather than sizing it solely by its serialized data.
    • These estimates apply to Grove V4; estimates for other elements, applied costs, stored data, and proofs are unchanged.

…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]>
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ec31b52-a516-42f7-9749-134709ecd39e
Commits

Reviewing files that changed from the base of the PR and between 2128ea1 and b368636.

Files selected for processing: 8
  • CHANGELOG.md
  • grovedb-private-document-store/src/lib.rs
  • grovedb-version/src/version/v4.rs
  • grovedb/src/estimated_costs/average_case_costs/merk_insert_element/mod.rs
  • grovedb/src/estimated_costs/average_case_costs/merk_insert_element/v1.rs
  • grovedb/src/estimated_costs/worst_case_costs/merk_insert_element/mod.rs
  • grovedb/src/estimated_costs/worst_case_costs/merk_insert_element/v1.rs
  • grovedb/src/tests/append_family_cost_bound_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The Grove V4 average- and worst-case insert estimators now include private document store creation costs. The worst-case estimator prices the store as a layered tree. Tests compare estimate headroom against actual apply costs.

Changes: Private document store estimates

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: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and specifically describes the main change: updating estimated costs so PrivateDocumentStore creation matches apply pricing for GROVE_V4.
Docstring Coverage Passed 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. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

Share

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw

thepastaclaw commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit b368636) · triage: low · Phase 2 only (no Phase 1 for this repository)

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.21%. Comparing base (2128ea1) to head (b368636).

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     
Components Coverage Δ
grovedb-core 91.59% <100.00%> (-0.01%) ⬇️
merk 94.18% <ø> (ø)
storage 91.68% <ø> (ø)
commitment-tree 95.62% <ø> (ø)
mmr 95.43% <ø> (ø)
bulk-append-tree 93.72% <ø> (ø)
element 97.39% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: low by gpt-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; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer

@github-actions

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 31, 2026
@QuantumExplorer
QuantumExplorer merged commit 7b8a258 into develop Nov 1, 2026
15 of 16 checks passed
@QuantumExplorer
QuantumExplorer deleted the fix/private-document-store-create-estimate branch November 1, 2026 07:35
QuantumExplorer added a commit to dashpay/platform that referenced this pull request Nov 1, 2026
…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]>
QuantumExplorer added a commit that referenced this pull request Nov 5, 2026
…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]>
QuantumExplorer added a commit that referenced this pull request Nov 5, 2026
…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]>
QuantumExplorer added a commit that referenced this pull request Nov 5, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants