Skip to content

feat(platform)!: elected contracts declare their own election delay, read by the electionOpen reference requirement - #4914

Merged
QuantumExplorer merged 2 commits into
v4.2-devfrom
claude/moderation-election-delay
Sep 22, 2026
Merged

QuantumExplorer merged 2 commits into
v4.2-devfrom
claude/moderation-election-delay

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

PR #4913 let a contract reference fix a delay in seconds between the referenced contract's creation and the referring document, so a moderation team cannot be seated on a contract before anyone has seen it. Sam asked for the delay to be the moderated contract's own: each contract declares how much notice it gives before its first election, and the charter that opens the contest only asks whether that notice has passed, without carrying a number.

What was done?

  • On the elected declaration (ElectedModerators, packages/rs-dpp/src/data_contract/config/moderation/elected.rs): a new optional, unbounded field electionDelay, seconds after the contract's creation before the first charter may be filed against it. Left out, the election may be called at once. It is frozen with the rest of the declaration (the freeze test covers it), absent from the wire form when not declared, and ElectedModerators::election_is_open(contract_created_at, block_time_ms) reads it. Because config update v2 refuses declaring elected moderation after creation, the contract's creation is the declaration's own time, so nothing new is recorded. A contract with a delay and no recorded creation time is of unknown age and never opens.
  • On the reference: the moderation requirement's closed set gains "electionOpen": the contract declares elected moderation and its own delay has passed at the block time of the write, or it declares none. The charter that opens the contest declares it on its targetContractId:
"refersTo": {
  "type": "contract",
  "contractRequirements": { "moderation": "electionOpen" }
}

Both values have a user in the charter contract: a charter proposal only needs the target elected, so teams can form during the notice the contract gives, while the charter that opens the contest needs its election electionOpen.

Unmet is the existing ReferencedContractRequirementNotMetError (40135) with field moderation and required electionOpen. No new error code or discriminant. The check runs against the contract already fetched for the existence check, so it costs no further read.

  • Declaration and clients: meta-schema v3 enum ["elected", "electionOpen"], parser message listing both, wasm-dpp2 ContractModerators type gains electionDelay?: number and the reference surface moderation?: 'elected' | 'electionOpen'.
  • Docs: v14 changelog items 22 and 24 extended in place; the book's elected moderation section describes the delay and the requirement. The book sentence from feat(platform)!: contract references may require a minimum age of, and time since the last update to, the referenced contract #4913 that motivated minimumSecondsSinceUpdate with "an old contract updated to declare elected moderation" was wrong, since an elected declaration cannot be added by an update; it now says that requirement is for other uses than the charter. minimumAgeSeconds and minimumSecondsSinceUpdate stay as the general numeric forms.

Follow-up: in the charter contract (#4898), the proposal type keeps "moderation": "elected" and the type that opens the contest declares "moderation": "electionOpen".

How Has This Been Tested?

  • rs-dpp: elected declaration round trip with and without the delay (absent, not null, when none), the defaults test, election_is_open (no delay, one millisecond short, exact boundary, unknown age, saturation), Display, the config update freeze test with the delay as an eighth change, the reference value's is_met_by on a fixture contract (no moderation, elected without delay, elected with delay before and after it passes, unknown age), parser and meta-schema acceptance of electionOpen, and the existing reference tests. 67 targeted tests green.
  • drive-abci: new fixture reference-validation-contract-election-open-contract-ref.json; five creation tests: referenced contract not elected (40135), elected without delay (success, even without a recorded creation time), created one millisecond less than its delay before the block (40135, field moderation, required electionOpen), delayed contract without a creation time (40135), created exactly its delay before the block (success). The existing contract-reference, moderation gate and no-locking contest tests still pass.
  • cargo check -p wasm-dpp2 --target wasm32-unknown-unknown, clippy on dpp and drive-abci, rustfmt.

Breaking Changes

Consensus, under the unreleased protocol version 14: the elected declaration gains an optional field, so its encoding changes for contracts that declare a delay, and a contract reference may now refuse a write by 40135 under a new requirement value.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · b1c9b94

  • Bots — coderabbitai not yet · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed once the bots are done
  • Within your 5 open PRs
  • Build running
  • Approvals — you own every area touched; none needed

When every box is checked the PR Hygiene check passes and this can merge.

…read by the electionOpen reference requirement

The elected moderation declaration gains an optional, unbounded
`electionDelay`: seconds after the contract's creation before the first
charter may be filed against it. Since config update v2 refuses
declaring elected moderation after creation, the creation is the
declaration's own time and nothing new is recorded. Frozen with the
rest of the declaration, absent from the wire when not declared.

The `moderation` reference requirement's closed set gains
`"electionOpen"`: the contract declares elected moderation and its own
delay has passed at the block time of the write, or it declares none.
The charter's `targetContractId` declares this and carries no number.
Unmet is the existing 40135 with field `moderation`, required
`electionOpen`.

The book sentence from #4913 that motivated `minimumSecondsSinceUpdate`
with an old contract updated to declare elected moderation was wrong,
since that update is refused; corrected.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 236936dd-08ba-4720-ac15-4edbcaf6f478

📥 Commits

Reviewing files that changed from the base of the PR and between 1a561f2 and b1c9b94.

📒 Files selected for processing (16)
  • book/src/data-model/contract-moderation.md
  • packages/rs-dpp/schema/meta_schemas/document/v3/document-meta.json
  • packages/rs-dpp/src/data_contract/config/methods/validate_update/v2/mod.rs
  • packages/rs-dpp/src/data_contract/config/moderation/elected.rs
  • packages/rs-dpp/src/data_contract/config/moderation/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-dpp/src/validation/meta_validators/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/creation.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/transformer/v0/contract_moderation_gate/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests.rs
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-election-open-contract-ref.json
  • packages/rs-platform-version/src/version/v14.rs
  • packages/wasm-dpp2/src/consensus_error.rs
  • packages/wasm-dpp2/src/data_contract/document_type_reference.rs
  • packages/wasm-dpp2/src/data_contract/model.rs

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

Download the preview from the workflow artifacts.
To view locally: download the artifact, unzip, and open index.html.

Updated at 2026-09-22T16:11:04.233Z

@thepastaclaw

thepastaclaw commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ DEGRADED — Queued for automated review — 31st in line, estimated start in ~30 h (commit b1c9b94)
Estimated review time once started: ~2.0 h (two-phase automated review; median of recent runs).
The primary review models are currently out of quota; this review will run on stand-in models and be marked as degraded.

  • Request priority review — click to move this review to the front of the queue.

A charter proposal needs the target elected so teams can form during
the notice; the charter that opens the contest needs the election open.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@QuantumExplorer
QuantumExplorer merged commit 58e471a into v4.2-dev Sep 22, 2026
15 of 16 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/moderation-election-delay branch September 22, 2026 16:12
QuantumExplorer added a commit that referenced this pull request Sep 22, 2026
#4914 made the notice before a contract's first election the contract's
own (`electionDelay` on its elected declaration), read by the
`moderation: "electionOpen"` reference requirement. The charter's
`targetContractId` reference declares that instead of the five days the
reference fixed with `minimumAgeSeconds`, so the charter carries no
number and a target that declares no delay is open at once.

The five-day constant in rs-dpp goes with it; the system contract test
pins the new requirement.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
QuantumExplorer added a commit that referenced this pull request Sep 22, 2026
Resolves the overlap with #4914 (electionDelay + `moderation: "electionOpen"`):
both sets of `contractRequirements` keys are kept in the type, the parser
tests, the meta-schema, the wasm-dpp2 surface, the book and the changelog.
The drive-abci elected-contract test helper takes the election delay, the
recorded creation time and the owner protection flag, and every helper's
setup closure receives the reference targets.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants