feat(dpp)!: encode typed array elements as their scalar property type (PV14) - #4923
Conversation
… (PV14) A typed array element is now parsed from its items schema exactly as a scalar property schema is (DocumentPropertyType::try_from_value_map with the contract's parsing options) and encoded exactly as a required scalar property of that type. An identifier element is 32 raw bytes instead of a 0x20 length byte and 32 bytes, an integer element takes the width its bounds give it instead of always 8 bytes, and a fixed-size byte array element is raw. Strings and variable-size byte arrays keep their varint length. TypedArrayProperty::item_type becomes Box<DocumentPropertyType>. The decoder refuses a serialized count above maxItems before reading any element, and the encoder refuses a raw identifier or fixed-size byte element of the wrong length. The schema compatibility rules allow raising maximum, adding enum values and unpinning a byte array's size, which would change an element's width, so validate_update v1 refuses a change in how an element encodes. Typed arrays have never shipped (#4922 is unreleased), so no stored document uses the old element encoding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 28 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
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 |
|
|
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-22T22:06:40.911Z |
…m parse Typed array elements are their scalar property type since #4923. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…h or signedness (PV14) A sized integer property takes its type (u8 ... i64) from its `minimum`, `maximum` or `enum`, and the schema compatibility rules allow raising `maximum`, lowering or removing `minimum`, removing the bounds and adding `enum` values; the contract config allows turning `sizedIntegerTypes` on. Each can move the type, and documents stored at the old width then no longer decode against the updated document type (or read back other values), while their index entries stay under keys of the old width. validate_update v1 (protocol version 14 only) now refuses any change of an integer property's type, nested properties included, with a DocumentTypeUpdateError, as validate_byte_array_encoding_stability refuses a byte array's fixed-size change. A bound change that keeps the type is still allowed. validate_update v0 is unchanged for replay. The layout description moves to DocumentPropertyType::stored_encoding, and the typed array element check (#4923) calls it instead of its own copy, so both checks describe a scalar's layout the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pe) into fix/typed-array-review-fixes The element constraints now sit on the boxed scalar item type and random integer elements come back in the element type's own value kind.
Issue being fixed or feature implemented
#4922 added typed scalar arrays at protocol version 14 and stored their elements in the legacy
ArrayItemTypeencoding, which is not how the same types are stored as scalar properties:0x20length byte in front of its 32 bytesThat array encoding had never been used for a stored document: #1851 (v1.0.0) made non-byte arrays unparsable, and #4922 is not in any release. So this is the last point where the element layout can change without a migration.
What was done?
A typed array element is now a scalar property in every respect:
Parse: the
itemsschema goes throughDocumentPropertyType::try_from_value_mapwith the contract's parsing options, the same parse a scalar property schema gets.TypedArrayProperty::item_typeis nowBox<DocumentPropertyType>. An element that parses to anything other than a scalar (U8..I128, F64, String, ByteArray, Identifier, Boolean) is refused. Objects, arrays of arrays,$refandrefersToare refused as before.Encode / decode: a varint count, then each element via
encode_value_ref_with_size(element, true)/read_optionally_from(buf, true), i.e. exactly as a required scalar property:20+ 32 bytes0..100sizedIntegerTypes14+ 20 bytesDecoder bound: a serialized count above
maxItemsis refused before any element is read. This bounds the loop even for zero-width elements (a byte array pinned to 0 bytes).Encoder check: a raw element (identifier, fixed-size byte array) whose bytes are not exactly its width is refused. Without the check, a short element would shift every element after it. Schema validation already catches this for real documents; the check stops the serializer itself from writing a misaligned list.
Update guard: the schema compatibility rules allow raising
maximum, addingenumvalues and unpinning a byte array's size, and each of these can change an element's width.validate_updatev1 (new at PV14, edited in place) now runsvalidate_typed_array_element_encoding_stabilityafter the byte-array stability check. It refuses withDocumentTypeUpdateErrorwhen an element's stored encoding would change, e.g.u8 -> u16ora fixed 20-byte array -> a length-prefixed byte array. A longermaxLength, a largermaxItems, and a raisedmaximumthat keeps the width are all accepted.Fee sizing:
min_byte_size/max_byte_sizeof a typed array are the count prefix plusmin/maxItemstimes the element's scalar byte size, plus its varint length when it has one.Removed:
ArrayItemTypekeeps only what the legacyDocumentPropertyType::Arraycodec uses. The typed-array-only helpers from feat(dpp)!: typed scalar arrays in document schemas (PV14) #4922 are gone.wasm-dpp2:
documentTypeTypedArraysmaps the scalar element type back to the same JS shape (integer/number/boolean/string/byteArray/identifier), so the TS surface is unchanged.Docs: v14 changelog item 25 was edited in place. The book's serialization table row, a new pitfall entry, and the Typed Arrays section in the documents chapter now describe the scalar element layout and the update guard.
Note: an element inherits the scalar integer sizing exactly, including
maximumwithoutminimumchoosing an unsigned type. The scalar integer width-change guard on contract update is a separate PR (claude/integer-width-update-guard). Whichever PR lands second should replace this PR's nestedelement_encodingwith that PR's sharedDocumentPropertyType::stored_encoding().How Has This Been Tested?
should_encode_each_typed_array_element_as_a_required_scalar_property_of_its_type: exact bytes for identifier, U8, I64, fixed and variable byte array, string and boolean elementsshould_round_trip_every_typed_array_element_type_through_encode_and_read_optionally_from: every element type, required and behind a presence flag, with no bytes left overshould_refuse_a_serialized_typed_array_counting_more_elements_than_its_max_items: including zero-width elementsshould_refuse_to_encode_a_typed_array_value_that_is_not_a_list_of_its_elements: including a 31-byte identifier and a short fixed-size elementshould_type_an_element_as_a_scalar_property_of_its_schema: U8, I16, I64 whensized_integer_typesis off, identifiershould_reject_an_update_that_changes_how_typed_array_elements_are_encoded/should_accept_an_update_that_keeps_how_typed_array_elements_are_encoded0..100integers are now 2..11 bytes, not 9..81).cargo test -p dpp --all-features --lib -- typed_array parse_typed_array validate_update property:: document: 1872 passed.cargo clippy -p dpp --all-features --all-targets -- -D warnings,cargo clippy -p wasm-dpp2 --target wasm32-unknown-unknown --all-targets -- -D warningsandcargo check -p drive --all-featuresare clean;cargo fmt --allapplied.DocumentTypedArrays.spec.ts), whose output shape is unchanged, and the drive-abci suites; CI covers these.Breaking Changes
Protocol version 14 is unreleased, so no stored document changes:
TypedArrayProperty::item_typechanges type fromArrayItemTypetoBox<DocumentPropertyType>, andTypedArrayPropertyno longer derivesEq.parse_typed_arraytakes the property'sDocumentPropertyTypeParsingOptions.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 ·
9f2497d/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.