Skip to content

feat(api): serve historical rewards from indexer, latest from chain - #43

Merged
nimrod-teich merged 1 commit into
mainfrom
feat/indexer-backed-rewards-snapshots
Apr 21, 2026
Merged

nimrod-teich merged 1 commit into
mainfrom
feat/indexer-backed-rewards-snapshots

Conversation

@nimrod-teich

Copy link
Copy Markdown
Contributor

Summary

  • Splits /provider-estimated-rewards into two clean paths: latest (no ?block=) reads live chain state as before; historical (?block=N) now reads from the lava-indexer snapshot tables instead of fanning out to chain RPC per provider.
  • /provider-estimated-rewards/blocks returns the indexer's snapshot set (status='ok' rows, sorted by date desc) instead of deriving the list from chain RPC.
  • Non-snapshotted historical blocks get a clean 404 with a pointer to /blocks — no slow fallback to the chain path.
  • Response shape is unchanged for both modes. processRawProviderRewards is reused by synthesising the EstimatedRewardsResponse shape from the flat indexer rows.

Depends on

Cold-fetch impact (once indexer has data)

Path Before After
/blocks ~3s (N chain RPCs) ~50ms (1 GraphQL)
?block=N ~50-95s (provider fan-out + archive-replica retries) ~50-100ms (1 GraphQL + 1 CoinGecko)
no block (latest) ~10-15s ~10-15s (unchanged)

Test plan

  • bun run typecheck — clean
  • pnpm --filter @info/api test — 117 passing (was 114; added 3)
  • Local smoke:
    • /blocks → empty array (indexer has no snapshots) ✓
    • ?block=4697952 → 404 with helpful message ✓
    • latest (no block) → 200 with 50 providers, ~10s cold ✓
  • After indexer ships + backfills: byte-exact compare of historical snapshot output against the old chain-fan-out path

Splits /provider-estimated-rewards into two clean paths:

- no ?block=      → live chain state (current accrued rewards). Address
                    list = currently staked only, from the existing
                    fetchAllProviderMonikers cache. Recent blocks live
                    on every chain replica so there are no archive-
                    routing/retry issues here.
- ?block=N        → indexer-backed historical snapshot. Single GraphQL
                    query against app.provider_rewards. Cold fetch is
                    one round trip. If the requested block has no 'ok'
                    snapshot, 404 with a pointer to the /blocks list —
                    no silent fallback to the chain's slow historical
                    path.

/provider-estimated-rewards/blocks is now indexer-sourced too: returns
exactly the snapshots the indexer has status='ok' for, sorted by date
desc. Empty array when the snapshotter hasn't run yet, which the FE
can treat as "no history available" instead of a broken state.

Synthesizes the chain's EstimatedRewardsResponse shape from the flat
indexer rows so processRawProviderRewards is reused untouched — same
IBC resolution, same USD math, same output shape. Response contract is
unchanged for both modes.

Depends on lava-indexer shipping the provider_rewards snapshotter
(separate PR). Until then: /blocks returns empty, any ?block=N returns
404 — both handled gracefully by gqlSafe.

Also removes the local monthlySnapshotTimestamps + fetchBlockAtTimestamp
usage (block list comes from indexer now) and the fetchBlockTime import
(snapshot rows carry blockTime).
@nimrod-teich
nimrod-teich merged commit 77cde5a into main Apr 21, 2026
2 checks passed
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.

1 participant