Repository navigation
fix(dpp)!: refuse token cost and unruled keyword changes on update with a consensus error (PV14) - #5069
Conversation
…th a consensus error (PV14) The protocol version 14 schema differ (validate_schema_compatibility v1) fails as an unsupported keyword, a ProtocolError, on any diff under a keyword the shared rule set has no rule for. Meta-schema v3 admits nineteen such keywords that are not stripped before the diff, among them tokenCost, ttl, actionFees, indexOnly, entryPayload, the keeps*History and aggregate flags, canBeDeletedByModerators(For), minProperties, maxProperties and contains. A contract update touching one was refused as an internal error instead of a consensus error. That held for any tokenCost change, which nothing compared on its parsed value, and for any edit that leaves a parsed value unchanged, such as writing out a default or switching to the documentsAverageable shorthand. - The v1 differ gives each of those keywords the frozen rule the property refersTo has, so any change to one is an incompatible schema change (IncompatibleDocumentTypeSchemaError, 10246). A test fails when meta-schema v3 admits a keyword the differ has no rule for. - validate_update v1 compares the parsed token costs of every action and refuses an added, changed or removed cost with DocumentTypeUpdateError (40212), as it does for actionFees and ttl. Both generations are selected only by protocol version 14. Generation 0, used up to protocol version 13, is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedNext included review available in 5 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 (3)
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 ~40 min (commit 29fc033)
|
…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]>
Basic explanation
What this does: When a contract owner updates a contract, Platform compares each existing document type's old schema with its new one and refuses changes that would break documents already stored. In protocol version 14 that comparison had no rule for 19 schema keywords (
tokenCost,ttl,actionFeesand others). It stopped with an internal error whenever an update touched one of them. This PR gives each of those keywords a rule: any change to it is refused, with a proper consensus error. Token costs are also compared on their parsed values now, so changing a cost is refused with a clear message saying token costs are fixed.Value: A contract update that touches one of these keywords now gets the consensus error code the same refusal gets elsewhere (40212 or 10246), not an internal error. The contract owner learns why the update was refused. The transition is handled like every other refused update, instead of being dropped as a node-side failure.
Risks: Low. Every update this PR affects was already refused, and it still is; only the kind of refusal changes. No update that failed before now passes, and none that passed now fails. The change is consensus-relevant: a refused update is now recorded as a failed transition, not left out of the block. It only touches the generations selected by protocol version 14, which is unreleased. Protocol version 13 and earlier keep their behaviour; a test pins that.
Issue being fixed or feature implemented
validate_schema_compatibilitygeneration 1 walks the JSON diff between a document type's old and new schema. For a keyword with no rule inrs-json-schema-compatibility-validator's rule set, it returnsUnsupportedSchemaKeywordError. That surfaces asProtocolError::DataContractError(JsonSchema(SchemaCompatibilityValidationError)), not a consensus-invalid result. drive-abci then treats the update as an internal error incheck_txand in block processing, not as a consensus error.Meta-schema v3 admits these keywords with no differ rule that
prepared_for_diffdoes not strip:tokenCost,ttl,actionFees,indexOnly,entryPayload,keepsTransferHistory,keepsPurchaseHistory,keepsPricingHistory,documentsCountable,rangeCountable,documentsSummable,rangeSummable,documentsAverageable,rangeAverageable,canBeDeletedByModerators,canBeDeletedByModeratorsFor,minProperties,maxPropertiesminProperties,maxProperties,containsMost of these are also compared on their parsed values by
validate_updatev1 or the shared config checks, which refuse a real change withDocumentTypeUpdateError(40212) before the differ runs. That left two gaps:tokenCosthad no parsed comparison, so everytokenCostchange on an existing document type reached the differ.documentsAverageableshorthand.What was done?
Frozen rules in the v1 differ.
FROZEN_KEYWORDS_WITHOUT_A_SHARED_RULElists the 19 keywords above. Each gets the frozen rule the propertyrefersToalready gets, the wayownerRefersTo,transientandpropertyConstraintsdo today. The rules go in generation 1's override rules, not the shared rule set, because generation 0 also reads the shared set. A new test reads meta-schema v3 and fails if any keyword it admits (top level, property schema, typed-array element) has no rule and is not stripped. A test at protocol version 13 pins that generation 0 still reports the old error.Parsed token cost comparison in
validate_updatev1.validate_token_costs_unchangedcompares the parsed cost of each of the six actions. An added, changed or removed cost getsDocumentTypeUpdateError(40212), asactionFeesandttlalready do. A document type added by the update may still declare its own costs. No earlier protocol version let an update change token costs either, since the differ failed on anytokenCostdiff.So a real change to one of these keywords gets 40212 wherever the document type parse reads the keyword. An edit that only changes the text gets 10246, the same as writing out
"documentsMutable": truetoday.Before / after
A real token cost change:
schema keyword 'tokenCost' at path '/tokenCost/create/amount' is not supportedDocumentTypeUpdateError(40212)document type can not change the token cost of its create action: token costs are fixed when the document type is publishedWriting out a default, with the parsed document type unchanged:
schema keyword 'keepsTransferHistory' at path '/keepsTransferHistory' is not supportedIncompatibleDocumentTypeSchemaError(10246),addat/keepsTransferHistorySwitching to the averageable shorthand:
schema keyword 'documentsAverageable' at path '/documentsAverageable' is not supportedIncompatibleDocumentTypeSchemaError(10246)A keyword with no parsed value:
schema keyword 'maxProperties' at path '/maxProperties' is not supportedIncompatibleDocumentTypeSchemaError(10246),replaceat/maxPropertiesNotes for reviewers
minProperties,maxPropertiesandcontainsare frozen outright, matching "Fixed" in the book's keyword reference. Loosening them (raisingmaxProperties, dropping acontains) would be safe for stored documents; that can be allowed later with dedicated rules if wanted.entryPayloadis parsed as a set, liketransient, but onlytransientis sorted before the diff. A reorderedentryPayloadis therefore refused (10246), not accepted.$defsdiff (validate_update_schema_defs). A$defschange underminProperties,maxPropertiesorcontainsnow getsIncompatibleDataContractSchemaError, not the internal error.tokenCostas "Fixed" with no code. Once both land, its Update column should read 40212, andminProperties,maxPropertiesandcontains10246.How Has This Been Tested?
should_report_every_change_to_a_keyword_without_a_shared_rule_as_incompatible: adding, removing and changing each of the 21 keyword placements is judged, not an error.should_have_a_rule_for_every_keyword_meta_schema_v3_admits: the meta-schema guard. Checked by removingcontainsfrom the list, which made it fail.should_hard_error_on_a_token_cost_diff_at_protocol_version_13: the generation 0 replay pin.should_return_invalid_result_when_token_costs_are_changed: 40212 for add, remove and change of amount,effect,gasFeesPaidByandoptional.should_refuse_a_schema_edit_that_leaves_the_parsed_document_type_unchanged: 13 text-only edits, each 10246.SchemaCompatibilityValidationErroron every case.should_refuse_an_update_adding_a_token_cost_as_a_document_type_update_errorandshould_refuse_an_update_writing_out_a_default_as_an_incompatible_schema.validate_statenow returns a consensus error instead ofErr.cargo test -p dpp: 4881 passed, 6 ignored, plus integration and doc tests.cargo test -p drive-abci --lib -- data_contract_update: 62 passed.cargo clippy -p dpp -p drive-abci --tests: clean.rustfmt --checkon the changed files: clean.Breaking Changes
Consensus, protocol version 14 only. A contract update that changes a token cost, or touches any of the keywords above, used to end as an internal error. It now ends as a consensus error (40212 or 10246) and is recorded like any other refused update. Protocol versions up to 13 are unchanged.
In-place changes to shipped generations
None. Both generations edited here,
validate_schema_compatibilityv1 andvalidate_updatev1, are selected only by protocol version 14, which is unreleased. Generation 0 of each, used up to protocol version 13, is byte-identical;should_hard_error_on_a_token_cost_diff_at_protocol_version_13pins its outcome.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 ·
29fc033/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.