feat(platform)!: maxBytes, a UTF-8 byte cap on document strings (PV14) - #4957
Conversation
…PV14) Two document schema keywords for bounds plain JSON Schema cannot count: `maxBytes` caps a string's UTF-8 length (maxLength counts characters) and `sumOfProperties` is the total an object's integer members must add up to. Parsed by the v3 parser, checked on document create and replace after the schema validation (DocumentPropertyMaxBytesExceededError 10421, DocumentPropertySumMismatchError 10422); replace structure validation 0 is extended in place and inert before protocol version 14. The moderation charters contract declares both on the proposal's description and reward split, replacing validate_submitted_charter, its errors 11001 and 11002 and SystemLimits::max_moderation_charter_description_length. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m-of-properties # Conflicts: # book/src/data-model/documents.md # docs/protocol/moderation-charters.md
|
Warning Review limit reachedNext included review available in 44 seconds. 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 (50)
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-24T01:26:14.505Z |
|
🕓 Queued for automated review — 9th in line, estimated start in ~1.8 h (commit 1fd989d)
|
Drop sumOfProperties (keyword, error 10422, version slots, compatibility rule); the charter's reward split rule goes back to validate_submitted_charter and error 11001, unchanged from the base branch. maxBytes review fixes: - the bound lives in StringPropertySizes::max_bytes, so max_byte_size, max_size and random documents respect it - the check runs inside DataContract::validate_document_properties, so client-side validation (wasm-dpp document.validate) refuses an oversized string before broadcast; the create and replace structure validations are back to the base branch - typed_array_items_keyword shared by distinctFrom and maxBytes - book: maxLength alone is bounded by the 5120-byte field cap - wasm-dpp2 DocumentMaxBytesErrorCode; test names start with "should" - tests for typed-array items compatibility and a typed-array element refusal end to end Also fixes a wasm-dpp2 lint error (a parameter shadowing `schemas` in DocumentPropertyReference.spec.ts) that failed the lint job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Issue being fixed or feature implemented
maxLengthcounts characters, and a UTF-8 character is up to four bytes, so a document schema cannot cap a string's size in bytes. The moderation charter proposal needs exactly that (itsdescriptionmust fit 4096 bytes), and so far it lived in charter-specific Rust.This PR adds a general
maxBytesschema keyword and moves the charter description onto it.What was done?
maxBytesis the most UTF-8 bytes a string may take. It goes on a string property, or on theitemsof a typed array of strings, where it bounds every element.Before, the v3 meta-schema refused it as an unknown keyword:
After, the contract registers:
bio"éééééééé""ééééééééé"DocumentPropertyMaxBytesExceededError(10421),Property bio is 18 bytes in UTF-8, over its maxBytes of 16For a typed array the error names the element, e.g.
tags[2].Rules:
minLength. It is refused on non-strings and on the typed array itself.maxLength. Raising or removing it is allowed; adding or lowering it is refused.Where it's stored:
apply_max_bytesfolds it intoStringPropertySizes::max_bytes, next tomax_length. So size estimates, and random documents in strategy tests and fixtures, respect it. Before,maxLength: 64withmaxBytes: 16was estimated at 256 bytes; now it's 16.Where it's checked: inside
DataContract::validate_document_properties, right after the JSON Schema. That covers every create and replace, CheckTx, and client-side validation (wasm-dppdocument.validate), so an SDK refuses an oversized string before the writer pays for a consensus refusal. The version slotsapply_max_bytesandvalidate_max_bytesareSome(0)from protocol version 14 andNonebefore.Moderation charters:
submittedCharter.descriptiondeclares"maxBytes": 4096. Before this PR, a 2049-édescription (4098 bytes) was accepted at create, since the charter check wasn't wired into consensus. Now it is refused with 10421.Removed as redundant:
SubmittedCharter::validateModerationCharterDescriptionTooLongError(11002)SystemLimits::max_moderation_charter_description_lengthThe reward split rule (
validate_submitted_charter, error 11001) is unchanged, so #4952 keeps compiling.Errors:
BasicErrordiscriminant 198 moves from the removed 11002 error to 10421. Both are unreleased (protocol version 14), and the frozen-tail test pins it.DocumentMaxBytesErrorCode.MaxBytesExceeded.Also:
distinctFrom's "belongs on the items" handling moved into a helper shared withmaxBytes. Its messages are unchanged.wasm-dpp2/tests/unit/DocumentPropertyReference.spec.tsis fixed (a parameter shadowedschemas, from #4940).In-place changes to shipped generations
DataContract::validate_document_propertiesv0 now callsvalidate_max_bytes_properties. It is inert before protocol version 14: thevalidate_max_bytesslot isNone, and no string parsed there can carry the keyword (meta-schemas v0 to v2 refuse unknown property keywords,$defsincluded, andapply_max_bytesisNone). A drive-abci test runs an over-cap replace at protocol version 13 (accepted) and 14 (refused).max_byte_sizeandmax_sizechange only for strings withmax_bytes: Some, which only protocol version 14 parses produce.CONTRACT_VERSIONS_V1toV5gain the two slots asNone.SYSTEM_LIMITS_V1toV3lose the charter description limit, which was never read below protocol version 14.maxBytesrule. The keyword cannot appear in a schema admitted before meta-schema v3.How Has This Been Tested?
itemsdocument.validaterefusing a 4098-byte description with 10421 and accepting 4096 bytes. Its lint passes.Breaking Changes
Protocol version 14, which is unreleased:
SystemLimits::max_moderation_charter_description_lengthare removed.StringPropertySizesgains amax_bytesfield, so struct literals must set it.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