Repository navigation
feat(api): serve historical rewards from indexer, latest from chain - #43
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/provider-estimated-rewardsinto 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/blocksreturns the indexer's snapshot set (status='ok' rows, sorted by date desc) instead of deriving the list from chain RPC./blocks— no slow fallback to the chain path.processRawProviderRewardsis reused by synthesising theEstimatedRewardsResponseshape from the flat indexer rows.Depends on
/blocksreturns[]and every?block=Nreturns 404 — both gracefully handled bygqlSafe+ the new 404 contract.Cold-fetch impact (once indexer has data)
/blocks?block=NTest plan
bun run typecheck— cleanpnpm --filter @info/api test— 117 passing (was 114; added 3)/blocks→ empty array (indexer has no snapshots) ✓?block=4697952→ 404 with helpful message ✓