Skip to content

Implemented cycle reward summaries to home#19

Merged
TristanAllaire merged 6 commits intomasterfrom
feature/total-rewards
Mar 2, 2026
Merged

Implemented cycle reward summaries to home#19
TristanAllaire merged 6 commits intomasterfrom
feature/total-rewards

Conversation

@0xVoronov
Copy link
Copy Markdown
Collaborator

@0xVoronov 0xVoronov commented Feb 20, 2026

Total Rewards Paid for the network is now returned in a single GET /v1/home call instead of N requests to GET /v1/rewards/bakers/{address}. The dashboard can read networkRewardsData from home and stop calling getNetworkRewardSummary(validators, limit).

Changes

  • GET /v1/home response includes networkRewardsData:

    • totalRewardsAllTime, totalBlockRewards, totalEndorsementRewards, totalBlockFees
    • cyclesCount, averageRewardsPerCycle
    • cycleRewardSummaries — optional array of per-cycle breakdown (when requested).
  • Aggregation: One SQL query over BakerCycles (all cycles), grouped by cycle; sums of block rewards, endorsement rewards, and block fees.

  • Optional cycleRewardSummaries: Query param can be re-added to include the per-cycle array; when omitted, the array is not returned to keep the default response small.

@0xVoronov 0xVoronov self-assigned this Feb 20, 2026
}


async Task<NetworkRewardsData> GetNetworkRewardsData(IDbConnection db)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This seems like a heavy computation that wouldn't scale with the growing amount of bakers. Did you stress test /home before and after the addition? It may cause a spike in cpu/mem so I want to be sure that it's harmless

Copy link
Copy Markdown
Collaborator Author

@0xVoronov 0xVoronov Feb 23, 2026

Choose a reason for hiding this comment

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

There are several points:

  1. The BakerCycles table does not contain many records, about 1,000 now, and expected to grow to 100,000+ (which is still not a large volume).
  2. This query is not executed on every /home request; it runs only during UpdateAsync() updates, once per UpdatePeriod levels. Therefore, I don’t see any issues with this query, as it places only a moderate load on the database.

I ran a quick test of the query itself using EXPLAIN, and also tested the method in a loop. We’ll need to set up an environment to perform proper load testing in a cluster on a real machine, but that can be done later.

BakerCycles GROUP BY Cycle (cycle reward summaries)
Runs: 5000
Min: 0.8 ms
Max: 6.1 ms
Avg: 1.0 ms
Median: 0.9 ms
p95: 1.5 ms
p99: 2.3 ms

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 20, 2026

Deploying mvkt-atlasnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0e124f9
Status: ✅  Deploy successful!
Preview URL: https://722e2113.mvkt-atlasnet.pages.dev
Branch Preview URL: https://feature-total-rewards.mvkt-atlasnet.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 20, 2026

Deploying mvkt-mainnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0e124f9
Status: ✅  Deploy successful!
Preview URL: https://a27dae0c.mvkt.pages.dev
Branch Preview URL: https://feature-total-rewards.mvkt.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 20, 2026

Deploying mvkt-basenet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0e124f9
Status: ✅  Deploy successful!
Preview URL: https://e974e7cc.mvkt-basenet.pages.dev
Branch Preview URL: https://feature-total-rewards.mvkt-basenet.pages.dev

View logs

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 1, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@TristanAllaire TristanAllaire merged commit e2fdb78 into master Mar 2, 2026
5 of 6 checks passed
@TristanAllaire TristanAllaire deleted the feature/total-rewards branch March 2, 2026 06:25
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