Skip to content

feat(platform)!: contract references may require the referenced contract's owner relation and config flags - #4915

Merged
QuantumExplorer merged 3 commits into
v4.2-devfrom
claude/blissful-archimedes-338473
Sep 22, 2026
Merged

QuantumExplorer merged 3 commits into
v4.2-devfrom
claude/blissful-archimedes-338473

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

#4909 introduced contractRequirements on refersTo: { "type": "contract" } with moderation: "elected", and #4913 added minimumAgeSeconds and minimumSecondsSinceUpdate. This adds four more requirements on the referenced contract, following the same grammar: each key names an aspect of the referenced contract and its value the requirement on it, closed sets of values, checked when the referring document is written against the contract already fetched for the existence check, so none costs a further read. An unmet requirement refuses the write with the existing ReferencedContractRequirementNotMetError (40135), field the key and required the value as the schema spells it. No new error code and no new StateError discriminant.

The first user is the moderation charter contract's targetContractId (#4898), but the requirements are general. Two consequences for #4898 worth deciding there: the charter's targetContractId can now declare owner: "other" if owners may not charter a team over their own contract, and a target declared readonly: true makes minimumSecondsSinceUpdate moot for it, since a read-only contract is never updated again.

What was done?

Two commits, one per group of requirements.

Commit 1: owner ("self" | "other"). self requires the referenced contract's owner to be the $ownerId of the referring document (the transition's owner), a write gate like the $ownerId property agreement of a document reference; other requires it not to be. Modelled as ContractReferenceOwner { Writer, Other } with wire names self and other (as_str / from_wire_name, like ContractReferenceModeration). The requirements are now checked against a small ReferringWrite { owner_id, block_time_ms } instead of the block time alone; validate_document_references_v0 already had the owner id.

Commit 2: readonly, keepsHistory, ownerProtected, read from the referenced contract's config:

  • readonly: true requires config().readonly(), a contract that can never be updated again. Only true is meaningful, so the parser and the meta-schema ("const": true) refuse false.
  • keepsHistory: true requires config().keeps_history(), the same way.
  • ownerProtected: true | false requires an elected moderation declaration whose owner_protected equals the value. A contract with no moderation or non-elected moderation meets neither value, so the check implies elected moderation without the schema having to say moderation: "elected" too.

Surfaces extended in place (protocol version 14 is unreleased): ContractReferenceRequirements / ContractReferenceRequirement in rs-dpp, the contractRequirements parser, meta-schema v3, Display of the reference target, the 40135 error docs, the wasm-dpp2 contractRequirements TypeScript type and reference_to_js, the v14 changelog item 24 and the book paragraph on referencing an elected contract.

How Has This Been Tested?

  • rs-dpp: parser tests for every new key (accepted values, refused values with messages naming the key and the allowed values), meta-schema v3 accept and reject tests, Display cases, unit tests of is_met_by for the owner relation and each config flag (including appointed and elected moderation for ownerProtected), and the update compatibility test now covers a changed owner, a changed ownerProtected, an added readonly and a removed keepsHistory (each reported at its own path).
  • rs-drive-abci: document creation tests for every requirement, met and unmet: owner self/other against a contract owned by the writer versus the fixture owned by someone else; readonly and keepsHistory against a contract whose config sets the flag versus the plain fixture; ownerProtected against an elected declaration with the flag set, one with it unset, and a contract with no moderation at all. The reference-validation test helper's setup step now receives the reference targets (the writer's identity among them) so a test can write a contract owned by the writer.
  • Ran locally: cargo test -p dpp --lib (targeted: contract_refers_to contract_requirements reference_targets should_display_reference_targets meta_validators owner_requirement config_flag contract_reference_requirement_changes), cargo test -p drive-abci --lib -- referenced_contract owned_contract readonly_contract history_keeping owner_protection, cargo check -p wasm-dpp2 --target wasm32-unknown-unknown, cargo clippy -p dpp --all-targets --features validation,fixtures-and-mocks, cargo clippy -p drive-abci --lib --tests, cargo fmt --all.

#4914 merged in. The electionDelay PR landed on v4.2-dev while this one was open and touched the same type, meta-schema block and the drive-abci elected-contract test helper. The merge commit keeps both key sets (moderation: "elected" | "electionOpen" beside the four keys here); the elected-contract helper now takes the election delay, the recorded creation time and the owner protection flag, and all 29 reference tests (the four electionOpen ones included) pass on the merged tree.

Breaking Changes

Consensus: a document type may now declare requirements a referenced contract did not have to meet before, and a write against a contract that does not meet one is refused with 40135. Contracts on protocol version 14 (unreleased) only; existing declarations are unaffected. Meta-schema v3 gains four contractRequirements keys, extended in place.

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

Summary by CodeRabbit

  • New Features

    • Contract references can now require ownership by the writing party or another party.
    • Added support for requiring referenced contracts to be read-only, retain document history, or use owner protection for elected moderation.
    • These requirements are validated during document writes and clearly report unmet conditions.
    • Public interfaces now expose the new contract-reference options with validation for supported values.
  • Documentation

    • Updated contract-reference guidance and error descriptions to cover the new requirements.

PR Hygiene · 4effae2

  • Bots — coderabbitai ✓ · 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 running
  • Approvals — you own every area touched; none needed

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

QuantumExplorer and others added 2 commits September 22, 2026 22:47
…act's owner relation to the writer

`contractRequirements` on a `contract` `refersTo` gains `owner`: `"self"`
requires the referenced contract to be owned by the `$ownerId` of the
referring document (the transition's owner), a write gate like the
`$ownerId` property agreement of a document reference; `"other"` requires
it not to be. The check runs against the contract already fetched for the
existence check, so it costs no further read, and refuses the write with
the existing `ReferencedContractRequirementNotMetError` (40135), field
`owner`, required `self` or `other`.

The requirements are now checked against a `ReferringWrite` (the writer's
id and the block time) instead of the block time alone. Meta-schema v3,
the parser, the wasm-dpp2 surface, the v14 changelog and the book are
extended in place, protocol version 14 being unreleased.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…act to be read-only, keep history or protect its owner

`contractRequirements` on a `contract` `refersTo` gains three flags read
from the referenced contract's config: `readonly: true` requires a
read-only contract, one that can never be updated again; `keepsHistory:
true` requires one keeping its history; `ownerProtected: true | false`
requires an elected moderation declaration whose owner protection flag
has that value, so a contract with no moderation or non-elected
moderation meets neither value and the check implies elected moderation
without the schema having to say so. Only `true` is meaningful for the
first two, so the parser and the meta-schema (`const: true`) refuse
`false`.

An unmet flag refuses the write with the existing
`ReferencedContractRequirementNotMetError` (40135), field the key and
required `true` or `false`. Meta-schema v3, the parser, the wasm-dpp2
surface, the v14 changelog and the book are extended in place, protocol
version 14 being unreleased. The drive-abci reference test helper for an
elected contract takes the owner protection flag, and a new one writes a
contract with an adjusted config.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: df84105c-8fc8-4787-98a5-3a37158a91b4

📥 Commits

Reviewing files that changed from the base of the PR and between 58e471a and 4effae2.

📒 Files selected for processing (18)
  • book/src/data-model/contract-moderation.md
  • packages/rs-dpp/schema/meta_schemas/document/v3/document-meta.json
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/validate_update/common/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_contract_requirement_not_met_error.rs
  • packages/rs-dpp/src/validation/meta_validators/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/creation.rs
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-keeps-history-contract-ref.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-owner-other-contract-ref.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-owner-protected-contract-ref.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-owner-self-contract-ref.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-readonly-contract-ref.json
  • packages/rs-platform-version/src/version/v14.rs
  • packages/wasm-dpp2/src/consensus_error.rs
  • packages/wasm-dpp2/src/data_contract/document_type_reference.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds owner, readonly, keepsHistory, and ownerProtected requirements to contract references. It parses and serializes these values, evaluates them during document validation, updates compatibility checks, and adds end-to-end tests.

Changes

Contract reference requirements

Layer / File(s) Summary
Requirement schema and parsing
packages/rs-dpp/schema/..., packages/rs-dpp/src/data_contract/document_type/..., packages/wasm-dpp2/src/..., book/src/...
Contract references accept owner relationships, readonly mode, history retention, and owner-protection requirements. Parsers validate their types and values. Exported interfaces serialize the new fields.
Requirement evaluation and representation
packages/rs-dpp/src/data_contract/document_type/property/mod.rs
Requirements use the referring writer and block time. Evaluation checks contract ownership and configuration. Serialization, ordering, emptiness checks, display text, and unit tests include the new fields.
Schema compatibility and validation wiring
packages/rs-dpp/src/validation/..., packages/rs-dpp/src/data_contract/document_type/methods/..., packages/rs-drive-abci/src/execution/...
Meta-schema and compatibility tests cover valid, invalid, and changed requirements. Document validation passes ReferringWrite into requirement checks.
Reference validation fixtures and scenarios
packages/rs-drive-abci/src/execution/.../creation.rs, packages/rs-drive-abci/tests/supporting_files/contract/...
Test helpers create configurable referenced contracts. New scenarios cover owner, readonly, history-retention, and owner-protection requirements.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant DocumentCreation
  participant DocumentReferenceValidation
  participant ContractReferenceRequirements
  participant ReferencedContract
  DocumentCreation->>DocumentReferenceValidation: validate referenced contract
  DocumentReferenceValidation->>ContractReferenceRequirements: pass ReferringWrite
  ContractReferenceRequirements->>ReferencedContract: check owner and configuration
  ReferencedContract-->>ContractReferenceRequirements: requirement result
  ContractReferenceRequirements-->>DocumentReferenceValidation: success or first unmet requirement
Loading

Suggested reviewers: lklimek, shumkov

Merge Risk: ⚪ Minimal · up to 4effa

Protocol v14 contract references now support owner and configuration requirements with corresponding validation and compatibility coverage. No merge-blocking risk is established by the supplied evidence.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 95.38% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 65 functions across 11 files. (7 skipped: 7…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding owner-relation and configuration-flag requirements to contract references.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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 the waiting-bots Waiting for the review bots to report on this head label Sep 22, 2026
@github-actions github-actions Bot modified the milestone: v4.2.0 Sep 22, 2026
@thepastaclaw

thepastaclaw commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ DEGRADED — Queued for automated review — 26th in line, estimated start in ~29 h (commit 4effae2)
Estimated review time once started: ~2.3 h (two-phase automated review; median of recent runs).
The primary review models are currently out of quota; this review will run on stand-in models and be marked as degraded.

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

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

Download the preview from the workflow artifacts.
To view locally: download the artifact, unzip, and open index.html.

Updated at 2026-09-22T17:09:43.787Z

Resolves the overlap with #4914 (electionDelay + `moderation: "electionOpen"`):
both sets of `contractRequirements` keys are kept in the type, the parser
tests, the meta-schema, the wasm-dpp2 surface, the book and the changelog.
The drive-abci elected-contract test helper takes the election delay, the
recorded creation time and the owner protection flag, and every helper's
setup closure receives the reference targets.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@QuantumExplorer
QuantumExplorer merged commit 8a0befd into v4.2-dev Sep 22, 2026
48 of 49 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/blissful-archimedes-338473 branch September 22, 2026 18:13
QuantumExplorer added a commit that referenced this pull request Sep 22, 2026
…istration, agreement refused (#4922 port)

Takes from the independent implementation in #4922 what it did better:

- `class_methods/parse_typed_array` is its own versioned method run before
  the scalar parser, whose signature and "array" arm are restored
  byte-for-byte; below protocol version 14 the historical refusal is reached
  exactly as before.
- The `maxItems` requirement and its `SystemLimits::max_typed_array_items`
  cap move to the generation 3 driver under full validation, like the other
  registration limits, so a later, lower cap can never make a stored
  contract unreadable; `TypedArrayProperty::max_items` is `Option<u16>`.
- drive-abci refuses a `propertyAgreement` on a typed array on either side
  (fixture + test): the write-time check compares index key encodings, which
  a list does not have.
- The ranked key-length check skips typed arrays so the type error is the
  one reported; a test pins it.
- Byte array items whose bounds pin 20, 32 or 36 bytes read back as
  `Bytes20/32/36`, boolean items must be 0 or 1, item bounds are read at u16
  like the scalar bounds.
- Meta-schema v3: `items` is allowed on `type: array` only.
- wasm-dpp2: `maxItems` is optional on the surface; a mocha spec covers the
  accessors.

Merges v4.2-dev (#4915).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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