Skip to content

feat(dpp): read which properties a document type has from its typed definition - #6439

Merged
QuantumExplorer merged 2 commits into
v5.2-devfrom
feat/definition-properties
Dec 2, 2026
Merged

QuantumExplorer merged 2 commits into
v5.2-devfrom
feat/definition-properties

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: DocumentType::try_from_definition builds a document type from its typed definition (#6433), with the type-level keywords already read from the definition's typed fields (#6437). This PR starts on the properties: which properties the type has, the order of their positions, the gap in positions registration refuses, and which properties are required (at any depth) or transient are now read from the typed fields. Each property itself (its type, its bounds, what it refers to) is still built from the schema the definition writes back for it, and follows in the next PRs.

Value: The walk over a document type's properties no longer reads JSON to learn which properties there are or in what order. It is the frame the next PRs fill in, one kind of property keyword at a time.

Risks: Low. Nothing carries a definition, so no state transition is validated differently. The one shipped function touched reads a schema by the same calls in the same order when it is given no definition.

Issue being fixed or feature implemented

Part of removing JSON schema from the protocol in 5.2, after #6422, #6433 and #6437.

What was done?

try_from_schema/typed_properties.rs, three functions that stand where parse_document_properties reads the schema:

  • in_position_order: the top-level properties in the order of their positions, those at the same position in the order they are declared, each with the schema the definition writes back for it. It orders them as Value::inner_optional_index_map orders the properties of a schema (a stable sort by position). A property without a position is refused with the error the reader of a schema gives.
  • required_fields: the names the type's required lists and those the required of each object lists, written object.member, to any depth. As for a schema, an object reached through a $ref or held by a list is not looked into.
  • transient_fields: the type's transient list.

Under full validation, the check that positions run from 0 without a gap compares the positions the definition declares.

In-place changes to shipped generations

parse_document_properties in try_from_schema/common/mod.rs, which every generation since 1 runs:

  • Three reads became match ctx.definition { Some(d) => typed reader, None => the call that was there }: the ordered properties, the required names and the transient names.
  • The position check reads the position from the definition when there is one, and otherwise makes the call it made (value.get_integer::<u32>("position")).

With no definition, which is every schema, the calls, their arguments and their order are unchanged.

How Has This Been Tested?

  • cargo test -p dpp --lib native_schema::tests: should_build_a_document_type_from_its_definition_as_from_its_schema builds document types from their definitions and from their schemas and holds the two to the same compiled document type or to a refusal both ways. It now also requires, each on a document type that builds: a required list at the root, on an object, and two objects down (a case added for it); a transient list; and properties declared out of the order of their positions.
  • Mutation checks, not committed: six single changes, each run against the test above, which fails on all six. The properties left in declared order; the root required dropped; an object's required member named without its object; a member two objects down named without the outer object; one transient name dropped; the position check always passing (built from its definition, refused from its schema: position field is not present).
  • cargo test -p dpp --lib class_methods::: 1,093 passed. cargo test -p dpp --test contract_corpus: 11 passed.
  • cargo clippy -p dpp --all-targets --all-features --locked -- --no-deps -D warnings, cargo check -p dpp --lib with no features, cargo fmt --all: clean.

Not run: the full dpp suite and the other crates.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 841f924

  • Bots — thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Build failed
  • 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
    • Document properties from typed definitions now follow their declared order.
    • Required fields are recognized within nested objects, and transient fields are preserved from the definition.
    • Property declarations and their positions are checked for consistency during full validation.
  • Tests
    • Added coverage for nested properties, required and transient declarations, and out-of-order positions.

…efinition

Building a document type from its definition reads from the definition's typed
fields which properties the type has and in what order (their positions), the
gap in positions registration refuses, and which properties are required, at
any depth, or transient (`try_from_schema/typed_properties.rs`).

Each property is still built from the schema the definition writes back for
it, which the typed order hands over beside the property's name.

`parse_document_properties` reads a schema by the calls it made, in the same
order, when it is given no definition.

The test that builds document types both ways requires a required list at the
root, on an object and two objects down, a transient list, and properties
declared out of the order of their positions, each on a document type that
builds. With the order, any of the lists or the position check changed, it
fails.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@QuantumExplorer QuantumExplorer added this to the v5.2.0 milestone Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Dec 1, 2026
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Document-type parsing now reads property order, positions, required fields, and transient fields from typed definitions when available. Schema-based parsing retains its schema readers. New tests cover nested properties and typed-keyword cases.

Changes: Typed property parsing

Layer / File(s) Summary
Typed property readers
packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_properties.rs
New helpers order definition properties by position and collect required fields, including nested names, and transient names.
Parser integration and validation
packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs, packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs, packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/native_schema/tests.rs, packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/v0/mod.rs
Parsing uses typed definition fields for property order, positions, required fields, and transient fields. Schema-based parsing keeps its existing readers. Tests add nested-property and typed-keyword cases, and module documentation describes the field sources.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • dashpay/platform#6113 — The PR checks definition-declared property positions during full validation, which relates to the issue’s DPP position-order validation gap.

Possibly related PRs

Suggested reviewers: thepastaclaw, shumkov

Merge Risk: Minimal · up to 841f9

Document types built from a typed definition now read property order, required fields and transient fields from that definition. Parsing from a schema with no definition keeps its previous behavior. No concrete defect was found, and the tests cover the equivalence between the two paths, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(dpp): read which properties a document type has from its typed definition" matches the main change. The PR adds typed-definition readers for top-level properties, their position order,…
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: Title check

Explanation

The title "feat(dpp): read which properties a document type has from its typed definition" matches the main change. The PR adds typed-definition readers for top-level properties, their position order, required fields, and transient fields in rs-dpp, and wires them into parse_document_properties when a definition is present. The title names the primary change and does not describe unrelated work. It does not mention position ordering, required fields, or transient fields, but it is not overly broad.

Finishing Touches

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2728f9a and 841f924.

Files selected for processing: 2

  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_properties.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.

@thepastaclaw

thepastaclaw commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress (commit 841f924) · live progress · priority

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

This change reads document-type property membership, ordering, required fields, and transient fields from the typed definition while preserving the existing schema-only path. No failed code checks are reported in the supplied CI snapshot, although the Kotlin build/tests, changed-package detection, PR Hygiene, and review checks are still in progress.

🟡 2 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.2-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 10: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — This is a contained Rust logic change to document-type construction and validation inputs, but it does not itself alter state-transition execution, funds, cryptography, networking, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_properties.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_properties.rs:30-34: Typed definition builds rescan the written property map for every top-level property
  Impact: Callers building wide typed definitions perform quadratic name comparisons before property compilation, with 5,050 comparisons for 100 properties.
  Wide definitions pay avoidable quadratic work before sorting: each iteration calls `written_property`, which linearly searches the same written property list from the beginning. The typed definition and its written schema preserve declaration order, so the entries can be paired in one pass while checking lengths and names, then stably sorted by position as they are now.

In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs:1019-1029: Typed parsing allocates duplicate property collections before compilation
  Impact: Every typed-definition parse clones all top-level property names into an `IndexMap` and allocates a separate position vector, including parses that do not perform full validation.
  The typed reader already returns each property name, position, and written schema together in a sorted vector, but this code immediately splits that data into an `IndexMap` and a parallel `Vec`, cloning names and allocating additional storage. Carry the positioned entries through the position check and property insertion, while retaining the existing schema-only representation for the `None` branch.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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 Dec 2, 2026
…in one pass

The schema a definition writes back holds its properties in the order the
definition declares them, so the two are read side by side instead of the
written map being searched once for every property. A schema that does not
hold the same names in the same order is refused as an internal error.

The ordered properties are moved into the map the parse walks, their positions
kept beside it, where the names were cloned.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants