Repository navigation
fix(dpp)!: accept a reordered entryPayload and refuse unruled keywords as incompatible (PV14) - #5074
Conversation
…s as incompatible (PV14) Follow-ups from the review of the frozen differ keywords: - validate_schema_compatibility v1 reports a change under a keyword with no rule at all as an incompatible change at its path (add, remove or replace, read off the two schemas) instead of a ProtocolError. The meta-schema admits no such keyword today; this keeps a later one from failing an update with an internal error. - entryPayload is sorted and deduplicated before the diff, as transient is: the parse reads both as sets, so a reorder is no change. - The keyword guard test checks the meta-schema of every protocol version that selects differ generation 1, not only v3. - New tests: all six token cost actions, a contract $defs change under maxProperties, and two drive-abci tests that run refused updates through block processing to a paid consensus error with a bumped nonce and a charged fee. - property_names gains TOKEN_COST, MIN_PROPERTIES, MAX_PROPERTIES and CONTAINS; test helpers are shared instead of duplicated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedNext included review available in 40 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 (6)
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 — 4th in line, estimated start in ~25 min (commit 52e255c)
|
…chapters #5069 and #5074 gave the keywords the schema comparison had no rule for a consensus error. The chapters now say so: a tokenCost change is refused with DocumentTypeUpdateError (40212); minProperties, maxProperties and contains changes with IncompatibleDocumentTypeSchemaError (10246); a text-only edit of a keyword with 10246; and a reordered entryPayload is no change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-up to #5069 (merged): the fixes from a review of that change.
Basic explanation
What this does: #5069 made Platform refuse, with a proper consensus error, contract updates that touch 19 schema keywords the update check had no rule for. This PR follows up on that in three ways.
entryPayload, which changes nothing about stored data, as reorderingtransientalready can.Value: Contract owners always get a consensus error code when an update is refused, even for keywords nobody has added a rule for yet. Harmless reorders of
entryPayloadare no longer refused.Risks: Low. The safety net cannot be reached by any schema today: the meta-schema admits no keyword without a rule, and a test checks that. The
entryPayloadchange only accepts updates whose parsed document type is identical to the stored one. Both touch only protocol version 14, which is unreleased.Issue being fixed or feature implemented
A review of #5069 found:
entryPayloadis parsed as a set, liketransient, but onlytransientwas sorted before the diff. A reorder was refused with 10246.createanddeletecosts.$defsdiff, which uses the same rules, had no test for the new frozen keywords.tokenCost,minProperties,maxPropertiesandcontainswere string literals with noproperty_namesconstant.What was done?
Fallback for a keyword with no rule (
validate_schema_compatibilityv1). When the validator reportsUnsupportedSchemaKeyword, v1 now returns an incompatible change at that path instead of aProtocolError. The operation is read off the two schemas: a path the original lacks was added, one the new schema lacks was removed, and anything else was replaced. The validator stops at that keyword, so only that change is reported. The 19-keyword list from #5069 stays, so the known keywords still report every change at its own path. Other validator errors stay internal errors.Before / after, for a keyword the meta-schema might admit later without a rule:
schema keyword 'someFutureKeyword' at path '/someFutureKeyword' is not supportedIncompatibleDocumentTypeSchemaError(10246),replaceat/someFutureKeywordentryPayloadreorders.prepared_for_diffnow sorts and deduplicatesentryPayloadas it doestransient(TOP_LEVEL_NAME_SETS). The parse reads both as sets, and an entry frames its payload properties in name order whatever order the list gives.schema keyword 'entryPayload' ... is not supportedIncompatibleDocumentTypeSchemaError(10246)A real change, such as
["a", "b"]to["a", "c"], is still refused: 40212 from the parsed comparison.Guard test across protocol versions.
should_have_a_rule_for_every_keyword_the_meta_schema_admitsnow checks the meta-schema of every protocol version that selects differ generation 1. It fails loudly when such a version uses a meta-schema the test does not list.Tests:
entryPayloadreorders and repeats.effect,gasFeesPaidByandoptional.$defschange undermaxProperties, refused withIncompatibleDataContractSchemaError.refused_keyword_updatesruns a token cost change and a written-out default throughprocess_raw_state_transitions. Each ends as aPaidConsensusError(40212 and 10246), with the identity contract nonce bumped to 1 and a fee charged.Cleanup:
property_namesgainsTOKEN_COST,MIN_PROPERTIES,MAX_PROPERTIESandCONTAINS.parse_token_costsreadsTOKEN_COST; the value is the same string.doc_type_with_action_feesgives way to the more generaldoc_type_with_keywords.Not changed:
minProperties,maxPropertiesandcontainsstay frozen, matching "Fixed" in the book's keyword reference. Loosening them would be safe for stored documents, but that is a rule change of its own.How Has This Been Tested?
cargo test -p dpp --libon the branch as rebased onto v4.2-dev: 4885 passed, 6 ignored. The fullcargo test -p dpp, including integration and doc tests, passed before the rebase.cargo test -p drive-abci --lib -- data_contract_updateon the rebased branch: 64 passed, including the two new end-to-end tests.cargo clippy -p dpp -p drive-abci --tests: clean.rustfmt --checkon the changed files: clean.Breaking Changes
Consensus, protocol version 14 only. A document type update that only reorders or repeats
entryPayloadnames is now accepted. A diff under a keyword with no rule would be refused with 10246 instead of failing as an internal error; the meta-schema admits no such keyword today. Protocol versions up to 13 are unchanged.In-place changes to shipped generations
None.
validate_schema_compatibilityv1 is selected only by protocol version 14, which is unreleased.parse_token_costsis shared by all parser generations, but it only swaps the"tokenCost"literal for a constant with the same value, so its output is identical at every version.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 ·
52e255c/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.