Skip to content

fix: skip proof query when CreatedAtBlockHeight is 0 for old epochs#973

Open
mingles-agent wants to merge 1 commit intogonka-ai:mainfrom
MinglesAI:upstream-pr/fix-epochs-height-zero
Open

fix: skip proof query when CreatedAtBlockHeight is 0 for old epochs#973
mingles-agent wants to merge 1 commit intogonka-ai:mainfrom
MinglesAI:upstream-pr/fix-epochs-height-zero

Conversation

@mingles-agent
Copy link
Copy Markdown

@mingles-agent mingles-agent commented Mar 30, 2026

Closes #983

Problem

GET /api/v1/epochs/{N}/participants returns 500 Internal Server Error for past epochs:

height must be greater than 0, but got 0

Repro: http://node1.gonka.ai:8000/api/v1/epochs/215/participants

Current epoch works fine. Past epochs (where data was stored before the CreatedAtBlockHeight field was introduced) fail.

Root Cause

In queryActiveParticipants (get_participants_handler.go):

  1. First query (no height) fetches activeParticipants
  2. blockHeight := activeParticipants.CreatedAtBlockHeight — for old epochs this is 0 (field not populated at the time of storage)
  3. Second call QueryByKeyWithOptions(..., height=0, prove=true) — CometBFT rejects height=0

Fix

Check if blockHeight == 0 before the second query. If so, skip the proof query and return the first result directly. A Warn log is emitted for observability.

Testing

Verified against epoch 215 (previously returned 500) and epoch 216 (current, unaffected).

Copy link
Copy Markdown

@Doog-bot534 Doog-bot534 left a comment

Choose a reason for hiding this comment

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

Review: fix: skip proof query when CreatedAtBlockHeight is 0 for old epochs

Approve

Surgically correct fix. CometBFT rejects ABCI queries at height=0, so short-circuiting when CreatedAtBlockHeight == 0 prevents runtime errors for legacy epochs that predate the field. Returning the first query result without the proof query is the right fallback.

Strengths

  • Correctly handles protobuf uint64 zero-value default as sentinel for old epochs
  • Converts a hard failure into a graceful skip with appropriate Warn-level log
  • Minimal regression risk since this path was already broken for old epochs

Suggestions

  1. Include the epoch index in the log message for traceability: "epoch_index", epochIndex
  2. Add a comment noting this guard can be removed once all CreatedAtBlockHeight == 0 epochs have aged out

Payout address: gonka10zaal553duxp05nvfpqtsqrm2g0j6j34r8nan7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: GET /api/v1/epochs/{N}/participants returns 500 for past epochs (CreatedAtBlockHeight=0)

2 participants