Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements database-level sorting by active_tvl (descending) for the /v2/finality-providers endpoint using cursor-based pagination. The implementation shifts from a "details-first" to a "stats-first" approach: it queries finality provider stats sorted by TVL, then fetches corresponding provider details in bulk.
- Added
IndexerFinalityProviderStatsPaginationmodel andGetFinalityProviderStatsPaginatedmethod with compound cursor logic (active_tvl+fp_btc_pk_hex) - Implemented
GetFinalityProvidersByPksto bulk-fetch provider details for FPs already sorted by stats - Refactored
GetFinalityProvidersWithStatsservice method to follow the stats-first approach
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
internal/indexer/db/model/stats.go |
Added pagination model and token builder for finality provider stats sorted by active TVL |
internal/indexer/db/client/stats.go |
Implemented paginated stats query with sorting by active_tvl DESC and compound cursor filtering |
internal/indexer/db/client/finality_provider.go |
Added bulk fetch method for finality provider details by public keys |
internal/indexer/db/client/interface.go |
Extended interface with new pagination and bulk fetch methods |
internal/v2/service/finality_provider.go |
Refactored to stats-first approach: fetch sorted stats, then merge with bulk-fetched details |
internal/v2/api/handlers/finality_provider.go |
Updated documentation to reflect sorting by active TVL |
docs/swagger.yaml, docs/swagger.json, docs/docs.go |
Updated API documentation for the sorted endpoint |
tests/mocks/mock_indexer_db_client.go |
Added mock implementations for new methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for _, stat := range fpStats { | ||
| fpDetails, hasDetails := detailsLookup[stat.FpBtcPkHex] | ||
| if !hasDetails { | ||
| log.Ctx(ctx).Debug(). |
There was a problem hiding this comment.
When some finality providers have stats but are missing from the details collection, they will be silently skipped (lines 102-106). This means the returned page will have fewer results than the configured page limit, potentially confusing pagination logic. Consider logging at a higher severity level (warn or error) since this represents a data inconsistency issue that should be investigated, or consider returning an error if critical details are missing.
| log.Ctx(ctx).Debug(). | |
| log.Ctx(ctx).Warn(). |
Resolves: #212
Implements database-level sorting by
active_tvl(descending) for the/v2/finality-providersendpoint using cursor-based pagination.IndexerFinalityProviderStatsPaginationmodel andGetFinalityProviderStatsPaginatedusing a compound key (active_tvl+fp_btc_pk_hex)GetFinalityProvidersByPksfor bulk-fetching finality provider details with case-insensitive matchingGetFinalityProvidersWithStatsto astats-firstapproach, fetching sorted stats before merging with bulk-fetched provider detailsactive_tvlDESC,_idDESC) for deterministic sorting and stable pagination(active_tvl < cursor.tvl) OR (active_tvl = cursor.tvl AND _id < cursor.id)