Skip to content

fix(platform)!: end a contest without a winner when the award has no room (PV15) - #5859

Closed
QuantumExplorer wants to merge 2 commits into
v5.1-devfrom
claude/contest-award-checks
Closed

QuantumExplorer wants to merge 2 commits into
v5.1-devfrom
claude/contest-award-checks

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: When a contest over a document (a DPNS name, for example) ends, the winner's document is moved out of the contest's area and stored with the ordinary documents of its type. This change makes that step look first: is there already a document with the same id, or one holding the same unique index values? If so, nothing is stored and the contest is recorded as ended without a winner. Otherwise the document is stored exactly as before.

Value: A contest always ends with a recorded result at its end date, whatever documents its type holds by then. This covers contests on contracts registered before protocol version 15 that were opened before the create checks of #5744 applied.

Risks: Low. This is a consensus change, active only from protocol version 15, which is unreleased. One module that protocol version 14 also uses is edited in place; the edit cannot change anything at protocol version 14 (see "In-place changes to shipped generations"). In the one case the new path covers, the leading contender does not receive the document and its prefunded balance is spent like a losing contender's. Every awarded contest pays two extra reads at its end. No slow or flaky tests.

Issue being fixed or feature implemented

A contender's document waits in the contest's area, where the checks a document create runs do not see it. Only checks run on other creates while the contest is live keep its place free.

#5744 added those checks for protocol version 15: registration refuses a contest its index values do not decide, and a create outside such a contest, on a contract registered earlier, is refused while the contest is live. A document created while the chain ran protocol version 14 is not covered by either: it still holds the contest's index values when the contest ends at protocol version 15. The award had no answer for that state.

What was done?

  • award_document_to_winner 1 (packages/rs-drive-abci/src/execution/platform_events/voting/award_document_to_winner/v1/mod.rs), selected by DRIVE_ABCI_METHOD_VERSIONS_V11 (protocol version 15). It runs the two checks of a document create on the winner's document, then calls version 0 unchanged:
    • no document of the type holds its id;
    • no document holds its unique index values (Drive::validate_moderated_document_uniqueness, the document-based uniqueness check). This is read only when the entry is one Drive shares between documents (unique_index_entry_is_shared); an entry kept under the document's id meets no other.
  • The dispatcher returns whether the document was awarded. Version 0 always answers yes or returns the insert's error.
  • check_for_ended_vote_polls 1 records ContestedDocumentVotePollWinnerInfo::NoWinner when the award answers no. The contest is then cleaned up like any other: contenders and votes removed, the prefunded balance emptied, the stored status back to NotStarted (or Locked if it was locked before).
  • Docs: note 19 of v15.rs, the DRIVE_ABCI_METHOD_VERSIONS_V11 doc and row comment, and the contested keyword page of the book.

Before and after

A contract registered at protocol version 14 with a contested index over [normalizedParentDomainName, normalizedLabel] whose fieldMatches reads label. State when the contest over ("dash", "quantum") ends at protocol version 15:

contest:    contender A   { label: "quantum", normalizedLabel: "quantum" }
documents:  document of B { label: "Quantum", normalizedLabel: "quantum" }   created at protocol version 14
Before: award_document_to_winner 0 inserts A's document; the insert returns
        CorruptedContractIndexes("reference already exists")
After:  award_document_to_winner 1 inserts nothing; the contest is recorded with
        NoWinner and its status returns to NotStarted; B's document is untouched

A contest whose index values no document holds is awarded as before (Awarded(A)).

In-place changes to shipped generations

check_for_ended_vote_polls/v1/mod.rs is selected by protocol versions 14 and 15. The edit replaces

self.award_document_to_winner(..)?;
ContestedDocumentVotePollWinnerInfo::WonByIdentity(contender_id)

with

if self.award_document_to_winner(..)? {
    ContestedDocumentVotePollWinnerInfo::WonByIdentity(contender_id)
} else {
    ContestedDocumentVotePollWinnerInfo::NoWinner
}

Protocol version 14 selects award_document_to_winner 0, whose dispatcher arm returns Ok(true) or the insert's error, so the else branch is unreachable there and the outcome is identical. should_find_the_awarded_entry_taken_at_protocol_version_14 runs the module at protocol version 14 and still sees the same result as before this change. check_for_ended_vote_polls/v0 (protocol versions 1 to 13) is not edited; it ignores the returned value.

How Has This Been Tested?

Four tests added to contest_decided_by_index_values in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/mod.rs:

  • a contest opened at protocol version 14 whose index values a document took there, taken through the real perform_events_on_first_block_of_protocol_change to the latest version: ends without a winner;
  • the same for a document holding the contest's index key with other values ("\0" beside "");
  • control: a contest opened at protocol version 14 whose values are free is awarded;
  • a document holding the winner's id (written straight to Drive, since no create can produce one from protocol version 14): ends without a winner.

The three "without a winner" tests fail when version 1 is routed to version 0.

Run locally:

  • cargo test -p drive-abci --lib contest_decided_by_index_values (15 tests)
  • cargo test -p drive-abci --lib masternode_vote:: (107 tests), clean_up_after_contested_resources_vote_polls_end, contested_index_mismatch_chain_halt
  • cargo test -p platform-version
  • cargo clippy -p drive-abci --lib --tests, cargo fmt --all

The full drive-abci suite and the strategy tests were left to CI.

Breaking Changes

Consensus change from protocol version 15: a contest whose winner's id or unique index values a document already holds ends without a winner. Protocol version 14 and earlier are unchanged.

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 · 724d951

  • Bots — thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

…room (PV15)

A contender's document waits in its contest's area, where the checks a
document create runs do not see it. A contract registered before protocol
version 15 can keep a contest its index values do not decide, and a
document created outside such a contest while the chain ran protocol
version 14 still holds the contest's index values when the contest ends.

award_document_to_winner 1, selected by the protocol version 15 table,
runs the two checks of a document create on the winner's document before
inserting it: no document holds its id, and no document holds its unique
index values (read only when the entry is one Drive shares). When one
fails it inserts nothing and the contest is recorded without a winner and
cleaned up like any other. Otherwise it calls version 0 unchanged.

check_for_ended_vote_polls 1 is edited in place to read the award's
answer. Protocol version 14 selects award version 0, which always inserts
or returns the insert's error, so nothing changes there.

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

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 40b76db and 724d951.

Files selected for processing: 7

  • book/src/contract-keywords/contested.md
  • packages/rs-drive-abci/src/execution/platform_events/voting/award_document_to_winner/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/voting/award_document_to_winner/v1/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/voting/check_for_ended_vote_polls/v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/mod.rs
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_method_versions/v11.rs
  • packages/rs-platform-version/src/version/v15.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 11, 2026
@thepastaclaw

thepastaclaw commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress — actively reviewing now (commit 724d951) · triage: normal
██░░░░░░░░░░░░░░░░░░ 8% · about 25 min left · running for 2 min
✅ triage → ⏳ Phase 1 (0/2 lanes) → ▫️ verify 1 → ▫️ gate → ▫️ Phase 2 → ▫️ verify 2 → ▫️ fresh Phase 2 → ▫️ publish
Estimated from recent reviews of this tier · updated 13:19 UTC · live progress

@github-actions

github-actions Bot commented Nov 11, 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-11-11T13:03:24.958Z

Conflict in packages/rs-platform-version/src/version/v15.rs: two adjacent
table row comments, one changed on each side. Kept both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

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