Skip to content

Typed document type definition: follow-ups from the review of #6422 #6427

Backlog

Description

@QuantumExplorer

#6422 adds DocumentTypeDefinition, a typed form of a document type's schema (packages/rs-dpp/src/data_contract/document_type/definition/). Nothing in consensus uses it yet. Its sixth review round had no blocking finding and left these suggestions, which belong to the pull requests that build on it rather than to another round on #6422. This issue tracks them so they are picked up there.

For the pull request that applies registration's rules to a definition

These are places where a definition reads a value registration refuses. #6422 holds a keyword to the type of its value (a name or code is one the keyword has, an id is 32 bytes) and leaves rules about which values go together to registration, so each of these is a rule to apply to the typed form, with a test against registration beside it.

  • The second operand of a requirement condition's contains (thread). TypeCondition::Contains takes a ConditionValue, which admits $kind; registration admits $property or a { "const": ... } there (native_schema/references.rs, slot_condition).
  • A list of reference targets (same thread). Reference::target takes any ReferenceTarget in a list; registration admits a list only on a reference that names its target through the referring document, and only of permanentDocument and moderatedDocument (reference_kind_list).
  • A contract id written as text (thread). ContractId::Text takes any string; registration reads $self.<property> or a Base58 id that decodes to 32 bytes (parse_document_reference_type, through Value::to_identifier). A typed form could tell the two apart and hold the id to its width, keeping both spellings a schema writes.

For the pull request that carries a definition in a contract format

  • A size budget for decoding (thread). The standalone decoders of DocumentTypeDefinition and SchemaDefinitions decode under the platform bincode configuration, which has no size limit; nesting is bounded, width is not. The format that carries a definition is bounded by the state transition's size, and should state its own budget for a definition decoded on its own. Until then the module documentation should say the standalone decoders impose none.
  • One form for the carrying format's bytes. Already recorded in the module documentation: the check that a definition's bytes are the ones it encodes to sits on its standalone decoder, so a format that embeds a definition must hold its own bytes to one form at its own boundary.

Small

  • SortedMap decoding (thread). Decoding a contract's $defs stages the entries in a vector, moves them into a BTreeMap and clones each name to compare it with the next. It could keep the decoded vector, check the order on borrowed neighbours and look a name up by binary search, with the same bytes.

Related

Activity

  1. QuantumExplorer commented on Dec 1, 2026

    @QuantumExplorer
    MemberAuthor

    One more item for the pull request that makes the last in-place change to the grammar before protocol version 16 ships.

    Mark the grammar's declarations // @append_only. #6422 now says the definition grows by appending: a keyword added later goes at the end of its group and is available from a protocol version, instead of a new generation. A test pins every position (definition/v0/layout.rs), but the declarations (keywords!, names!, codes!, shapes! and the derived enums of the rule language) do not carry the CI marker yet, because "Detect immutable structure changes" would refuse the changes listed above, which alter the type a keyword or a variant holds. Once those are in, each declaration gets the marker, so CI refuses a removed, renamed, reordered or retyped entry whatever the pull request does to the pinned list.

    Also for the first keyword added after protocol version 16: it has to bring the check of the version it is available from, at the point where the carrying format is decoded, so that a node refuses it below that version as a node built before it does.

  2. QuantumExplorer commented on Dec 1, 2026

    @QuantumExplorer
    MemberAuthor

    Correction to the item above, after the review of #6422: the marker goes on the pinned list itself, PINNED in definition/v0/layout.rs, as the last step before a protocol version that carries definitions ships.

    Every line of the list carries its position and the types of what it holds, so against the base branch the CI check then refuses a removed, renamed, reordered or retyped entry, and also a keyword put in the middle, since that renumbers the lines behind it. On the declarations alone the check would miss a pure insertion. PINNED is the last item of its file, which is what the check's block extraction needs for a block without braces: keep it last, and confirm the check sees the list in the pull request that adds the marker.

  3. QuantumExplorer commented on Dec 1, 2026

    @QuantumExplorer
    MemberAuthor

    With the step above (marking PINNED for the CI check), from the last review round of #6422 (thread):

    • Widen the alias scan. should_pin_no_type_by_an_alias in definition/v0/layout.rs finds aliases by pub type at the start of a line. Make it find an alias of any visibility (pub(crate) type, pub(super) type, type) declared in the grammar's files, so a keyword pinned through one cannot change what it holds with its line unchanged. No such alias exists today.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions