Skip to content

feat(dpp)!: refersTo propertyAgreement binds referring and referenced document properties - #4505

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
feat/refers-to-property-agreement
Aug 28, 2026
Merged

feat(dpp)!: refersTo propertyAgreement binds referring and referenced document properties#4505
QuantumExplorer merged 1 commit into
v4.2-devfrom
feat/refers-to-property-agreement

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

indexOnly follow-up: refersTo property agreement. A like references a post and both carry a hashtag, but nothing bound them — a like under #dash could reference a post living under #btc, silently corrupting every hashtag-scoped count and ranking. Contracts can now declare that a property of the referring document must EQUAL a property of the referenced document, enforced by consensus at write time.

What was done?

Schema. A permanentDocument reference may declare "propertyAgreement": { "<referring property>": "<referenced property>" } (1–10 pairs, dotted paths admitted). Meta-schema v3 gains the keyword — the file is explicitly editable until the PV14 release ships — and the parser (apply_property_reference, PV14-only) accepts it only on permanentDocument references. DocumentPropertyReferenceTarget::PermanentDocument gains the field; contracts serialize their schemas and rebuild document types on load, so nothing changes on the wire.

Zero new reads — the headline of the design pass. Both validation layers already fetch exactly what agreement needs:

  • Contract registration (data_contract_reference_validation, in place): the referenced doctype is already resolved (foreign contracts memoized + billed). Declarations are validated there — both properties exist, are plain values (no object containers), the referring property is not the reference itself, and the two share one value kind (sizes may differ; Identifier with or without its own reference annotation counts as one kind). A cross-kind equality could never be satisfied and would brick every create of the doctype, so it is refused at registration with the new ReferencedDocumentPropertyAgreementInvalidError (40126).
  • Document write time (document_reference_validation, in place): the full referenced document was already fetched for the existence check and its body discarded. Now each pair is compared — through the two doctypes' own key encodings, giving one deterministic normal form per value kind, so an identifier stored as bytes and one carried as an identifier compare equal. Any absence or inequality → the new ReferencedDocumentPropertyMismatchError (40127). Replace transitions re-validate when the reference OR any referring agreement property changed (the changed-fields gate now binds the agreement's referring properties too).

Both errors are appended to StateError (append-only wire enum, discriminants pinned 99/100).

How Has This Been Tested?

  • dpp parser (4 tests): the keyword parses and populates the target on permanentDocument; refused on other reference types; empty map refused; non-string values refused.
  • Contract registration (3 tests): valid agreement registers; missing referenced property refused; cross-kind (string↔integer) refused — each pinned to the typed error.
  • Write time: the yappr-likes fixture now declares { "hashtag": "hashtag" } on like.postId, so every existing lifecycle test exercises the agreeing direction implicitly; a new test pins the refusal of a #btc like on a #dash post.
  • Replace side: a new test creates an agreeing note+message pair, then replaces ONLY the message's referring property — proving the agreement-aware changed-fields gate fires with the reference untouched.
  • Full document pipeline suite (172 tests), drive indexOnly e2e (21, parsing the updated fixture), workspace --all-targets and clippy -D warnings clean.

Breaking Changes

Consensus: a new contract keyword and two new consensus errors, all PV14-only (unreleased) and extended in place per the stack convention. Contracts without the keyword parse and validate byte-identically; below PV14 the keyword is rejected by meta-schema v2 as before.

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

Remaining indexOnly follow-ups (tracked, not here): platform-test-suite functional spec, sum axes via SumItem, timeRange buckets.

🤖 Generated with Claude Code

…d document properties

A permanentDocument reference may now declare
propertyAgreement: { <referring property>: <referenced property> } — each
pair must hold as an EQUALITY between the referring document's value and
the referenced document's, enforced by consensus at document write time.
For Yappr this binds a like's hashtag to its referenced post's, so a like
under #dash can never point at a post living under #btc.

Zero new reads: both validation layers already fetch exactly what
agreement needs. Contract registration already resolves the referenced
doctype (memoized + billed) — declarations are validated there: both
properties exist, are plain values, and share one value kind (identifier
with or without its own reference annotation counts as one kind; a
cross-kind equality could never be satisfied and would brick the
doctype). Document write time already fetches the full referenced
document for the existence check and discarded the body — now each pair
is compared through the two doctypes' own key encodings (one
deterministic normal form per value kind, so identifiers stored as bytes
and carried as identifiers compare equal). Replaces re-validate when the
reference OR any referring agreement property changed.

Meta-schema v3 gains the keyword (editable until the PV14 release
ships); the parser accepts it only on permanentDocument references, 1-10
pairs. Two consensus errors appended:
ReferencedDocumentPropertyAgreementInvalidError (40126, registration)
and ReferencedDocumentPropertyMismatchError (40127, write time). The
yappr-likes fixture now declares the hashtag agreement, so every
existing lifecycle test exercises the agreeing direction implicitly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added this to the v4.2.0 milestone Aug 28, 2026
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 21 minutes.

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ea9c497-a3f2-4b3e-8ad4-e2216d88b95f

📥 Commits

Reviewing files that changed from the base of the PR and between 51fd54b and 14a9d9f.

📒 Files selected for processing (20)
  • book/src/drive/index-only-document-types.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/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-dpp/src/errors/consensus/codes.rs
  • packages/rs-dpp/src/errors/consensus/state/document/mod.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_document_property_agreement_invalid_error.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_document_property_mismatch_error.rs
  • packages/rs-dpp/src/errors/consensus/state/state_error.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/index_only.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/replacement.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_common/data_contract_reference_validation/v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/mod.rs
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-kind-mismatch.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-missing-property.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-valid.json
  • packages/rs-drive/tests/supporting_files/contract/yappr-likes/yappr-likes-contract.json
  • packages/wasm-dpp/src/errors/consensus/consensus_error.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.

@thepastaclaw

thepastaclaw commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

🕓 Ready for review — next in queue (commit 14a9d9f)
Queue position: 1/2 · 1 review active
ETA: start ~10:50 UTC · complete ~11:11 UTC (median 21m across 30 recent reviews; 2 slots)
Queued 13m ago · Last checked: 2026-08-28 10:50 UTC

@github-actions

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-08-28T10:36:42.249Z

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.79646% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.37%. Comparing base (51fd54b) to head (14a9d9f).

Files with missing lines Patch % Lines
...document_type/class_methods/try_from_schema/mod.rs 71.02% 51 Missing ⚠️
...n/document/document_reference_validation/v0/mod.rs 55.88% 30 Missing ⚠️
...ommon/data_contract_reference_validation/v0/mod.rs 73.07% 14 Missing ⚠️
...tion/state_transitions/data_contract_create/mod.rs 92.50% 3 Missing ⚠️
...pp/src/data_contract/document_type/property/mod.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4505      +/-   ##
============================================
+ Coverage     82.98%   83.37%   +0.38%     
============================================
  Files          2744     2773      +29     
  Lines        368407   373254    +4847     
============================================
+ Hits         305740   311200    +5460     
+ Misses        62667    62054     -613     
Components Coverage Δ
dpp 82.76% <70.94%> (-0.59%) ⬇️
drive 82.22% <ø> (+0.91%) ⬆️
drive-abci 86.87% <70.62%> (+0.98%) ⬆️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.92% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 48.41% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@QuantumExplorer

Copy link
Copy Markdown
Member Author

Reviewed, nice feature

@QuantumExplorer
QuantumExplorer merged commit 6a34ba2 into v4.2-dev Aug 28, 2026
33 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/refers-to-property-agreement branch August 28, 2026 10:55
QuantumExplorer added a commit that referenced this pull request Aug 28, 2026
…eement

The reference_targets_are_exhaustively_mirrored test's PermanentDocument
literal predates the property_agreement field (#4450 x #4505 parallel
merge) — E0063 in dpp's lib tests on v4.2-dev.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
QuantumExplorer added a commit that referenced this pull request Aug 28, 2026
…rence metadata

PR #4450 (refersTo reference metadata) and PR #4505 (propertyAgreement on
permanentDocument references) were developed in parallel and merged
without a rebase between them: #4450's exhaustive destructure of
DocumentPropertyReferenceTarget::PermanentDocument does not mention the
propertyAgreement field #4505 added, so v4.2-dev fails E0027 in
wasm-dpp2 (and everything downstream: wasm-sdk, js-evo-sdk).

Rather than ignoring the field, surface it: a permanentDocument
reference object now carries propertyAgreement as a plain
{ referring: referenced } record when the declaration has one, absent
otherwise — matching the schema's own omission and the absent-field
convention of the other optional target fields. TS custom section,
specs (presence + absence) and the js-evo-sdk README updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants