Repository navigation
feat(dpp): read which properties a document type has from its typed definition - #6439
Conversation
…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]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
🔍 Review in progress (commit 841f924) · live progress · priority |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
normalbygpt-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); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-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.
|
Bots are done — your move: post |
…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]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
Basic explanation
What this does:
DocumentType::try_from_definitionbuilds 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 whereparse_document_propertiesreads 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 asValue::inner_optional_index_maporders the properties of a schema (a stable sort byposition). A property without a position is refused with the error the reader of a schema gives.required_fields: the names the type'srequiredlists and those therequiredof each object lists, writtenobject.member, to any depth. As for a schema, an object reached through a$refor held by a list is not looked into.transient_fields: the type'stransientlist.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_propertiesintry_from_schema/common/mod.rs, which every generation since 1 runs:match ctx.definition { Some(d) => typed reader, None => the call that was there }: the ordered properties, the required names and the transient names.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_schemabuilds 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: arequiredlist at the root, on an object, and two objects down (a case added for it); atransientlist; and properties declared out of the order of their positions.requireddropped; 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 --libwith no features,cargo fmt --all: clean.Not run: the full
dppsuite and the other crates.Breaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
841f924/skip-botsproceeds without the ones not yet reported/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