Repository navigation
feat(dpp): read the type-level keywords of a document type from its typed definition - #6437
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
🔍 Review in progress (commit b4275e7) · live progress · priority |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
This change routes the remaining type-level document keywords through typed-definition readers while preserving schema-based parsing and adds broad equivalence and mutation coverage. The CI snapshot shows no failed checks; the Kotlin SDK build and review check are still in progress.
🟡 4 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) — This is a large, intricate change to consensus-critical document-type parsing and validation across shipped protocol generations, including flags, key requirements, aggregates, privacy, fees, and token-cost rules. - 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_schema/common/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs:2287-2293: An oversized token position reports a different error code when read from a definition
Impact: With validation enabled and full validation disabled, callers parsing tokenPosition 65536 receive code 10228 from a typed definition but code 10103 from the equivalent schema.
The typed-definition path rejects the same out-of-range value as the schema path but constructs DataContractError::ValueWrongType, while the schema reader's get_integer::<TokenContractPosition> returns platform_value::Error::IntegerSizeError. Generation 3 maps these to different public error codes. Map the narrowing failure to IntegerSizeError so the existing generation-level conversion preserves parity.
In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_keywords.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_keywords.rs:142-149: The two readers independently decide whose approval counts for a settled deletion
Impact: A future change to moderation defaults in only one reader can make the same document type use different authorization rules depending on whether it was parsed from a schema or a typed definition.
Both paths currently default approvals to one and approversPredateDocument to approvals > 1, but the typed reader repeats the rule implemented in parse_moderator_abilities_keyword. This is authorization behavior rather than merely input-shape validation. Extract a shared SettledDeletionRule constructor that accepts the decoded optional values, and retain each reader's existing shape checks and error ordering.
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/typed_keywords.rs:348-381: A new private-document parser generation must be added to two independent dispatchers
Impact: If a later protocol version adds parse_private_document generation 1 to the schema dispatcher but not this typed dispatcher, every typed-definition parse at that version fails with UnknownVersionMismatch, including non-private document types.
The schema path dispatches parse_private_document through common::declares_private_document, while the typed path independently matches the same version table before checking whether private is present. The duplicated version gate can drift and can reject definitions even when no private declaration exists. Centralize the version dispatch and pass the schema or definition keyword source into the selected generation.
In `packages/rs-dpp/src/data_contract/document_type/definition/v0/keywords.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/definition/v0/keywords.rs:59-70: The new declared_keywords helper exposes public API on every keyword group
Impact: Downstream users can depend on a Vec-returning method and its ordering on all public keyword-group structs, expanding the API that rs-dpp must preserve even though only the internal private-document check uses it.
The macro adds a public declared_keywords method to every generated keyword group, including nested ability, fee, property, rule, and reference types. The only repository caller is the internal typed private-document reader, so this visibility is broader than required. Restrict the generated helper to crate visibility.
…e typed definition Building a document type from its definition reads `documentsCountable`, `rangeCountable`, `documentsSummable`, `rangeSummable`, the two averageable shorthands and `moderatorAbilities` from the definition's typed fields. The reader of the aggregate keywords is split where it already divided: its six reads of the schema, then the desugaring of the shorthands, which now takes what was read as a `DeclaredDoctypeAggregates`. A schema is read by the same calls in the same order and desugared by the same code, and a definition hands its fields to that desugaring, so the rules are written once. The test that builds document types both ways requires each of these keywords to be declared by a document type that builds, with cases added for the ones no written document type declared. With any field of the two typed readers dropped, it fails. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Building a document type from its definition reads `immutable` and `actionFees` from the definition's typed fields. - `immutable`: the properties listed by name and those listed with a condition, a property listed twice refused. A condition is still handed on as written, taken from the schema the definition writes back at the entry's place, since the stage that applies it parses the rule language from a schema. - `actionFees`: `DocumentActionFees::try_from_definition`. The three rules of the schema reader (a part over the maximum, an action that charges nothing or adds up past the maximum, no action priced) move to functions of their own, called where each stood, so a schema is held to them at the same places and a definition is held to the same code. The test that builds document types both ways requires both keywords to be declared by document types that build, with cases for two conditions and for every action priced. With a field of either reader changed, it fails. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Building a document type from its definition reads its flags (`documentsKeepHistory`, the three kinds of kept history, `documentsMutable`, `canBeDeleted`, `transferable`, `tradeMode`, `creationRestrictionMode`) and its key requirements (`signatureSecurityLevelRequirement` and the two bounded key requirements) from the definition's typed fields. The core parse, which every generation shares, takes the definition as an optional argument and keeps it in its context. Generation 1 passes `None`, as generation 3 does for a schema, and the reads of the schema are then the ones that were there, in the same order. The test that builds document types both ways requires each of these keywords to be declared by a document type that builds, with each kind of history kept on its own. With any of them misread, it fails. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Building a document type from its definition reads `tokenCost` from the definition's typed fields. The four rules registration holds a token cost to (a position the contract has, a non-transferable token burnt, no cost in this contract's token named by its id, no burning of another contract's token) move out of the schema reader into `token_cost_rules`, called where they stood: after an action's cost is read and before who pays its gas is. A schema is held to them at the same place, and a definition to the same code. `parse_token_costs` keeps the formatting it had, marked `rustfmt::skip`: one of its lines was too long for rustfmt to format the function, and is among those moved. The test that builds document types both ways requires a cost in another contract's token and in a token of the contract, a burnt one, each payer of gas, an optional cost and every action to be declared by document types that build. With any field of the typed reader misread, it fails. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Building a document type from its definition reads `private` from the definition's typed fields: whether the type is private, the keywords a private type may declare, and the bytes each entry takes. A group of keywords of a definition says which keywords it declares (`declared_keywords`, written by `keywords!`), which the rule on a private type's keywords reads in place of the keys of a schema. The test that builds document types both ways builds a private type, and one with a keyword only that rule refuses. With the typed readers changed, it fails. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Review of the typed readers of the type-level keywords: - The defaults of a `deleteSettled` (one approval, approvers predating the document from two) are filled in by one function, `settled_deletion_rule`, for a schema and for a definition. The schema reader reads its three values in the order it did and hands them over. - `common::declares_private_document` dispatches on the version of the `private` keyword once, and calls the reader of a schema or of a definition in the generation it selects. The typed reader no longer matches the version table itself. - A token position past a token position's range is refused from a definition with the error a schema's reader gives, `IntegerSizeError`. - `declared_keywords` is visible in the crate only. 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 |
43e3f83 to
e44b8d6
Compare
|
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.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: This head contains the review-fix refactor that centralizes private-document dispatch, settled-deletion defaults, and typed/schema error handling while keeping the existing schema paths intact. The CI snapshot shows the relevant Rust, wasm32, JavaScript, and Kotlin checks still in progress; completed checks are successful and no failed code check is reported.
💬 1 nitpick(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) — This is a large, intricate change to consensus-critical document-type parsing that alters validation and interpretation of typed definitions, including key requirements, action fees, token costs, privacy, and protocol-versioned readers. - 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_schema/common/mod.rs`:
- [NITPICK] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs:3250-3254: The moderation validator's Rustdoc is attached to the defaults helper
Impact: Maintainers reading either function receive misleading documentation: the defaults helper appears to enforce the full moderation contract, while apply_moderator_abilities is left without its intended Rustdoc.
The Rustdoc immediately preceding `settled_deletion_rule` describes `apply_moderator_abilities`, including that it runs after immutable-field, index, reference, and generated-property processing, but Rust attaches that entire block to `settled_deletion_rule`, which is called during keyword parsing. Move `settled_deletion_rule` and its four-line rule-specific comment above the documentation beginning `Applies the moderatorAbilities object`, so the moderation contract remains attached to `apply_moderator_abilities` and the helper receives only its own documentation.
|
Bots are done — your move: post |
`settled_deletion_rule` and `token_cost_rules` were added between `apply_moderator_abilities` and `parse_token_costs` and their documentation, which then described the new functions. Each helper now stands before the documentation of the function it was added beside. 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: #6433 added
DocumentType::try_from_definition, which builds a document type from its typed definition, with five keywords read from the definition's typed fields and everything else read from the schema the definition writes back. This PR moves the rest of the type-level keywords to the typed fields: the flags, the key requirements, the aggregates,moderatorAbilities,immutable,actionFees,tokenCostandprivate. Properties, indexes, references and the rule language are still read from the written-back schema and follow in later PRs.Value: One more section of the grammar no longer goes through JSON on the way from a definition to a document type. Where a schema reader carried rules as well as shape checks, the rules now live in one function that both sources call, so a definition is held to the same code as a schema, not to a copy.
Risks: Low. Nothing carries a definition, so no state transition is validated differently. Four shipped readers were split so that their rules could be shared; each split keeps every read and every refusal at the place and in the order it had (see "In-place changes to shipped generations").
Follows #6433, which is merged: this branch is rebased on
v5.2-devand holds only its own commits.Issue being fixed or feature implemented
Part of removing JSON schema from the protocol in 5.2, after #6422 and #6433.
What was done?
Typed readers in
try_from_schema/typed_keywords.rs, each standing where the schema reader it replaces stands in the parse:documentsKeepHistory,keepsTransferHistory,keepsPurchaseHistory,keepsPricingHistory,documentsMutable,canBeDeleted,transferable,tradeMode,creationRestrictionModeflagssignatureSecurityLevelRequirement, the two bounded key requirementssecurity_level_requirement,bounded_key_requirementdocumentsCountable,rangeCountable,documentsSummable,rangeSummable,documentsAverageable,rangeAverageableaggregatesdesugar_doctype_aggregates)moderatorAbilitiesmoderator_abilitiesdeleteSettled, shared (settled_deletion_rule); an empty object or list refusedimmutableimmutableactionFeesDocumentActionFees::try_from_definitiontokenCosttoken_costs_from_definitiontoken_cost_rules)privatedeclares_private_document,private_documentTwo things are deliberately partial:
immutableis still handed on as written, taken from the written-back schema at the entry's place in the list. The stage that applies it parses the rule language from a schema, and the rule language moves in its own PR.keywords!gainsdeclared_keywords(crate-visible), the keywords a group of a definition declares. The rule on a private type's keywords reads it where the schema reader reads the keys of the schema.In-place changes to shipped generations
All in code protocol versions up to 15 select. In each, a schema is read by the same calls in the same order, and refused by the same code at the same point.
parse_document_type_core(every generation) takesdefinition: Option<&DocumentTypeDefinitionV0>and keeps it in its context. Generation 1 passesNone; generation 3 passes what it was given,Nonefor a schema.match definition { Some(d) => typed reader, None => the call that was there }: the aggregates,moderatorAbilities,immutable,actionFees, the entry size ofprivate, the three key requirements.parse_document_type_flagsandparse_token_costsreturn the typed reader's answer first when there is a definition and are otherwise unchanged.parse_doctype_aggregate_keywordsis split where it already divided: its six reads, thendesugar_doctype_aggregateson what they read. The one difference in the text: the desugaring used to readdocumentsCountablea second time to tell "left out" fromfalse; it now uses the first read's answer, which is the same value from the same call.parse_moderator_abilities_keywordreads the three values of adeleteSettledin the order it did and hands them tosettled_deletion_rule, which fills in the defaults it filled in.declares_private_documenttakes the definition as an optional argument and, in the generation the version selects, calls the reader of a schema as before when there is none.DocumentActionFees::try_from_document_schema: its three rules (a part over the maximum, an action that charges nothing or adds up past the maximum, no action priced) move to functions of their own, each called where the rule stood.parse_token_costs: its four rules move totoken_cost_rules, called where they stood, after an action's cost is read and before who pays its gas is. The function is markedrustfmt::skipso that its remaining lines read as they did: rustfmt had left it unformatted because one of its lines, now among those moved, was too long to break.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 requires 46 keywords and shapes of keywords to be declared by a document type that builds, and adds the cases no written document type had: each kind of history kept alone, a range count, the averageable shorthands, every moderator ability (a settled deletion under an elected team), two conditionalimmutableentries, every action priced in credits and in tokens with each payer of gas, a private type, and a private type with a keyword only the private rule refuses.deleteKeepsRecordonly at its default, a condition taken from the wrong entry, one action's fee read for another, one kind of history read for another (twice), and the private keyword rule hidden by a later refusal.cargo test -p dpp --lib class_methods::: 1,093 passed.cargo test -p dpp --lib action_fees: 21 passed.cargo test -p dpp --lib definition::: 47 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 ·
b4275e7/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