Skip to content

fix(rewards): guard BeginBlocker against clock regression - #361

Open
amathxbt wants to merge 1 commit into
KiiChain:mainfrom
amathxbt:fix/beginblocker-clock-skew-guard
Open

fix(rewards): guard BeginBlocker against clock regression#361
amathxbt wants to merge 1 commit into
KiiChain:mainfrom
amathxbt:fix/beginblocker-clock-skew-guard

Conversation

@amathxbt

@amathxbt amathxbt commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Bug: BeginBlocker had no guard for the case where ctx.BlockTime() <= schedule.LastReleaseTime. The only time check was if schedule.LastReleaseTime.IsZero(). If block time did not advance (clock skew, replay, same-millisecond blocks in testing), CalculateReward was called with a non-positive elapsed duration, producing a zero or — absent the companion reward.go guard — a negative coin amount that panicked sdk.NewCoin.

Fix: Return nil early when !ctx.BlockTime().After(schedule.LastReleaseTime), logging the anomaly at ERROR for operator visibility.

Files changed

  • x/rewards/keeper/abci.go

If ctx.BlockTime() <= schedule.LastReleaseTime (clock skew), BeginBlocker
called CalculateReward with a non-positive elapsed duration. This produced
a zero or negative coin amount that panicked sdk.NewCoin.

Fix: return nil early when block time has not advanced past the last
release time, logging the anomaly at ERROR level.
@amathxbt
amathxbt requested a review from jhelison as a code owner July 6, 2026 12:13
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@amathxbt, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 521011a1-505e-452e-b2f0-d52b3f2262bb

📥 Commits

Reviewing files that changed from the base of the PR and between e0d3113 and 5d6f7d6.

📒 Files selected for processing (1)
  • x/rewards/keeper/abci.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
x/rewards/keeper/abci.go 0.00% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

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