Skip to content

fix(dpp): parse nested required and transient entries by prefix - #5050

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/friendly-bhaskara-7ef96c
Sep 27, 2026
Merged

QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/friendly-bhaskara-7ef96c

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: Each document type in a data contract lists which of its fields are required and which are transient (checked when a document is written, but never stored). When a field is an object with fields of its own, the contract parser works out which inner fields those lists cover by removing the object's name from the front of each list entry. It used to do that by cutting the entry at a fixed byte position. It now removes the name with a prefix match and reads the rest with a checked slice, so an entry that does not have the expected shape simply names no inner field.

Value: Contract parsing no longer depends on a byte-offset string index. Every node runs this parser on each contract create and update and whenever it loads a contract, and clients built on rs-dpp (the WASM and JS SDKs among them) run the same code.

Risks: Low. For every entry the old code handled, the new code returns exactly the same result, so every contract that parses today parses to the same document type at every protocol version. No protocol version, version table or stored data changes. The only difference is for entries the old code could not process: they now name no inner field. The two new unit tests are fast.

Issue being fixed or feature implemented

insert_values_nested (packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs) builds the member-level required and transient sets of an object property from the document type's sets, by indexing each matching entry at a byte offset past the property name. This change parses those nested entries by prefix instead of byte offset.

What was done?

  • insert_values_nested: stripped_required and stripped_transient are built with a prefix match and a checked slice.

    Before:

    if key.starts_with(&property_key) && key.len() > property_key.len() {
        Some(key[property_key.len() + 1..].to_string())
    } else {
        None
    }

    After:

    key.strip_prefix(property_key.as_str())
        .and_then(|rest| rest.get(1..))
        .map(str::to_string)
  • The matching rule is deliberately unchanged: an entry for a member is the object's name, one separator byte, then the member's own entry. Requiring the separator to be . would change how some schemas that parse today are read, so that is left for a separate, versioned change. The comment at the edited lines records this.

  • Two unit tests in the same file's test module (below).

In-place changes to shipped generations

insert_values_nested is shared by every try_from_schema generation, so this edits shipped code in place.

Generation Protocol versions Reaches the edited lines through
0 1 to 8 DocumentTypeV0::try_from_schema (v0/mod.rs), a direct call
1 9 to 11 DocumentTypeV1::try_from_schema (v1/mod.rs) → common::parse_document_type_core → parse_document_properties
2 12 and 13 DocumentType::try_from_schema_v2 (v2/mod.rs) → DocumentTypeV2::try_from_schema → generation 1's parser
3 14 (unreleased) DocumentType::try_from_schema_v3 (v3/mod.rs) → common::parse_document_type_core → parse_document_properties

Why consensus cannot change at any of them: for an entry that starts with the property name (n bytes long), the new expression is key.get(n + 1..). str::get returns Some(&key[n + 1..]), the exact string the old expression produced, whenever that slice is valid, and None otherwise. None covers the entry equal to the property name (the old key.len() > n guard gave the same result) and the entries for which the old expression could not produce a value. Every schema that parsed before this change therefore parses to an identical DocumentType (nested and flattened properties) at every protocol version, and no stored contract can contain an entry of the last kind, because its parse could never have completed.

How Has This Been Tested?

  • New tests in try_from_schema/mod.rs, run through the public DocumentType::try_from_schema dispatcher at PlatformVersion::latest() and at protocol version 13, the last shipped one:
    • should_match_required_entries_to_object_members_by_prefix: a top-level required entry that names no member leaves the nested and flattened properties identical to the same schema without it, and the members keep the flags the object's own list gives them. The validating parse at the latest version accepts the schema.
    • should_match_transient_entries_to_object_members_by_prefix: the same for transient. The validating parse at the latest version refuses the entry under the protocol version 14 rule that every transient entry names a top-level property.
    • Both fail on the base branch at both versions and pass with this change.
  • Throwaway checks, not committed: the same schemas parsed before and after the change at every protocol version 1 to 14 gave identical document types, and an exhaustive comparison of the old and new expressions over short entries found them identical wherever the old expression produced a value.
  • cargo test -p dpp --lib object_members_by_prefix (2 passed), cargo test -p dpp --lib data_contract (2401 passed), cargo clippy -p dpp --all-features --all-targets -- -D warnings (clean).

Breaking Changes

None. Every contract that parses today parses to the same result at every protocol version, and there is no protocol version bump.

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 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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 2f9b01d

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

When every box is checked the PR Hygiene check passes and this can merge.

Summary by CodeRabbit

  • Bug Fixes
    • Improved document schema handling for required and transient paths that share a prefix with an object name. Parsing preserves existing property matching behavior and avoids panics on invalid path boundaries.
    • Confirmed required and transient validation behavior remains consistent on the latest and protocol version 13.

insert_values_nested derives the required and transient entries of an
object property's members by removing the object's name from the front of
each document type entry. It now does so with `strip_prefix` and a checked
`str::get` instead of indexing the entry at a byte offset.

The result is the same string the previous expression produced wherever
that expression was valid, and no member entry otherwise, so every schema
that parsed before parses to the same document type. The helper is shared
by every try_from_schema generation (protocol versions 1 to 14); the
matching rule itself is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 27, 2026
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 27, 2026
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 7ca866e6-4b20-48c1-86a5-9be44de97c51

📥 Commits

Reviewing files that changed from the base of the PR and between 4d4f38d and 2f9b01d.

📒 Files selected for processing (1)
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.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

Walkthrough

Required and transient paths now use strip_prefix and get(1..) to remove an object-property prefix. Tests cover unmatched paths when parsing the latest and protocol version 13 schemas, and during full validation.

Changes

Schema Path Handling

Layer / File(s) Summary
Prefix removal and validation tests
packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs
Required and transient path handling now uses strip_prefix and get(1..). Tests verify that paths sharing the profile prefix without naming a member do not change parsed properties. Full validation accepts the unmatched required entry and rejects the unmatched transient entry.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 2f9b0

No actionable merge-blocking risk is identified; the change is ready for normal merge checks.

Architecture Summary

Architecture risk: 🟡 Medium · up to 2f9b0

The change affects 1 system.

Changed systems: packages/rs-dpp

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/rs-dpp (library) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs: Required and transient path-prefix removal now uses strip_prefix followed by get(1..), instead of checking prefix and length before direct byte-offset slicing. This retains the old one-byte removal behavior without requiring a dot separator and safely omits entries when the slice is invalid.
  • observed — Modified behavior in packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs: Added test fixtures and a test confirming that a top-level required entry sharing the profile prefix but naming no object member does not change member requiredness or parsed properties. The test covers the latest and protocol version 13 parses, and full validation.
  • observed — Modified behavior in packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs: Added a test confirming that a transient entry sharing the profile prefix but naming no object member does not mark its members transient or change parsed properties on the latest and protocol version 13. Full validation rejects that unmatched transient entry as not naming a top-level property.

Reliability and maintainability

  • inferred — Risk-relevant change factors for packages/rs-dpp: blast_radius_2; direct_dependents_2
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing prefix-based parsing of nested required and transient entries.
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. Analyzed 6 functions across 1 files.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 2f9b01d) · triage: low

@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

Verified the supplied findings against head 2f9b01d and found no actionable in-scope issues. The checked prefix slicing preserves previously successful results while avoiding invalid UTF-8 boundary panics; both focused regression tests passed locally. The proposed comment expansion, closure extraction, and adjacent validation or rollout follow-ups do not warrant review findings.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: architecture-layering); reviewer 3: glm-5.3-flash (agent: phase1-reviewer, role: platform-versioning); reviewer 4: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: low by gpt-6-astra (effort low) — The diff is a small, contained replacement of unchecked string slicing with prefix matching and checked slicing in insert_values_nested, preserving previously successful parsing behavior and adding two focused regression tests.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — architecture-layering (completed, effort high); agent phase1-reviewer, glm-5.3-flash — platform-versioning (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 98% left, weekly 34% left; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort medium); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6-astra — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort medium); agent phase2-reviewer

@github-actions

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 Sep 27, 2026

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Approved

@QuantumExplorer
QuantumExplorer merged commit 3e6e258 into v4.2-dev Sep 27, 2026
36 of 37 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/friendly-bhaskara-7ef96c branch September 27, 2026 14:57
@PastaPastaPasta PastaPastaPasta mentioned this pull request Sep 28, 2026
2 of 24 tasks
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