feat(platform)!: present and absent tests in propertyConstraints rules (PV14) - #5037
Conversation
…s (PV14)
A propertyConstraints condition may now be `{ "present": path }` or
`{ "absent": path }`: whether the document holds the property, the one
way to tell a property left out from one set to 0. A presence test may
name a property of any type, an object included, but not a transient
one; it counts as one node and never faults.
Extended in place in meta-schema v3 and parse_property_constraints 0:
every declaration valid before parses and evaluates as it did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 9 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
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. Comment |
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-27T07:00:50.160Z |
|
🔍 Review in progress — actively reviewing now (commit c8ccb09) · triage: normal |
#5037 squash-merged into v4.2-dev as e8c4d1b, whose tree is identical to c8ccb09, the #5037 commit this branch is built on; every conflict resolved to this branch's side, which is that commit plus this PR's own changes. The merged tree equals 8c94d74's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Basic explanation
What this does: A
propertyConstraintsrule can now test whether a document holds a property at all:{ "present": "discount" }or{ "absent": "discount" }. Until now a rule could only compare numbers, and a property the document leaves out read as 0. So "no discount given" and "a discount of 0" looked the same.Value: Contract authors can write rules such as "a discount is optional, but when given it must be above 0" or "a closed order (status 3) must have a
closedAt". A document schema can't say these today:dependentRequiredonly ties one property's presence to another's, and there is no JSON Schemaif/then. The test works on properties of any type (strings, identifiers, objects), not only integers.Risks: Low. This changes consensus validation, but only in protocol version 14, which is not on mainnet. It only widens what is accepted: every rule that registered before still registers and evaluates the same way. Devnets on an earlier 4.2 build would refuse a contract using the new tests, so their nodes need to upgrade together.
Issue being fixed or feature implemented
Follow-up to #4962 and #5036. An operand reads a missing property as 0 (or as its
ifAbsentdefault), so a rule could not tell "left out" from "set to 0". The only workaround was anifAbsentdefault outside the property's range, and that only works for integers.What was done?
Grammar
Two new conditions sit next to the comparisons, and they nest under
anyOf,allOfandnot:{ "present": path }holds if the document holds the property with a value other than null.{ "absent": path }holds if the document leaves it out or sets it to null. That is exactly when an operand would read 0 or itsifAbsentvalue.Before, this rule was refused when the contract registered (the meta-schema didn't know
absent). Now it registers:{ "price": 100 }(no discount){ "price": 100, "discount": 10 }{ "price": 100, "discount": 0 }discountGivenAboveZeroNotMetWritten with an operand alone,
{ "greaterThan": ["discount", 0] }refuses the first document too, because the missing discount reads as 0.What a presence test may name
"meta") or a member of one ("meta.tag"). An operand still needs an integer property.$ownerId): the meta-schema refuses the$on registration, and the parser refuses the path on a stored parse.max_property_constraint_nodes, and it never faults.Code
property_constraints/mod.rs:PropertyConstraintgainsPresent(String)andAbsent(String), evaluated byis_present, which matchesproperty_value's idea of absent.PropertyRead(ValueorPresence) andPropertyConstraint::property_reads()tell the two kinds of read apart.property_paths()still lists every path.apply_property_constraints_v0: value reads keep the integer check. Presence reads resolve through the property tree with a newproperty_at_path, which walks objects. Both kinds get the transient check.presentandabsenton thepropertyConstraintdef, and thepropertyConstraintPathand keyword descriptions updated.SystemLimits,DocumentTypeV2andPROPERTY_CONSTRAINTSdocs.How Has This Been Tested?
property_constraints/tests.rs:try_from_schema/v3/property_constraints_tests.rs: on both paths, presence of a string, a float, an array, an object and a nested member, refusal of a missing path and of a path through a non-object, refusal of a transient property or object,$ownerIdrefused, and the meta-schema refusing malformed shapes.batch/tests/document/property_constraints.rs: theofferfixture gainsdiscountGivenAboveZero, andshould_tell_a_property_left_out_from_one_set_to_zeroruns real creates (one refused with 10422, two accepted).cargo test -p dpp --lib(4851 passed),cargo test -p drive-abci --lib property_constraints(10 passed),cargo clippy -p dpp --all-features --all-targets -- -D warnings,cargo clippy -p drive-abci --all-targets -- -D warnings.Breaking Changes
Consensus, protocol version 14 only: contracts may now register rules using
presentandabsent, which earlier 4.2 builds refuse. Meta-schema v3,parse_property_constraints0 andvalidate_property_constraints0 were introduced in protocol version 14, which is not released on mainnet, so they are extended in place. Every declaration valid before parses and evaluates identically. Protocol version 13 and earlier ignore the keyword.Rust API:
PropertyConstraintgains two variants, so an exhaustivematchon it needs two new arms.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
c8ccb09/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are donejs-wasm-sdk(packages/js-evo-sdk/README.md) — shumkovdpp— you own itrs-drive-abci— you own itWhen every box is checked the
PR Hygienecheck passes and this can merge.