Repository navigation
feat(platform)!: derived index properties read a removed document's kept fields (PV14) - #5223
Conversation
…ept fields (PV14) A derived index property reading through a moderatedDocument reference could name only the referenced $ownerId, because the removal record a moderator's deletion leaves kept nothing else. Since #5219 the record also keeps the fields the type lists under moderatorAbilities.deleteKeepsFields, so a derived property may now read one of those too (a kept path, or a path inside a kept object), e.g. a reply indexed by postId.hashtag. - dpp: the kept check moves from the name parse to resolve_derived_index_properties, where the referenced type is known; $creatorId stays refused, since no record keeps it. is_kept_path and kept_value_at move to config::moderation, shared by the parser, Drive and the moderatedDocument pair check. - drive: once the referenced document is removed, derived values come from its removal record (owner, or the kept value decoded on first use); a field the record does not keep is an error, never a key under null. - Book and v14 note 65 updated; dpp, helper and drive-abci e2e tests added. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-30T14:27:19.816Z |
|
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 configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughDerived indexes through moderated-document references can now use fields retained in removal records, in addition to the owner. Registration validates retained paths, and Drive reads retained values when it materializes derived indexes. ChangesModerated-reference derived indexes
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant Moderator
participant ContractDocumentRemoval
participant derived_index_values
participant CommittedStateProofQuery
Moderator->>ContractDocumentRemoval: retain configured fields on removal
derived_index_values->>ContractDocumentRemoval: read owner and retained values
derived_index_values->>CommittedStateProofQuery: provide materialized index values
CommittedStateProofQuery-->>derived_index_values: query matching indexed replies
Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is established. Retained-field indexes appear consistent across registration and removal-record reads; merge after normal checks and the planned coordinated PV14 upgrade. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new index access remains restricted to same-contract references and explicitly retained, fixed fields. No newly introduced authorization bypass was demonstrated. Recovery across interrupted moderation, retention-policy changes, and version rollback is only partially established. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
🕓 Queued for automated review — 1st in line, estimated start in ~35 min (commit 0ff5cfc)
|
|
Reviewed |
Basic explanation
An index can hold a value of the document a reference points at, such as a reply indexed by its post's owner (
postId.$ownerId, #5216). When the reference is amoderatedDocumentone, the post can be removed by a moderator, and Drive then reads the value from the post's removal record instead. Until now that record kept only the owner, so the owner was the only value such an index could hold.Since #5219 a post type can list fields its removal record keeps public (
moderatorAbilities.deleteKeepsFields), such as a hashtag. This PR lets an index read those kept fields through amoderatedDocumentreference too. A reply can now be indexed by the hashtag of the post it replies to, and it stays filed under that hashtag after a moderator removes the post.Issue being fixed or feature implemented
Follow-up to #5216 (derived index properties) and #5219 (
deleteKeepsFields). ThemoderatedDocumentpair check already reads kept fields from a removal record; derived index values read only the owner.Before, this contract was refused at registration:
After, it registers.
[["postId.hashtag", "==", "dash"]]finds the replies to posts taggeddash, before and after a moderator removes the post. An edit or deletion of a reply after the removal finds its entry under the hashtag the record kept.What was done?
Registration (dpp). Through a
moderatedDocumentreference, a derived field may be:$ownerId, as before;deleteKeepsFields;postId.meta.topicwhenmetais kept whole).Every other #5216 rule still applies: the field must be fixed once written and indexable. The kept check needs the referenced type, so it moved from
parse_derived_index_property_nametoresolve_derived_index_properties(derived_index_field_errornow takes the reference kind).$creatorIdstays refused in the name parse, since no record keeps it. A property the record does not keep is refused withInvalidContractStructure(10231), saying to list it underdeleteKeepsFields.Shared helpers.
is_kept_pathandkept_value_atmoved from drive-abci's reference validation (privateis_kept/kept_value) todpp::data_contract::config::moderation. The parser, Drive and themoderatedDocumentpair check now share one definition of "kept" and one read of a kept value.Drive.
ReferencedValues::RemovedOwner(Identifier)becameRemoved(Box<ContractDocumentRemoval>).removed_document_valuereturns:$ownerId;A field the record does not keep is
CorruptedCodeExecution, never a key under a value the entry was not written under. A record whose values do not decode isCorruptedDriveState.How Drive gets a derived value. Drive reads the removal record only when the referenced document is no longer in state, and only through a
moderatedDocumentreference. It always tries the document first.flowchart TD A["Drive keys a reply: insert, replace, delete,<br/>moderator delete or restore, ttl expiry"] --> B{"Values already carried<br/>for this postId?"} B -- "yes: a create, from its reference validation,<br/>or a replace's old version, from the new one" --> K["Use the carried values<br/>nothing read"] B -- no --> C{"Reply holds a postId?"} C -- no --> N["Value: null<br/>nothing read"] C -- yes --> D{"Dry run?"} D -- yes --> E["Price the worst case: the post read,<br/>plus the removal record read for moderatedDocument<br/>Value: a placeholder of the field's type"] D -- no --> F["Read the post at its id (billed)"] F --> G{"Post in state?"} G -- yes --> H["Value read from the post"] G -- no --> I{"Reference kind?"} I -- permanentDocument --> X1["Error: CorruptedDriveState<br/>its documents never leave state"] I -- moderatedDocument --> J["Read the post's removal record (billed)"] J --> L{"Record there and not restored?"} L -- no --> X2["Error: CorruptedDriveState<br/>neither in state nor removed on the record"] L -- yes --> M{"Field the index reads?"} M -- "$ownerId" --> O["Owner kept in the record"] M -- "kept field, or a path<br/>inside a kept object" --> P["Kept values decoded once per reference<br/>Value as the post held it, null if it held none"] M -- "anything else" --> X3["Error: CorruptedCodeExecution<br/>registration refuses such a field"]A create can not newly refer to a removed document, so only later writes of a reply (replace, delete, moderator delete or restore, expiry) ever reach the record.
Unchanged:
Docs. Book
derived-index-properties.md(example, the "removed referenced document" step, the registration rule) anddeletion.md(a kept value can be indexed through a reference); v14 note 65.In-place changes to shipped generations
None shipped. Parser generation 3,
create_document_types_from_document_schemas1, Drive's derived-value reads and document reference validation 0's pair check are protocol version 14 only. PV14 is unreleased, and these are edited in place. The pair check's behaviour is unchanged: its helpers only moved crates.How Has This Been Tested?
dpp:
should_admit_a_field_a_moderated_posts_removal_record_keepscovers a kept field (full validation and stored-contract parse) and a path inside a kept object.should_refuse_a_field_a_moderated_posts_removal_record_does_not_keepcovers a type keeping nothing, a type keeping another field, and$creatorId.should_read_a_kept_path_or_a_path_inside_a_kept_objectis a unit test for the shared helpers.drive-abci e2e
should_read_a_kept_field_of_a_removed_post_from_its_removal_record. It files replies under a post's kepttext, removes the post, then checks:Mutation-checked: with Drive reading null instead of the kept value, the edit fails.
cargo clippy -p dpp -p drive -p drive-abci --all-targets -- -D warningsis clean, andcargo fmt --all -- --checkpasses.cargo test -p dpp --lib -- derived_index document_removal moderator_abilities moderated_document validate_update: 201 passed.cargo test -p drive --lib -- derived_index moderation moderated: 66 passed.cargo test -p drive-abci --lib -- contract_user_moderation document_reference derived: 175 passed.Breaking Changes
Protocol version 14 (unreleased) registers contracts it refused before: a derived index property reading a kept field through a
moderatedDocumentreference. A node without this change would refuse such a contract, so nodes running PV14 must upgrade together. Nothing changes for protocol versions 13 and earlier.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 ·
0ff5cfc/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit