Skip to content

fix(dpns): fetch every contest that ends at a page boundary - #1164

Merged
lklimek merged 5 commits into
v1.0-devfrom
fix/contest-end-times-paging
Oct 30, 2026
Merged

lklimek merged 5 commits into
v1.0-devfrom
fix/contest-end-times-paging

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Some contested usernames showed no end time when many contests ended at the same moment, and in one rare case the whole end-time refresh failed. Every contest in the window now gets its end time, and the refresh no longer fails when a contest ends exactly at the edge of the time window it looks at.

User story

As a masternode operator voting on DPNS contests, I want every open contest to show when it ends, so that I can vote before the deadline instead of guessing.

Scenario

  1. More than 100 contested-name polls end within the ±2-week window, and several of them end at the same millisecond (for example, names registered together in one block).
  2. The 100-poll page limit falls between two polls that share that end time.
  3. Before this fix, the polls after the cut were skipped and their contests had no end time in the contested-names screen.
  4. After this fix, the next page starts at that end time inclusive. Repeated contests collapse in the name map, so each contest is recorded once, and every contest gets its end time.

Detailed discussion

Verified against platform 575d961 (the pinned rev):

  • VotePollsByEndDateDriveQuery::construct_path_query reads a range of end times with a subquery insert_all and SizedQuery { limit, offset: None }. The GroveDB limit counts subquery result slots (polls), not end times.
  • drive-abci rejects any non-zero offset on proved queries (RequestingProofWithOffset), and the SDK always requests proofs. Paging by offset is therefore not possible.
  • Empty end-time trees also take limit slots (see the docs on execute_no_proof_empty_end_times). A cut page can therefore hold fewer than 100 polls, so checking whether a page is full is not a reliable signal.

The end-date index also lists contests of every other contract, and the old parser recorded them as usernames. dpns_end_times_page now keeps only polls on the DPNS domain document type. Polls of other contracts still count towards the page's last end time and poll count, or a page holding only them would end the walk.

The fix is a pure next_page_start(page_start, page_last_end_time, range_end):

  • An empty page ends the walk.
  • A page whose last end time is newer than its start moves the next start to that time, inclusive.
  • A page holding only its own included start moves the next start just past that time.
  • A stale page (one not past its own start) ends the walk instead of looping.
  • Every step strictly advances, so the walk ends. This holds even when more than 100 polls share one end time. Without an offset, polls past the 100th at that time are out of reach, and the app logs a warning.
  • The walk also stops before sending an excluded start equal to the range end. The platform rejects that request, which used to fail the whole refresh.

Tests: unit tests for the decision, plus a walk over an in-memory index that follows the platform's slot-limit rules. They cover a page cut in the middle of an end time, more polls at one end time than the limit, empty pages, stale pages, a poll at the range end, and empty end-time trees taking slots. Six of the eight failed on the old behaviour.

Also fixed: a poll ending exactly at the range end made the next request start strictly after the range end, which the platform rejects, so the whole refresh failed. The walk now stops before sending that request.

Known upstream limit: when more than 100 polls end at the same millisecond, the polls past the 100th cannot be fetched, because proved queries reject an offset. The app logs a warning, and a TODO(upstream) marks the spot.

Known upstream limit: the page limit also counts empty end-time trees, which a proved page never returns, so a page made only of such trees comes back empty and ends the walk early. The app cannot page past them without upstream support; a TODO(upstream) marks the spot.

Hard-coded test seeds in backend_task/identity/mod.rs (also found in the #1153 review) are not changed here: draft #1163 already replaces them with runtime-generated seeds.

Merging with #1153: this PR changes only the end of the paging loop and leaves the page-parsing arm alone. When #1153 lands, next_page_start takes page.last_end_time (the latest time of any poll, including yes/no polls) where it now takes the latest DPNS name time.

Attribution

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT

PR Hygiene · 95938c7

  • Bots — coderabbitai ✓ · thepastaclaw skipped by lklimek
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (src/backend_task/contested_names/query_ending_times.rs) — approved by lklimek

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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the accuracy of domain name end-time results when many vote polls are present.
    • Prevented unrelated document types from affecting domain name end-time results.

lklimek and others added 2 commits October 29, 2026 16:44
The end-date index limit counts vote polls, not end times, so a page of
100 can stop partway through the polls ending at its last end time.
Starting the next page strictly after that time dropped the rest, and
those contests got no end time. Proved queries refuse an offset, so the
next page now re-reads the boundary time (the name map dedupes) and
moves strictly past it once a page holds nothing newer. Every step
advances, so the walk ends even when more polls share one end time than
a page holds (logged as a warning). It also no longer sends the invalid
excluded start at the range end that the platform rejects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4182743 and 95938c7.

Files selected for processing: 1
  • src/backend_task/contested_names/query_ending_times.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The DPNS contested-name query now paginates polls with inclusive or exclusive end-time starts. It records end times only for DPNS domain polls, while all polls contribute to pagination progress. Tests cover filtering and pagination boundaries.

Changes: DPNS end-time query

Layer / File(s) Summary
Page filtering and metadata
src/backend_task/contested_names/query_ending_times.rs
The page parser records contest names only for polls matching the DPNS contract and domain document type. It tracks the latest end time and poll count across all polls.
Pagination boundaries
src/backend_task/contested_names/query_ending_times.rs
Query bounds use a page start and an explicit upper timestamp. The next-page logic rereads later timestamps inclusively and advances past an already-included start exclusively.
Page walk and validation
src/backend_task/contested_names/query_ending_times.rs
The query accumulates page results and warns if a full page cannot advance. Tests cover filtering, page cuts, same-time polls, empty pages, and range-end handling.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • dashpay/dash-evo-tool#1153: This PR continues the changes to query_dpns_ending_times by addressing inclusive boundaries and polls with the same end time.

Suggested reviewers: pauldelucia, lklimek

Merge Risk: Minimal · up to 95938

No identified issue blocks merging. Run the normal tests and platform checks before release.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(dpns): fetch every contest that ends at a page boundary" matches the main change. The PR changes DPNS contest end-time paging so that polls sharing an end time at a page cut are not omi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(dpns): fetch every contest that ends at a page boundary" matches the main change. The PR changes DPNS contest end-time paging so that polls sharing an end time at a page cut are not omitted. The raw summary confirms the inclusive re-read of the last end time and the advance-past logic. The title is specific and concise, and it follows the conventional commit style. It names the DPNS scope and the boundary case. The title does not mention the DPNS-only filtering or the upstream limitation, but those are secondary details.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

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

@thepastaclaw

thepastaclaw commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 1 blocking finding(s) (commit 95938c7)

lklimek and others added 3 commits October 29, 2026 17:15
…early

An empty end-time tree takes a page slot but returns no row, and proved
queries refuse an offset. A page holding only such trees therefore comes
back empty and ends the walk before the polls behind them, and no request
can page past them. Getting past them needs an upstream change, so the
behaviour stays as it is. A TODO(upstream) in next_page_start records the
limit, and a comment on the test that pins this behaviour points to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
The end-date index lists the contested polls of every contract, so a
contest on another contract could be recorded as a contested username.
Keep only polls on the DPNS domain document type. Polls of other
contracts still advance the page start, or a page holding only them
would end the walk early.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
@Claudius-Maginificent
Claudius-Maginificent marked this pull request as ready for review October 30, 2026 10:05
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai ✓ · 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 Oct 30, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 2 only (no Phase 1 for this repository)

The paging and DPNS-domain filtering changes correctly address the new cross-contract contamination path and boundary paging behavior. However, the persistence layer only accepts end times that advance the cached value, so records contaminated by the old parser can retain a later foreign-contract deadline indefinitely and continue showing an incorrect contest deadline.

🔴 1 blocking

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a contained but nontrivial change to pagination and termination logic for DPNS contest end-time queries, without affecting consensus, funds, cryptography, key handling, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/backend_task/contested_names/query_ending_times.rs`:
- [BLOCKING] src/backend_task/contested_names/query_ending_times.rs:122-126: Filtering new pages does not repair previously persisted cross-contract end times
  The new filter prevents future foreign-contract polls from entering `contests_end_times`, but it does not repair values written by the previous implementation. Before this change, the parser stored polls from every contract under the shared `det:contested_name:<name>` key. `update_contested_name_ending_times` only writes a value when it is greater than the stored end time (or when no value exists), so a previously stored later deadline from another contract remains when the current DPNS deadline is earlier. The cache then continues to show the contest as open past its actual DPNS deadline. Add a migration or refresh path that can rebuild or clear legacy end times using authoritative DPNS data, while preserving a valid newer DPNS value rather than blindly replacing it with stale data.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 30, 2026
@lklimek
lklimek dismissed thepastaclaw’s stale review October 30, 2026 14:38

No migration here, it's overengineering - this data will become outdated/refreshed soon anyway.

@lklimek
lklimek enabled auto-merge (squash) October 30, 2026 14:38
@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai ✓ · 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 waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 30, 2026
@lklimek

lklimek commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

/skip-

@lklimek

lklimek commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

/skip-bots

@github-actions

Copy link
Copy Markdown
Contributor

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot added bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 30, 2026
@lklimek
lklimek merged commit d94e624 into v1.0-dev Oct 30, 2026
21 checks passed
@lklimek
lklimek deleted the fix/contest-end-times-paging branch October 30, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants