Skip to content

fix(census): improve on-chain census retry robustness#468

Open
altergui wants to merge 1 commit into
mainfrom
fix/census-retry-robustness
Open

fix(census): improve on-chain census retry robustness#468
altergui wants to merge 1 commit into
mainfrom
fix/census-retry-robustness

Conversation

@altergui

Copy link
Copy Markdown
Contributor

Summary

  • Exponential backoff between retry attempts (5s → 10s → 20s → 40s → 60s…) instead of a fixed 5s cooldown, extending the effective retry window from ~20s to ~4.3 minutes
  • Increase default attempts from 5 to 8, and Expiration from 2min to 10min to match
  • OnCensusDownloaded no longer exits early when attempts are exhausted — only true Terminal errors (HTTP 404) trigger an immediate failure; indexer-lag failures keep waiting for the context deadline
  • checkOnchainCensuses re-queues failed on-chain censuses after MaxCooldown (60s) without requiring the on-chain root to have changed, giving the indexer a second round of retries

Context

On-chain dynamic censuses fail when davinci-node reads the census root from the contract before the GraphQL indexer has processed the corresponding weight-change event. On Sepolia (12s blocks, 12 confirmations), the indexer can take ~5 minutes to catch up — far beyond the previous ~20s retry window.

Test plan

  • Existing service tests pass (go test ./service/...)
  • Observe Sepolia census with slow indexer: should now retry with backoff and succeed once the indexer catches up
  • Verify Terminal (404) errors still fail fast without waiting the full window

🤖 Generated with Claude Code

- Exponential backoff between attempts (5s, 10s, 20s, 40s, 60s...) instead
  of fixed 5s cooldown, extending the effective retry window from ~20s to ~4.3min
- Increase default attempts from 5 to 8 and Expiration from 2min to 10min
- OnCensusDownloaded no longer exits early on attempt exhaustion; only Terminal
  errors (true 404s) trigger an immediate failure callback
- checkOnchainCensuses re-queues exhausted non-terminal on-chain censuses after
  MaxCooldown (60s), giving the indexer a second round without needing a root change

Fixes the race where a slow indexer (e.g. Sepolia at 12s blocks) would exhaust
all retries before catching up with newly mined weight-change events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 15, 2026 08:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves robustness of on-chain dynamic census downloads in davinci-node by extending the retry window and adding exponential backoff to better tolerate GraphQL/indexer lag before census data becomes available.

Changes:

  • Added MaxCooldown and implemented exponential backoff (doubling cooldown per retry, capped) for census download retries.
  • Increased default retry attempts (5 → 8) and expiration window (2min → 10min) to align with longer on-chain/indexer delays.
  • Updated on-chain census re-check logic to re-queue exhausted (non-terminal) downloads after MaxCooldown even when the on-chain root hasn’t changed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread service/census_service.go
Comment on lines 269 to 273
case status.Terminal && status.LastErr != nil:
// Return the last error if the downloader has reached a
// terminal error.
callback(status.LastErr)
return
Comment thread service/census_service.go
Comment on lines 399 to +401
// 1s (to cover the 1s OnCensusDownloaded polling tick) +
// Attempts * AttemptTimeout +
// (Attempts - 1) * Cooldown (when Attempts > 1).
//
// Note that the per-attempt timeout does not increase between attempts; each
// attempt uses the same AttemptTimeout value.
// sum of per-attempt cooldowns: Cooldown<<0, Cooldown<<1, ..., capped at MaxCooldown
Comment thread service/census_service.go
Comment on lines +534 to +538
// Attempts exhausted but root unchanged — wait MaxCooldown before
// giving the indexer another chance.
if cd.config.MaxCooldown <= 0 || time.Since(status.lastUpdated) < cd.config.MaxCooldown {
return true
}
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.

2 participants