Repository navigation
feat(dpp)!: moderator removal records keep the fields a type lists (PV14) - #5219
Conversation
…V14) A moderator's deletion leaves a removal record saying whose document it was, who removed it, why, when and a hash of it, and nothing of what it said. `moderatorAbilities.deleteKeepsFields` lists the fields that stay public: the record keeps a copy of their values, copied from the stored document at the deletion (the hashtag of a removed post, the time it was written). Paths reach into objects; the timestamps and block heights the type requires may be kept too. The list needs a record, and is fixed with the type. The record's tag byte gains bit 1: kept fields follow the restoration, each path with its value as a bincode platform value. A record keeping nothing is written as before. The removals response, and a join through a `moderatedDocument` reference, carry them as `kept_fields` (field 8); wasm-dpp2 and wasm-sdk show them as `keptFields`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (67)
✨ 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 |
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-30T09:38:04.688Z |
|
🔍 Review in progress — actively reviewing now (commit fdb18ec) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Verified the findings against head 595f095. Independent protobuf and WASM reproductions confirmed three newly exposed client-conversion defects; inspection also confirmed the kept-field fee-test coverage gap. The client defects are suggestions under the supplied consensus-focused severity policy: none establishes consensus divergence or skipped proof verification.
🟡 4 suggestion(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: ffi-engineer); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: platform-versioning); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 11: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 12: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 13: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 14: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 15: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This intricate cross-layer change modifies consensus-relevant contract validation in packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs and persistent removal-record encoding in packages/rs-drive/src/drive/contract/moderation/types.rs, alongside deletion execution and fee estimation. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— architecture-layering (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— ffi-engineer (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— platform-versioning (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 13% left, 5h 100% left),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer - Model comparison: every Phase-2 reviewer also ran on
gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `packages/dapi-grpc/clients/platform/v0/nodejs/platform_pbjs.js`:
- [SUGGESTION] packages/dapi-grpc/clients/platform/v0/nodejs/platform_pbjs.js:28855-28857: Preserve __proto__ kept fields throughout JavaScript protobuf conversion
The admitted property path `__proto__` is lost because the generated decoder initializes `keptFields` with `{}` and assigns through its inherited prototype setter. Using the checked-in platform codec and pinned protobufjs runtime, a message containing own `__proto__` and `hashtag` entries decoded with only `hashtag` as an own key, changed the map's prototype to the received Buffer, and shrank from 31 bytes to 14 when re-encoded. Independently exercising `fromObject`, `toObject`, the Drive codec, and the google-protobuf binding confirmed the same loss. These are separate transport paths that the WASM own-property helper cannot protect. Preserve arbitrary map keys throughout decoding, conversion, enumeration, and serialization through a reproducible generator/runtime repair, regenerate the affected clients, and add reserved-name round-trip tests. Updating only this generated assignment would leave the other conversion paths broken.
In `packages/wasm-dpp2/src/serialization/conversions.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/serialization/conversions.rs:426-434: Preserve own properties recursively inside retained objects
The own-property helper protects only the outer property-path map, after each retained value has already been serialized. A valid `deleteKeepsFields: ["meta"]` declaration can keep an object containing a declared `__proto__` property. Both conversion branches delegate nested maps to the pinned serde-wasm-bindgen serializer, which constructs ordinary objects and uses an indexing setter. A WASM test importing this exact conversion implementation confirmed that an object-valued nested `__proto__` entry disappears from own keys and makes its contents inherited properties in both object and JSON modes. Thus the new retained-value surfaces do not faithfully expose the stored or proof-verified value. Construct nested maps recursively with own-property writes, or repair the shared serializer and update its pin. Cover scalar and object-valued `__proto__` entries, including objects inside arrays.
In `packages/wasm-dpp2/src/state_transitions/proof_result/data_contract.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/state_transitions/proof_result/data_contract.rs:481: Make retained large integers JSON-compatible
Adding kept fields to `toJSON()` makes this existing wrapper fail for valid retained 64-bit integers outside JavaScript's safe integer range. `kept_fields_to_js(..., true)` passes them through `platform_value_to_json` to serde-wasm-bindgen's JSON-compatible serializer, which disables BigInt output and rejects these integers. A WASM reproduction against the actual helper confirmed that retained values of 9007199254740992 and -9007199254740992 succeed in object mode but return errors in JSON mode. Consequently, `toJSON()` and JSON serialization of an otherwise valid removal record throw. Convert out-of-range integers recursively to a lossless JSON representation, such as decimal strings, while leaving safe integers numeric, and add boundary-value tests.
In `packages/rs-drive/src/drive/contract/moderation/estimated_costs/v0/mod.rs`:
- [SUGGESTION] packages/rs-drive/src/drive/contract/moderation/estimated_costs/v0/mod.rs:164-167: Exercise nonempty kept fields in fee-estimation regressions
The estimated removal-tree item size now includes the encoded kept-field size, but the estimate-versus-apply tests still use records with empty `kept_fields`. `should_estimate_a_record_at_no_less_than_it_costs` exercises reason sizes only, and the restore/redelete regression also starts with an empty kept-field map. The new ABCI tests assert retained contents and proofs without checking fees. Extend the fee regressions with nonempty retained values, including a large nested value and an already populated removal tree, and compare estimated and applied fees for insertion and restoration/replacement. Include processing-fee assertions appropriate to the estimator's guarantees as well as storage fees, since this size also describes records traversed by the write.
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
…nd review fixes
A removal record now keeps its fields encoded the way the document
encodes its properties: for each path its type lists, in the list's
order, a presence byte and the value as an optional property of its
type is written, the paths themselves not stored. The record is read
under the document's type, as the document is, so each value comes
back typed exactly as reading the document gives it. The record holds
the raw bytes, so it keeps Eq, and a node returns them as stored
(proto `kept_fields` becomes bytes); wasm-sdk reads them under the
contract's type for `keptFields`, wasm-dpp2 exposes the bytes and a
`keptFields(dataContract)` reader.
Review fixes:
- a moderatedDocument `where` pair on a kept property is checked
against the record's kept value instead of refused (40145); writer
gates stay on $ownerId/$id, their texts corrected
- transience is judged by `is_transient` on the declared paths
- system fields go through `SystemProperty`
- a record replacement is estimated by what it adds, walked-past
records from the type's kept paths
- a re-deletion spares the refund of the moderator holding the
replaced record (ForfeitStorageRefunds { spared })
- a record marked restored no longer proves a deletion
- JS: own properties at every depth and through the JSON normalizer
- docs, v14 note, tests
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…docs-public-fields-f90570 # Conflicts: # packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/common/mod.rs # packages/wasm-dpp2/src/data_contract/transitions/user_moderation.rs
…arrays Estimate against apply, storage and processing, for fresh records and restores that keep a full-length text and a whole object, in a removals tree other records already fill. The kept values' JS conversion keeps a `__proto__` member its own inside arrays too, object-valued or scalar. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Basic explanation
When a moderator deletes a document, the platform keeps a small removal record: whose document it was, who removed it, why, when, and a hash of it. Everything the document said is gone.
Sometimes part of a removed document should stay visible. On a social app, a moderator removes a spam post, but the post's hashtag should still say "a post here was removed", and the time it was written still places it in the timeline. This PR lets a document type list those fields. When a moderator deletes a document, the record keeps a copy of their values; everything else leaves with the document.
Issue being fixed or feature implemented
A contract could choose whether a moderator's deletion leaves a record (
deleteKeepsRecord), but not what the record says about the document. Clients showing a removed post (a hashtag page, a thread, a quote) had nothing to show beyond "removed".What was done?
A new key of
moderatorAbilities(protocol version 14, in place):deleteKeepsFields, a list of property paths.Before:
{ "documentOwnerId": "…", "moderatorId": "…", "reason": { "text": "spam" }, "removedAt": 1759200000000, "documentHash": "…" }After:
{ "documentOwnerId": "…", "moderatorId": "…", "reason": { "text": "spam" }, "removedAt": 1759200000000, "documentHash": "…", "keptFields": { "$createdAt": 1759100000000, "hashtag": "dash", "meta.tags": ["privacy", "payments"] } }The keyword (dpp). Each entry is a declared property at any depth (
hashtag,meta.tags, ormetakept whole), or one of the timestamps and block heights ($createdAt,$updatedAt,$transferredAtand theirBlockHeight/CoreBlockHeightforms, theSystemPropertyset) that the type lists inrequired. Refused (10231) on both parse paths: withoutdelete: true; besidedeleteKeepsRecord: false(nowhere to keep them); an undeclared path or one stepping through a non-object; a transient property (judged byis_transienton the declared transient paths);$id/$ownerId(every record has them); any other system property; a path inside another listed path. Fixed with the type in both directions (40212): which fields stay public is what an author was told when writing. Meta-schema v3 gains the key.The record: kept fields stored the way documents store their properties.
ContractDocumentRemoval.kept_fieldsis the raw bytesencode_kept_fieldswrites from the stored document at deletion: for each path the type lists, in the list's order,0when the document holds no value there, or1and the value as an optional property of its type is written (DocumentPropertyType::encode_value_ref_with_size, an object length-prefixed with its members in order), a time or block height as eight big-endian bytes, a core block height as four. The paths are not stored: the type lists them and never changes the list. The record is read, as a document is, under its document type (ContractDocumentRemoval::kept_values(document_type)), and each value comes back typed exactly as reading the document gives it; an object kept whole reads members an update added after the removal as absent, as an older document does. The record keepsEq. In the Drive item, bit 1 of the tag byte says kept fields follow the restoration and come before the reason (length u32, then the bytes); a record keeping nothing is byte-for-byte what it was before. A restore keeps what the record kept; a second deletion writes fresh values. The moderator pays for the record, kept values included.Fees. Records a write walks past are estimated from the type's kept paths (presence byte and middle size, as documents are estimated), not from the record being written. A replacement (restore, or re-deletion of a restored document) is estimated by what it adds to the record it replaces, never less. A re-deletion's forfeiture (
ForfeitStorageRefunds { spared }) now spares the moderator holding the replaced record, who is refunded the bytes a shorter fresh record frees; the document's owner still forfeits.moderatedDocumentreferences (#5214). Awherepair on a property the removed document's record keeps is checked against the kept value (same absence rule as against a document in state) instead of refused with 40145; writer gates stay limited to$ownerId/$id, the only values sure to be in every record, and the parser, error and book texts now say so. A record marked restored no longer verifies as proof of a deletion.The wire.
GetContractDocumentRemovalsResponse.ContractDocumentRemovalgainsbytes kept_fields = 8, the bytes as the record stores them; the removals query and joins through amoderatedDocumentreference return them as stored. Clients regenerated.SDKs. rs-sdk returns the record;
kept_values(document_type)reads it. wasm-sdk reads kept fields under the contract's document type forkeptFieldsongetContractDocumentRemovalsentries, joined removals, and the results ofcontractDeleteDocument/contractRestoreDocument: an object keyed by path, values as a document'spropertiesshow them, every key at any depth an own property (a__proto__property is data). wasm-dpp2VerifiedContractDocumentRemovalhaskeptFieldsBytesandkeptFields(dataContract). The JSON normalizer defines rather than sets keys, and writes 64-bit integers as strings.Docs. Book: a
deleteKeepsFieldssection in the Deletion chapter with the example, the abilities and keyword tables, the record layout, fees and query in Contract Moderation, themoderatedDocumenttext in refers-to. v14 changelog: folded into item 57, besidedeleteKeepsRecord.Out of scope, by design: kept values are not indexed, so no query finds records by a kept value.
How Has This Been Tested?
validate_updaterefuses changing the list; the kept-field codec round-trips values typed as the document reads them (integers, identifiers, a whole object, a nested member, system times and core heights) and refuses bytes cut short, trailing, or with an unknown marker.hashtag,meta.tagsand$createdAt: the record reads back exactly those, the proof returns the record, a restore keeps them and the restored record no longer proves the deletion; a missing value is left out; a contract update changing the list is refused; amoderatedDocumentpair on a kept text holds against the kept value, a different text mismatches, and on a type keeping nothing the same edit is refused (40145).__proto__own at every depth and inside arrays, JSON of large integers, empty object when nothing is kept); wasm-dpp2 (1377) and wasm-sdk (455) mocha; js-evo-sdk facade.Breaking Changes
Consensus: the removal record's stored encoding gains the kept-fields section (records that keep nothing are unchanged),
moderatorAbilitiesaccepts a new key,moderatedDocumentpair checks read kept values, fee estimates of removal records change, and a re-deletion refunds the holder of the replaced record. All protocol version 14, which has not been released.Rust API:
ContractDocumentRemovalhas a new public fieldkept_fields: Vec<u8>;ContractModerationOperationType::AddDocumentRemovalcarriesreplaced_record_size/estimated_kept_fields_sizeand a boxed record;ForfeitStorageRefundscarriesspared.In-place changes to shipped generations
None: everything changed is protocol version 14, unreleased.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull request (no structure change: only the record item's contents)🤖 Generated with Claude Code
PR Hygiene ·
fdb18ec/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are donejs-wasm-sdk(packages/js-evo-sdk/README.md,packages/js-evo-sdk/tests/unit/facades/contracts.spec.ts,packages/wasm-sdk/src/queries/chained_document.rsand 3 more) — shumkovdpp— you own itrs-drive-abci— you own itrs-drive— you own itrust-sdk(packages/rs-sdk/src/mock/requests.rs,packages/rs-sdk/tests/fetch/document_query_v0_v1.rs) — lklimek or shumkovWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit