Skip to content

fix(rewards): guard CalculateReward against non-positive elapsed time - #360

Open
amathxbt wants to merge 1 commit into
KiiChain:mainfrom
amathxbt:fix/calculate-reward-negative-elapsed
Open

fix(rewards): guard CalculateReward against non-positive elapsed time#360
amathxbt wants to merge 1 commit into
KiiChain:mainfrom
amathxbt:fix/calculate-reward-negative-elapsed

Conversation

@amathxbt

@amathxbt amathxbt commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Bug: If blockTime <= LastReleaseTime (clock skew, same-block re-entry, or governance setting LastReleaseTime close to block time), timeElapsedNs was zero or negative.

  • Zero: releaseProportion = 0 — silent no-op, acceptable
  • Negative: releaseProportion < 0amountToRelease < 0sdk.NewCoin panics with "negative coin amount", halting the chain

Fix: Return a zero coin early when timeElapsedStamp.Nanoseconds() <= 0.

Files changed

  • x/rewards/types/reward.go

If blockTime <= LastReleaseTime (clock skew, same-block re-entry),
timeElapsedNs was zero or negative, making releaseProportion negative,
which propagated into a negative amountToRelease and ultimately panicked
sdk.NewCoin. Fix: return a zero coin early when elapsed ns <= 0.
@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: 82912015-d5ea-4398-b73b-696aea460ec9

📥 Commits

Reviewing files that changed from the base of the PR and between e0d3113 and 865151a.

📒 Files selected for processing (1)
  • x/rewards/types/reward.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 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
x/rewards/types/reward.go 0.00% 1 Missing and 1 partial ⚠️

📢 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