Repository navigation
fix(dpp): parse nested required and transient entries by prefix - #5050
Conversation
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]>
|
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 configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughRequired and transient paths now use ChangesSchema Path Handling
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk is identified; the change is ready for normal merge checks. Architecture SummaryArchitecture risk: 🟡 Medium · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
Reliability and maintainability
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
✅ Final review complete — no blockers (commit 2f9b01d) · triage: low |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
lowbygpt-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); agentphase1-reviewer,glm-5.3-flash— architecture-layering (completed, effort high); agentphase1-reviewer,glm-5.3-flash— platform-versioning (completed, effort high); agentphase1-reviewer,glm-5.3-flash— rust-quality (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 98% left, weekly 34% left; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 13% left, 5h 100% left) - Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort medium); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort medium); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort medium); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort medium); agentphase2-reviewer
|
Bots are done — your move: post |
Basic explanation
What this does: Each document type in a data contract lists which of its fields are
requiredand which aretransient(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-levelrequiredandtransientsets 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_requiredandstripped_transientare built with a prefix match and a checked slice.Before:
After:
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_nestedis shared by everytry_from_schemageneration, so this edits shipped code in place.DocumentTypeV0::try_from_schema(v0/mod.rs), a direct callDocumentTypeV1::try_from_schema(v1/mod.rs) →common::parse_document_type_core→parse_document_propertiesDocumentType::try_from_schema_v2(v2/mod.rs) →DocumentTypeV2::try_from_schema→ generation 1's parserDocumentType::try_from_schema_v3(v3/mod.rs) →common::parse_document_type_core→parse_document_propertiesWhy consensus cannot change at any of them: for an entry that starts with the property name (
nbytes long), the new expression iskey.get(n + 1..).str::getreturnsSome(&key[n + 1..]), the exact string the old expression produced, whenever that slice is valid, andNoneotherwise.Nonecovers the entry equal to the property name (the oldkey.len() > nguard 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 identicalDocumentType(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?
try_from_schema/mod.rs, run through the publicDocumentType::try_from_schemadispatcher atPlatformVersion::latest()and at protocol version 13, the last shipped one:should_match_required_entries_to_object_members_by_prefix: a top-levelrequiredentry 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 fortransient. 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.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:
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 ·
2f9b01d/self-reviewedWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit