Skip to content

refactor(platform): share the delete state checks and cover what delete rules leave alone - #5330

Merged
QuantumExplorer merged 1 commit into
v5.0-devfrom
claude/delete-constraints-review-fixes
Oct 8, 2026
Merged

QuantumExplorer merged 1 commit into
v5.0-devfrom
claude/delete-constraints-review-fixes

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: Clean-ups and extra tests for the delete rules (deleteConstraints) that landed in #5319, from its code review, which finished after that PR merged. The checks every owner's delete runs (the document exists, the signer owns it) now live in one function that both versions of delete validation share, instead of being copied. Both rule keywords are parsed under one version switch. A delete with rules converts the stored document once instead of twice. New tests pin what the rules leave alone: moderators and expiry still delete, and a banned owner is still held to them.

Value: Less duplicated consensus code to keep in step, slightly less work per gated delete, and tests that would catch a later change routing moderator deletes or ttl expiry through the rules, or letting a barred owner skip them. A docs gap in the References chapter is closed.

Risks: Low. Nothing a user or a contract can observe changes. The one edit to a generation shipped before protocol version 14, document delete state validation 0, moves its body into a shared function with the same checks, in the same order, with the same billing and the same errors (see below). Everything else is protocol version 14 code, not yet released, or tests and docs.

Issue being fixed or feature implemented

The review of #5319 (deleteConstraints) finished after it merged. This PR applies its findings, except one design follow-up (below).

What was done?

No behaviour changes; each item is a refactor, a doc fix or a test.

Shared delete checks. Document delete state validation 0's checks (base transition, document type, stored document fetch, owner) move into fetch_owned_document, which returns the owned document or the first refusal. Version 0 returns its errors; version 1, which judges deleteConstraints, builds on the document it returns instead of repeating about 45 lines.

One parse dispatch. apply_property_constraints version 0 now also reads deleteConstraints (apply_delete_constraints_v0), so a single match on parse_property_constraints covers both keywords and they can't drift apart. The separate apply_delete_constraints dispatcher is gone.

One conversion per gated delete. State validation 1 converts the stored properties to a Value once and passes it to both read_delete_constraint_aggregates and validate_delete_constraints (which now takes the Value). Before, each cloned the document.

A documented assumption. read_delete_constraint_aggregates reads committed state, so it leaves out writes earlier in the same batch. That is sound only while a document batch carries one transition, and the function now says so, as the write path's reader already did.

Docs. The References chapter said deleting a referenced document never looks at referrers. It now notes that a deleteConstraints rule counting referrers by the target's $id holds a deletableDocument target in place until the last one is gone.

Tests.

  • contract_user_moderation/tests/delete_constraints.rs: a moderator deletes a post its owner's rule refuses; a banned owner's delete passes the moderation gate and is still judged (refused 40147 by the rule, accepted when the rule holds).
  • document_ttl: a note its owner may not delete (refused 40147) still expires on time.
  • property_constraint_aggregates_tests: the same own-type count on a contested type is refused in propertyConstraints and accepted in deleteConstraints.
  • The billing test now asserts each read is charged on both the accepted and the refused delete, instead of asserting the two charges are equal (which held only because the trees had the same shape).
  • Small test clean-ups: an inline drive::query:: path imported, a throwaway tuple removed.

Not done here: letting a permanentDocument reference target a type whose delete rule proves nothing points at it. That is a feature of its own, listed as a follow-up in #5319.

In-place changes to shipped generations

  • Document delete state validation 0 (state_v0, shipped since protocol version 1): its body moves into fetch_owned_document, and validate_state_v0 returns that helper's errors. The checks run in the same order, with the same reads billed the same way and the same errors, so its outcome is unchanged at every protocol version. check_ownership is private to the module again.
  • The batch transformer's property_constraint_aggregates.rs (shared with earlier versions): the reader takes prebuilt values. It reads a total only for a rule that reads one, which only the protocol version 14 parser produces, so earlier versions read and bill nothing, as before.
  • Everything else (parser generation 3, validate_delete_constraints, state validation 1) is selected by protocol version 14 only, which is not yet released.

How Has This Been Tested?

  • The full dpp lib suite passes (5475).
  • Targeted drive-abci suites pass (232): delete_constraints property_constraints document_ttl contract_user_moderation deletion commit_reveal_lookup deletable_document_reference, including the four new tests.
  • cargo clippy -p dpp --features all_features --all-targets, cargo clippy -p drive-abci --all-targets and cargo fmt --check are clean.

Breaking Changes

None. No consensus behaviour changes at any protocol 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 · 8148a3f

  • Bots — coderabbitai not yet · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

…te rules leave alone

Follow-ups to the deleteConstraints review (#5319):

- Document delete state validation 0's checks (base transition, document
  type, stored document, owner) move into `fetch_owned_document`, which
  returns the owned document; version 0 keeps its outcome and billing, and
  version 1 builds on it instead of repeating them.
- `apply_property_constraints` version 0 also reads `deleteConstraints`, so
  one dispatch on `parse_property_constraints` covers both keywords.
- A gated delete converts the stored properties to a value once, for both
  the totals and the rules.
- `read_delete_constraint_aggregates` documents that it leaves out the
  batch's own earlier writes, sound only while a batch carries one
  transition.
- Tests: a moderator deletes what the owner's rules refuse, a banned
  owner's delete is still judged, a ttl expires a document its owner may not
  delete, and a contested type's own total is accepted in delete rules and
  still refused in propertyConstraints. The billing test asserts each read
  is charged, not that the two charges are equal.
- References chapter: a deletableDocument target can refuse its owner's
  delete while documents count toward a rule matched by its `$id`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added this to the v5.0.0 milestone Oct 8, 2026
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 36 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: dashpay/platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a8c7a80e-9a9a-4216-ad5c-8718fdedbb4b
📥 Commits

Reviewing files that changed from the base of the PR and between 575b7a3 and 8148a3f.

📒 Files selected for processing (16)
  • book/src/contract-keywords/refers-to.md
  • book/src/data-model/documents.md
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/property_constraint_aggregates_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/versioned_methods.rs
  • packages/rs-dpp/src/data_contract/document_type/v2/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_delete_transition_action/state_v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_delete_transition_action/state_v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/delete_constraints.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/document_ttl.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/transformer/v0/property_constraint_aggregates.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/delete_constraints.rs
  • packages/rs-platform-version/src/version/v14.rs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 commented Oct 8, 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-10-08T11:32:51.965Z

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 8, 2026
@thepastaclaw

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because the new head is waiting for the 30-minute push debounce.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 8148a3f. Normal review starts when eligible; priority review starts as soon as a slot is available.

@QuantumExplorer
QuantumExplorer merged commit 91e2ae6 into v5.0-dev Oct 8, 2026
18 of 19 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/delete-constraints-review-fixes branch October 8, 2026 11:38
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