Skip to content

fix(rewards): ChangeSchedule checks net amount instead of total - #348

Open
g0spel wants to merge 1 commit into
KiiChain:mainfrom
g0spel:fix/change-schedule-net-amount-check
Open

fix(rewards): ChangeSchedule checks net amount instead of total#348
g0spel wants to merge 1 commit into
KiiChain:mainfrom
g0spel:fix/change-schedule-net-amount-check

Conversation

@g0spel

@g0spel g0spel commented Jul 5, 2026

Copy link
Copy Markdown

Description

Fixes #338 - Broken ChangeSchedule function.

The ChangeSchedule function in the x/rewards module was checking funds availability against the full TotalAmount, ignoring already-released tokens. This prevented governance from updating a schedule after partial release, even when the pool held sufficient funds to cover the remaining balance.

The Bug

// Before (buggy):
if err := k.fundsAvailable(sdkCtx, schedule.TotalAmount); err != nil {

If TotalAmount=1000 and ReleasedAmount=900, the function required 1000 in the pool even though only 100 remained to be paid.

The Fix

// After (fixed):
netAmount := schedule.TotalAmount.Sub(schedule.ReleasedAmount)
if err := k.fundsAvailable(sdkCtx, netAmount); err != nil {

Now only the unreleased portion is checked against the community pool.

Validation

  • ReleasedAmount ≤ TotalAmount is already enforced by validateSchedule() on line 91-94
  • Denom consistency between TotalAmount and ReleasedAmount is validated on line 83-86
  • The Sub() operation is safe because of these pre-conditions

Related

Fixes KiiChain#338. The ChangeSchedule function in the rewards module was
checking funds availability against the full TotalAmount, ignoring
already-released tokens. This prevented governance from updating a
schedule after partial release, even when the pool held sufficient
funds to cover the remaining balance.

Change: pass TotalAmount - ReleasedAmount to fundsAvailable instead
of TotalAmount, so only the unreleased portion is reserved.

Closes: KiiChain#338
@g0spel
g0spel requested a review from jhelison as a code owner July 5, 2026 00:10
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8692b3e9-f0ab-4b77-ac1d-b41337e7dee5

📥 Commits

Reviewing files that changed from the base of the PR and between 3192468 and f3bf3bf.

📒 Files selected for processing (1)
  • x/rewards/keeper/msg_server.go

Walkthrough

The ChangeSchedule function in the rewards keeper's message server was updated to validate community pool funds against the remaining unreleased amount of a schedule (TotalAmount minus ReleasedAmount) instead of the full TotalAmount. This netAmount is passed to the funds-availability check, and the insufficient-funds error now reflects the remaining amount owed. All other validation logic and event emission remain unchanged.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MsgServer
  participant Schedule
  participant FundsAvailable

  MsgServer->>Schedule: Read TotalAmount, ReleasedAmount
  MsgServer->>MsgServer: Compute netAmount = TotalAmount - ReleasedAmount
  MsgServer->>FundsAvailable: Check funds against netAmount
  FundsAvailable-->>MsgServer: sufficient or insufficient funds result
Loading

Related issues: #338 — Fixes the "Broken ChangeSchedule function" bug by checking fund availability against the remaining unreleased amount instead of the total amount.

Related PRs: None identified.

Suggested labels: bug, rewards

Suggested reviewers: None specified.

🐰 A schedule once demanded its whole,
Ignoring what's already been paid toll,
Now netAmount takes the stage,
Remaining funds, not the full page,
Governance proposals reach their goal!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: ChangeSchedule now checks the net amount instead of the total.
Description check ✅ Passed The description matches the change and explains the bug, fix, and validation clearly.
Linked Issues check ✅ Passed The code change satisfies #338 by checking available funds against the unreleased remainder while preserving existing validations.
Out of Scope Changes check ✅ Passed The PR appears scoped to the single funds-check fix in msg_server.go with no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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/keeper/msg_server.go 0.00% 2 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.

[BUG] Broken ChangeSchedule function

1 participant