Repository navigation
fix(platform)!: refuse a by-id refersTo to an indexOnly document type at registration (PV14) - #5284
Conversation
… at registration (PV14) An indexOnly document type keeps its documents only as index entries, and Drive refuses to fetch one by id. A permanentDocument, deletableDocument or moderatedDocument reference without findBy (or with inList) to such a type passed registration, since only the reference kind was compared, and every write resolving it then failed with an internal error, dropped unpaid. The contract reference validation 0 now refuses it, for same-contract and cross-contract targets, with ReferencedDocumentTypeIndexOnlyError (40146, StateError discriminant 171). In place: only parser generation 3, selected from protocol version 14, admits an indexOnly document type. A findBy into one keeps its own refusal (40137). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-10-05T12:12:35.069Z |
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (17)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change rejects ID-based document references to index-only types during contract registration with consensus error 40146. It adds the error to consensus and WASM mappings, tests the validation cases, and documents the rule and its protocol version. ChangesIndex-only reference validation
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to This change adds a registration-time refusal for by-id references to index-only document types, with consistent error mapping and documentation. No concrete merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change rejects unusable references earlier without adding permissions. No introduced security concern was established in the inspected registration paths. Protocol rollout and recovery behavior remain only partially assessed. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 58.82% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 10 files. (7 skipped: 7 unsupported.)
✨ Finishing Touches 💡 1📝 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 |
|
🕓 Review not started yet because the new head is waiting for the 30-minute push debounce.
Commit 1c31082. Normal review starts when eligible; priority review starts as soon as a slot is available. |
|
Reviewed |
Basic explanation
Some document types are
indexOnly: their documents are stored only as index entries, with no stored document behind them. Because of that, Drive cannot fetch one of their documents by its id.A
refersToreference that points at a document by its id (permanentDocument,deletableDocumentormoderatedDocumentwithoutfindBy) needs exactly that fetch every time a referring document is written. Until now a contract could register such a reference to an indexOnly type, and then every write to the referring type failed with an internal error and was dropped without being paid for. The referring type was unusable.This PR refuses that reference when the contract is registered, with a new consensus error,
ReferencedDocumentTypeIndexOnlyError(40146). AfindByreference to an indexOnly type was already refused and keeps its existing error.Issue being fixed or feature implemented
Registration (
validate_data_contract_references0) only compared the declared reference kind withdocument_reference_kind()of the referenced type. An indexOnly type withcanBeDeleted: falsereportsPermanent, and one that allows deletion reportsDeletable, so a by-id reference of the matching kind passed. OnlyfindByrefused indexOnly targets.At write time the document reference validation calls
fetch_document_with_id, which reachesDrivequery code that returnsQuerySyntaxError::Unsupported("indexOnly documents cannot be fetched by id ...").process_raw_state_transitionsturns that intoStateTransitionExecutionResult::InternalError, and prepare_proposal drops the transition unpaid. The same happens in the deletable-target-gone check.What was done?
ReferencedDocumentTypeIndexOnlyError(code 40146, appended toStateErrorat discriminant 171), carrying the referenced contract id, the document type name and the declaration path, like its 40122/40131/40143/40144 siblings.validate_data_contract_references_v0refuses any document reference without alookup(by id, or withinList, whose list's document is also fetched by id) whose referenced type is indexOnly. It runs before the kind check, since no kind fixes it, and covers same-contract and cross-contract targets alike.DocumentReferenceErrorCode.ReferencedDocumentTypeIndexOnly = 40146with itsfrom_codearm and the mirror test.refers-to.mdgets the registration rule and the error table row;index-only.mdsays no document reference can target such a type.v14.rs.Before (registration of this contract succeeded; every
notecreate then failed with an internal error):After: the contract create is refused, paid:
A
findByinto an indexOnly type of another contract still fails as before, withReferencedDocumentLookupInvalidError(40137), because an indexOnly type has no unique index.In-place changes to shipped generations
validate_data_contract_referencesv0 (data_contract_reference_validation: 0, selected by every protocol version's table) gains the indexOnly refusal in place. This cannot change consensus on any released version: only parser generation 3, selected from protocol version 14 (unreleased), admits anindexOnlydocument type, so before protocol version 14 no referenced type is ever indexOnly and the new branch is never taken. The reason is also stated in a note at the line.How Has This Been Tested?
New registration tests in
data_contract_create(permanent_document_reference_declarations), with a foreign fixture contract holding two indexOnly types:should_reject_a_permanent_reference_by_id_to_an_index_only_type_of_the_same_contract: 40146 atnote.pinId.should_reject_a_deletable_reference_by_id_to_an_index_only_type_of_another_contract: 40146 atnote.likeId, naming the other contract.should_keep_refusing_a_find_by_into_an_index_only_type_as_an_invalid_lookup: still 40137 ("index "byBallot" of "vote" over (ballotId) is not unique").Also: the
StateErrordiscriminant test pins 171, and the wasm-dpp2 code mirror test covers 40146.Run locally:
cargo test -p drive-abci --lib -- permanent_document_reference_declarations index_only: 87 passed (the whole reference registration module and every indexOnly test).cargo test -p dpp --lib -- errors::consensus::state::state_error: 2 passed.cargo test -p wasm-dpp2 --lib -- consensus_error: 10 passed.cargo check -p wasm-dpp: clean.Breaking Changes
None on released protocol versions. On protocol version 14 (unreleased) a contract declaring a by-id document reference to an indexOnly type is now refused at registration.
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 ·
1c31082/skip-botsproceeds without the ones not yet reported/self-reviewedWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit
findBycontinue to follow their existing validation rules.