Skip to content

fix(dpp)!: accept a reordered entryPayload and refuse unruled keywords as incompatible (PV14) - #5074

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/differ-review-fixes
Sep 27, 2026
Merged

QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/differ-review-fixes

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #5069 (merged): the fixes from a review of that change.

Basic explanation

What this does: #5069 made Platform refuse, with a proper consensus error, contract updates that touch 19 schema keywords the update check had no rule for. This PR follows up on that in three ways.

  • It adds a safety net: a keyword that still has no rule (for example one added to a future meta-schema) is refused like the others, instead of stopping the check with an internal error.
  • It lets a contract owner reorder the property names in entryPayload, which changes nothing about stored data, as reordering transient already can.
  • It adds tests that pin the rest of the behaviour.

Value: Contract owners always get a consensus error code when an update is refused, even for keywords nobody has added a rule for yet. Harmless reorders of entryPayload are no longer refused.

Risks: Low. The safety net cannot be reached by any schema today: the meta-schema admits no keyword without a rule, and a test checks that. The entryPayload change only accepts updates whose parsed document type is identical to the stored one. Both touch only protocol version 14, which is unreleased.

Issue being fixed or feature implemented

A review of #5069 found:

  1. The v1 differ still turned every error of the compatibility validator into an internal error. fix(dpp)!: refuse token cost and unruled keyword changes on update with a consensus error (PV14) #5069 lists the known keywords, but the next keyword added without a rule would repeat the problem.
  2. The test that checks every meta-schema keyword has a rule read meta-schema v3 only. A later meta-schema diffed by the same generation would escape it.
  3. entryPayload is parsed as a set, like transient, but only transient was sorted before the diff. A reorder was refused with 10246.
  4. Nothing tested the result through block processing: a paid consensus error, a bumped nonce and a charged fee.
  5. The token cost test changed only the create and delete costs.
  6. The contract-level $defs diff, which uses the same rules, had no test for the new frozen keywords.
  7. Test helpers duplicated each other, and tokenCost, minProperties, maxProperties and contains were string literals with no property_names constant.

What was done?

Fallback for a keyword with no rule (validate_schema_compatibility v1). When the validator reports UnsupportedSchemaKeyword, v1 now returns an incompatible change at that path instead of a ProtocolError. The operation is read off the two schemas: a path the original lacks was added, one the new schema lacks was removed, and anything else was replaced. The validator stops at that keyword, so only that change is reported. The 19-keyword list from #5069 stays, so the known keywords still report every change at its own path. Other validator errors stay internal errors.

Before / after, for a keyword the meta-schema might admit later without a rule:

// stored                          // update
"someFutureKeyword": 1             "someFutureKeyword": 2
  • Before: internal error schema keyword 'someFutureKeyword' at path '/someFutureKeyword' is not supported
  • After: IncompatibleDocumentTypeSchemaError (10246), replace at /someFutureKeyword

entryPayload reorders. prepared_for_diff now sorts and deduplicates entryPayload as it does transient (TOP_LEVEL_NAME_SETS). The parse reads both as sets, and an entry frames its payload properties in name order whatever order the list gives.

// stored                          // update
"entryPayload": ["a", "b"]         "entryPayload": ["b", "a"]

A real change, such as ["a", "b"] to ["a", "c"], is still refused: 40212 from the parsed comparison.

Guard test across protocol versions. should_have_a_rule_for_every_keyword_the_meta_schema_admits now checks the meta-schema of every protocol version that selects differ generation 1. It fails loudly when such a version uses a meta-schema the test does not list.

Tests:

  • rs-dpp:
    • The fallback: add, remove, replace and nested cases.
    • entryPayload reorders and repeats.
    • All six token cost actions (add, remove, change), plus effect, gasFeesPaidBy and optional.
    • A contract $defs change under maxProperties, refused with IncompatibleDataContractSchemaError.
  • drive-abci:
    • refused_keyword_updates runs a token cost change and a written-out default through process_raw_state_transitions. Each ends as a PaidConsensusError (40212 and 10246), with the identity contract nonce bumped to 1 and a fee charged.
    • The transient test now uses the shared helper.

Cleanup:

  • property_names gains TOKEN_COST, MIN_PROPERTIES, MAX_PROPERTIES and CONTAINS.
  • parse_token_costs reads TOKEN_COST; the value is the same string.
  • doc_type_with_action_fees gives way to the more general doc_type_with_keywords.

Not changed: minProperties, maxProperties and contains stay frozen, matching "Fixed" in the book's keyword reference. Loosening them would be safe for stored documents, but that is a rule change of its own.

How Has This Been Tested?

  • cargo test -p dpp --lib on the branch as rebased onto v4.2-dev: 4885 passed, 6 ignored. The full cargo test -p dpp, including integration and doc tests, passed before the rebase.
  • cargo test -p drive-abci --lib -- data_contract_update on the rebased branch: 64 passed, including the two new end-to-end tests.
  • cargo clippy -p dpp -p drive-abci --tests: clean. rustfmt --check on the changed files: clean.

Breaking Changes

Consensus, protocol version 14 only. A document type update that only reorders or repeats entryPayload names is now accepted. A diff under a keyword with no rule would be refused with 10246 instead of failing as an internal error; the meta-schema admits no such keyword today. Protocol versions up to 13 are unchanged.

In-place changes to shipped generations

None. validate_schema_compatibility v1 is selected only by protocol version 14, which is unreleased. parse_token_costs is shared by all parser generations, but it only swaps the "tokenCost" literal for a constant with the same value, so its output is identical at every version.

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 · 52e255c

  • Bots — coderabbitai not yet · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed once the bots are done
  • Within your 5 open PRs
  • Build failed
  • Approvals — you own every area touched; none needed

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

…s as incompatible (PV14)

Follow-ups from the review of the frozen differ keywords:

- validate_schema_compatibility v1 reports a change under a keyword with
  no rule at all as an incompatible change at its path (add, remove or
  replace, read off the two schemas) instead of a ProtocolError. The
  meta-schema admits no such keyword today; this keeps a later one from
  failing an update with an internal error.
- entryPayload is sorted and deduplicated before the diff, as transient
  is: the parse reads both as sets, so a reorder is no change.
- The keyword guard test checks the meta-schema of every protocol version
  that selects differ generation 1, not only v3.
- New tests: all six token cost actions, a contract $defs change under
  maxProperties, and two drive-abci tests that run refused updates
  through block processing to a paid consensus error with a bumped
  nonce and a charged fee.
- property_names gains TOKEN_COST, MIN_PROPERTIES, MAX_PROPERTIES and
  CONTAINS; test helpers are shared instead of duplicated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 40 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: 401888b6-f59d-433a-b74c-030afc84e2bf

📥 Commits

Reviewing files that changed from the base of the PR and between e090ae2 and 52e255c.

📒 Files selected for processing (6)
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/validate_update/v1/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/schema/validate_schema_compatibility/v1/mod.rs
  • packages/rs-dpp/src/data_contract/methods/validate_update/v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs

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.

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

thepastaclaw commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 4th in line, estimated start in ~25 min (commit 52e255c)
Estimated review time once started: ~1.4 h (two-phase automated review; median of recent runs).

  • Request priority review — click to move this review to the front of the queue.

@QuantumExplorer
QuantumExplorer merged commit d7d5c84 into v4.2-dev Sep 27, 2026
15 of 17 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/differ-review-fixes branch September 27, 2026 17:51
QuantumExplorer added a commit that referenced this pull request Sep 27, 2026
…chapters

#5069 and #5074 gave the keywords the schema comparison had no rule
for a consensus error. The chapters now say so: a tokenCost change is
refused with DocumentTypeUpdateError (40212); minProperties,
maxProperties and contains changes with
IncompatibleDocumentTypeSchemaError (10246); a text-only edit of a
keyword with 10246; and a reordered entryPayload is no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants