Conversation
`DocumentType::try_from_definition` builds from a `DocumentTypeDefinition` the document type its schema builds through `try_from_schema`. Generation 0, which protocol version 16 selects (`CONTRACT_VERSIONS_V8`), parses the schema the definition writes back with generation 4 of the schema parser; the sections of the grammar move from there to the definition's typed fields one at a time. Nothing carries a definition yet, so no state transition is validated differently. A corpus test builds each of the 1,503 document types registered on mainnet and testnet both ways, as a contract holds it and under the rules of registration, and holds the two to the same document type or the same refusal. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Building a document type from its definition reads `indexOnly`, `entryPayload`, `ttl`, `canBeErased` and whether `canBeDeleted` is `"onlyWhenConsumed"` from the definition's typed fields (`try_from_schema/typed_keywords.rs`), where it read them from the schema the definition writes back. The generation-3 and generation-4 parses take the definition as an optional argument. It is `None` for every document type registered or loaded from a schema, and each stage then makes the call it made before, in the same place. A test builds the written document types, the corpus and schemas generated from both from their definitions and from their schemas, and holds each typed reader to the reader of the schema it stands for: with any of the five changed, it fails. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
✅ Final review complete — no blockers (commit c99df76) |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Changes requested: 1 blocker
full_validation: trueaccepts registration-invalid definitions in JSON-only builds —packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/mod.rs:30-45(new)
Impact: A caller compiling DPP withjson-conversionbut withoutvalidationcan receiveOkfor a definition such as a hyphenated document type name even though a node rejects it during registration.
This PR adds a protocol-v16-dispatched DocumentType::try_from_definition path that converts typed definitions through the generation-4 parser while preserving existing schema callers. No code checks are failing in the supplied CI snapshot; package detection, CodeRabbit, and PR Hygiene are still in progress, with other applicable checks skipped or successful.
🔴 1 blocking | 🟡 5 suggestion(s)
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 substantial Rust parsing and protocol-dispatch change, but the existing schema path is preserved and no currently used state-transition or consensus behavior changes. - 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_definition/mod.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/mod.rs:30-45: `full_validation: true` accepts registration-invalid definitions in JSON-only builds
Impact: A caller compiling DPP with `json-conversion` but without `validation` can receive `Ok` for a definition such as a hyphenated document type name even though a node rejects it during registration.
The public API documents `full_validation` as applying registration rules, but the method is available with `json-conversion` alone. In that configuration, the shared generation-3/4 parser compiles out the hyphenated-name check, schema-depth accounting, and native schema validation, so the method silently performs only parse-level work and can report success for input that a validating node refuses. Fail closed when `full_validation` is requested without the `validation` feature, while retaining parse-only construction and the existing schema entry point behavior.
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/mod.rs:49-60: The tests do not verify that typed construction remains unavailable at protocol 15
Impact: A future version-table regression could expose typed construction at protocol 15 while the current equivalence tests continue to pass because they exercise only `PlatformVersion::latest()`.
Both new public-API equivalence tests use the latest platform version, so they verify the active v16 path but never exercise the inactive side of the dispatch boundary. Add a test using a valid fixture that confirms schema construction still works at protocol 15, `try_from_definition` returns `NotSupported` at protocol 15, and the same definition builds at the latest version.
In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/v0/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/v0/mod.rs:40-45: An oversized `bytes` shorthand can pass full validation after typed import
Impact: A definition imported from a schema containing an unindexed `bytes` property with `size` above `max_field_value_size` can build successfully even though registration rejects that source schema.
The schema-to-definition conversion expands shorthands with `full_validation: false`, so a `bytes` shorthand such as `size: 5121` becomes a long-form byte array with `minItems` and `maxItems` set to 5121. This method then writes only that normalized long form back and invokes generation 4; the existing shorthand-specific `bytes_size` check is no longer reached, allowing the typed path to accept a source schema that registration rejects. Preserve or re-run the shorthand admission checks in registration mode before normalization so definition construction retains source-schema parity.
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/v0/mod.rs:40-45: Definitions beyond the schema depth limit return the wrong error class
Impact: A caller using full validation with a typed definition whose rendered schema exceeds the protocol depth limit receives a bare `ProtocolError::DataContractError` instead of the registration-style consensus data-contract error and its normal validation accounting.
`definition.to_schema` checks the rendered schema depth before generation 3 runs and returns `write_error`, which constructs a bare `ProtocolError::DataContractError`. The schema registration path instead routes the same depth failure through `validate_schema_depth_and_account_for_size`, which reports the contract refusal as a consensus error under validation and records the schema-size operation. Map definition-rendering depth failures through the existing registration error helper on the full-validation path, leaving unrelated conversion failures unchanged.
In `packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/mod.rs`:
- [SUGGESTION] packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/mod.rs:77-83: Adding the public version-table field is a Rust source compatibility break
Impact: Downstream Rust users that construct `DocumentTypeClassMethodVersions` with a complete struct literal or exhaustive pattern stop compiling when upgrading to this release, despite the PR declaring no breaking changes.
`DocumentTypeClassMethodVersions` is a public, non-`non_exhaustive` two-field struct in the previous release. Adding `try_from_definition` makes existing complete literals and exhaustive destructuring fail to compile even though the protocol behavior is additive. Document this Rust API compatibility change in the PR's breaking-changes section and release notes, including that pre-v16 callers should initialize the field as `None`.
In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/native_schema/tests.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/native_schema/tests.rs:1469-1476: The generated parity test treats matching compilation failures as successful parity
Impact: A generated case where both document types fail compilation with the same error can be counted as `both_built`, allowing the test to pass without comparing compiled document types and inflating keyword coverage.
The `compiled` closure returns a `Result`, and the comparison at line 1480 compares those results directly. When both compilations fail identically, the results are equal and the surrounding branch still reports `both_built: true`; the test therefore does not enforce that either document type actually compiled. Make the closure panic on compilation failure, as the corpus test does, so only successfully compiled document types enter the parity comparison.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…on feature Review of the entry point that builds a document type from its definition: - Asked for full validation in a build without the `validation` feature, it refuses as not supported. The rules of registration are compiled with that feature, and it answered `Ok` for rules it had not applied. - A definition that does not write as a schema, nesting deeper than a schema registers, is refused as registration refuses a contract: a consensus error where the rules of registration are compiled. - The documentation says what a definition is held to: what registration holds the schema it writes back to, which holds byte arrays written out. The rules on a property type shorthand as such (a `bytes` size within the most a field may hold) are rules on reading a shorthand, and a definition holds none. - The test that builds document types both ways fails on a document type that does not compile, where it compared two equal failures as built. - New tests: the entry point is not supported at protocol version 15 and builds at 16; a byte array longer than a field may hold registers written out, from a schema and from a definition, while its shorthand is refused; a definition too deep to write is refused with a consensus error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Updated after discussion: 1 finding(s) of this review were settled in the inline threads.
- ✅ Withdrawn: 🟡 The tests do not exercise full-validation refusal in JSON-only builds
New on this head: This revision makes typed document-type construction refuse full validation when the validation feature is absent, maps schema-rendering failures to the registration error class, and adds coverage for the protocol-16 boundary and written-schema parity. Rust workspace tests, Rust WASM tests, and Kotlin SDK build and tests passed on this head; the Swift SDK and JS build checks are still pending, with no code-check failures reported.
🟡 1 0 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-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The substantial Rust diff changes consensus-critical document-type construction and validation across a new protocol-version dispatch path and shipped parser generations. - 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) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (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_definition/mod.rs`:
- [SUGGESTION → WITHDRAWN in discussion; do not fix] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_definition/mod.rs:61-68: The tests do not exercise full-validation refusal in JSON-only builds
Impact: For callers who enable `json-conversion` without `validation`, the tests would miss a regression that silently accepts a full-validation request or rejects a valid parse-only request.
The reported JSON-only `cargo check` verifies compilation, not which calls succeed. The new test module requires `validation`, and DPP's self dev-dependency enables that feature through `all_features_without_client`, so an ordinary DPP test under the opposite feature gate would not exercise this branch. Add an isolated consumer test that depends on DPP with default features disabled and only `json-conversion` enabled. With one valid definition at protocol 16, assert that `full_validation: true` returns `NotSupported` and `false` builds successfully.
|
Bots are done — your move: post |
|
/self-reviewed |
…dsa-65-keys v5.2-dev gained a third note in the protocol version 16 notes (a document type from its typed definition, #6433), where this branch had its note on ML_DSA_65 identity keys. The base's note keeps number 3, which a table comment cites, and the ML_DSA_65 note becomes note 4. No code conflicts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…et-listings #6433 took v16 note 3; the listings note is v16 note 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#6433 took v16 note 3: the offers note is v16 note 5 and cites the listings as note 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#6433 took v16 note 3: the history note is v16 note 6. Brings the offer proof's signed limit check, which the open-offer branch of this PR's restructured verifier now applies too. Review round of 2026-12-01 on #5531: - A closed offer, proved by its orderPlaced record, is refused when the escrow at the record's decimals passes the transition's max_total_price (should_not_prove_a_closed_offer_whose_signed_limit_ is_below_its_escrow). - The token history storage flags row of the direct upgrade is pinned to protocol version 16 (pv16()), not latest(). - The TokenEvent and token history v3 CHANGELOG entries move under Unreleased. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#6433 took v16 note 3: the frozen listings note is v16 note 7. The CHANGELOG entries of this PR move under Unreleased with the history ones, reworded for protocol version 16 (SYSTEM_LIMITS_V6, lower_document_operation; the raw converter's balance write merging is no longer part of this PR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generation 4 on v5.2-dev takes the typed definition after schema_defs (#6433), so generation 5's call to it no longer compiled after the merge. Generation 5 now takes definition: Option<&DocumentTypeDefinitionV0> in the same position and forwards it, so generation 4's typed readers serve a build from a definition; try_from_schema_v5 passes None, as try_from_schema_v4 does. permissions is still read from the schema. No test: a build fix with no behaviour change; the type-checker is the check (cargo check -p dpp --all-features --tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Basic explanation
What this does: #6422 added a typed form of a document type's schema,
DocumentTypeDefinition. A definition could be read and written, but a document type could only be built from a JSON schema. This addsDocumentType::try_from_definition, which builds from a definition the document type its schema builds. It is the first of several PRs: here the entry point exists and works end to end, five type-level keywords are read from the definition's typed fields, and everything else is still read from the schema the definition writes back.Value: It is the route by which JSON schema leaves registration in 5.2. Each following PR moves one section of the grammar (the rest of the type-level keywords, properties, indexes, references, the rule language) from "read from the written-back schema" to "read from the typed fields", and the tests added here hold every such move to the existing parser. When the last section has moved, the schema is no longer on the path, and a contract format that carries definitions can register through it.
Risks: Low. Nothing carries a definition, so no state transition is validated differently. The one change to code that shipped protocol versions run is an extra optional argument on the generation-3 and generation-4 parses, which is
Nonefor every schema (see "In-place changes to shipped generations").Issue being fixed or feature implemented
Part of removing JSON schema from the protocol in 5.2, after #6422. Follow-ups to the definition itself are tracked in #6427 and #6426. Delta contract updates (#4730) wait on the contract format that will carry definitions, which needs this entry point complete.
What was done?
DocumentType::try_from_definition(document_type/class_methods/try_from_definition/), with the arguments oftry_from_schemaand aDocumentTypeDefinitionand optionalSchemaDefinitionsin place of the schema and$defs. Selected bytry_from_definition: Some(0)in a newCONTRACT_VERSIONS_V8, which protocol version 16 selects;Nonein every earlier table, where the method answers "not supported".bytessize within the most a field may hold) are not applied to a definition: they are rules on reading a shorthand.try_from_schema/typed_keywords.rs):indexOnly,entryPayload,ttl,canBeErased, and whethercanBeDeletedis"onlyWhenConsumed". A reader of the schema checks the shape of what it reads; the definition already holds each keyword at its type, so a typed reader checks nothing and can not fail.json-conversionfeature for now, because writing a definition back to a schema is.validationimplies that feature, so every node build has it. The gate goes when the written-back schema leaves the path.Not in this PR: the remaining type-level keywords (aggregates,
moderatorAbilities,immutable,actionFees,private, the flags, token costs, key requirements), properties, indexes, references, the rule language, the schema check and the fee for a definition's size. Each is a later PR on the same pattern.In-place changes to shipped generations
try_from_schema/v3/mod.rsandv4/mod.rsare selected by protocol versions 14 and 15, which have shipped.parse_generation_3andtry_from_schema_generation_4take one more argument,definition: Option<&DocumentTypeDefinitionV0>.try_from_schema_generation_3andtry_from_schema_v4, the entry points every schema goes through, keep their signatures and passNone.match definition { Some(d) => typed reader, None => the call that was there }. WithNoneeach makes the same call with the same arguments at the same place, so the values read, the errors returned and the order they are returned in are unchanged.No other line of the shipped parsers changed. The 1,090 existing tests under
class_methods::pass unchanged.How Has This Been Tested?
cargo test -p dpp --test contract_corpus: 11 passed, 1 new.should_build_every_corpus_document_type_from_its_definition_as_from_its_schemabuilds each of the 1,503 document types registered on mainnet and testnet both ways, as a contract holds it and under today's rules of registration: the same compiled document type, or the same error.cargo test -p dpp --lib native_schema::tests: 1 new,should_build_a_document_type_from_its_definition_as_from_its_schema. It builds both ways the hand-written document types that use every keyword, 300 generated changes of each, the corpus with generated changes, and each written type made erasable and made deletable only when consumed. Both build the same compiled document type or both refuse. It also requires that, for each of the five typed keywords, some document type that builds declares it.indexOnlyandcanBeErasedread asfalse, the firstentryPayloadname dropped,ttloff by one,"onlyWhenConsumed"missed). The test above failed all five times.cargo test -p dpp --lib try_from_definition::tests: 3 passed, new. The entry point is not supported at protocol version 15, where the schema still registers, and builds at 16 what the schema builds; abytesshorthand longer than a field may hold is refused by registration while the byte array it stands for registers from a schema and from a definition alike; a definition too deep to write as a schema is refused with a consensus error.cargo test -p dpp --lib class_methods::: 1,093 passed.cargo clippy -p dpp -p platform-version --all-targets --all-features --locked -- --no-deps -D warnings,cargo check -p dpp --libwith default features and with none,cargo fmt --all: clean.Not run: the full
dppsuite and the other crates.Public interface changes
DocumentType::try_from_definition, new, behind thejson-conversionfeature. It takes the arguments oftry_from_schemawith a&DocumentTypeDefinitionand anOption<&SchemaDefinitions>in place of the schema and the$defs. Asked forfull_validationin a build without thevalidationfeature, it answersProtocolError::NotSupported; before protocol version 16 it answers the same.platform_version::...::DocumentTypeClassMethodVersionsgains the fieldtry_from_definition: OptionalFeatureVersion.DPPContractVersions: new tableCONTRACT_VERSIONS_V8, selected by protocol version 16.Breaking Changes
None for the protocol: the entry point is new and nothing calls it.
Rust source: code that builds a
DocumentTypeClassMethodVersionswith a full struct literal, or destructures one exhaustively, must name the new field. A version before 16 setstry_from_definition: 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 ·
c99df76/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