fix(rewards): skip ReleasedAmount denom check when amount is zero - #355
fix(rewards): skip ReleasedAmount denom check when amount is zero#355amathxbt wants to merge 1 commit into
Conversation
validateSchedule ran the denom-consistency check on ReleasedAmount
unconditionally, before the IsZero guard. This rejected schedules whose
ReleasedAmount was sdk.Coin{} (empty denom) with a misleading error.
Fix: move denom validation inside the !IsZero block.
WalkthroughThe change modifies schedule validation logic in the rewards keeper to allow a fresh release schedule with a zero-value Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)Not applicable — the change is a conditional logic tweak within a single validation function rather than a multi-component interaction flow. Related Issues: Not specified in the provided information. Related PRs: Not specified in the provided information. Suggested labels: bug, rewards-module Suggested reviewers: Not specified in the provided information. PoemA rabbit hopped through code so neat, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@x/rewards/keeper/validation.go`:
- Around line 76-91: The released-amount validation in validateSchedule
currently skips denom checks whenever ReleasedAmount.IsZero(), which lets
zero-amount coins with a non-empty, mismatched denom slip through. Update the
logic in validateSchedule so zero-amount released coins still validate the denom
unless it is the canonical empty coin, and keep the amount/limit checks guarded
appropriately. Use ReleasedAmount, TotalAmount, and validateAmount as the key
symbols when adjusting the condition, and align msg_server_test.go expectations
if the rule changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ef0f16d3-7a4b-4c63-b8a2-0879cfdff5ef
📒 Files selected for processing (1)
x/rewards/keeper/validation.go
| \t// Validate ReleasedAmount only when non-zero. The denom check was previously | ||
| \t// run unconditionally, which rejected zero-value coins (sdk.Coin{} with empty | ||
| \t// denom) used to represent a fresh schedule with no released tokens yet. | ||
| \tif !schedule.ReleasedAmount.IsZero() { | ||
| \t if schedule.ReleasedAmount.Denom != schedule.TotalAmount.Denom { | ||
| \t return fmt.Errorf("released amount denom %s doesn't match total amount denom %s", | ||
| \t schedule.ReleasedAmount.Denom, schedule.TotalAmount.Denom) | ||
| \t } | ||
| \t if err := validateAmount(schedule.ReleasedAmount); err != nil { | ||
| \t return fmt.Errorf("invalid released amount: %w", err) | ||
| \t } | ||
| \t if schedule.ReleasedAmount.Amount.GT(schedule.TotalAmount.Amount) { | ||
| \t return fmt.Errorf("released amount %s cannot exceed total amount %s", | ||
| \t schedule.ReleasedAmount, schedule.TotalAmount) | ||
| \t } | ||
| \t} |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n "denom mismatch" -A 10 x/rewards/keeper/msg_server_test.goRepository: KiiChain/kiichain
Length of output: 482
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- validation.go ---'
cat -n x/rewards/keeper/validation.go | sed -n '1,180p'
echo
echo '--- release_schedule.go ---'
cat -n x/rewards/types/release_schedule.go | sed -n '1,220p'
echo
echo '--- msg_server_test.go relevant section ---'
cat -n x/rewards/keeper/msg_server_test.go | sed -n '180,230p'Repository: KiiChain/kiichain
Length of output: 8631
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "ReleasedAmount|ReleasedAmount\." x/rewards -g'*.go'Repository: KiiChain/kiichain
Length of output: 6967
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "ReleasedAmount|ReleasedAmount\\." x/rewards -g'*.go'Repository: KiiChain/kiichain
Length of output: 6967
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- x/rewards/types/release_schedule_test.go ---'
cat -n x/rewards/types/release_schedule_test.go | sed -n '1,140p'
echo
echo '--- x/rewards/types/genesis_test.go ---'
cat -n x/rewards/types/genesis_test.go | sed -n '1,160p'
echo
echo '--- x/rewards/types/reward.go ---'
cat -n x/rewards/types/reward.go | sed -n '1,120p'Repository: KiiChain/kiichain
Length of output: 10885
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- x/rewards/keeper/abci.go ---'
cat -n x/rewards/keeper/abci.go | sed -n '1,160p'
echo
echo '--- sdk coin subtraction semantics references ---'
rg -n "func \\(c Coin\\) Sub|Sub\\(" "$(go env GOPATH 2>/dev/null)/pkg/mod" -g'coin.go' -g'*.go' 2>/dev/null | head -n 40Repository: KiiChain/kiichain
Length of output: 5723
Zero-amount released coins should still reject mismatched denoms.
ReleasedAmount.IsZero() only checks Amount, so sdk.NewCoin("otherdenom", 0) now skips the denom check and makes the msg_server_test.go “denom mismatch” case pass unexpectedly. If zero released amounts are only meant to allow the canonical empty coin, keep validating Denom when it is set; otherwise update the test and callers to the new rule.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@x/rewards/keeper/validation.go` around lines 76 - 91, The released-amount
validation in validateSchedule currently skips denom checks whenever
ReleasedAmount.IsZero(), which lets zero-amount coins with a non-empty,
mismatched denom slip through. Update the logic in validateSchedule so
zero-amount released coins still validate the denom unless it is the canonical
empty coin, and keep the amount/limit checks guarded appropriately. Use
ReleasedAmount, TotalAmount, and validateAmount as the key symbols when
adjusting the condition, and align msg_server_test.go expectations if the rule
changes.
Summary
Bug:
validateScheduleran the denom-consistency check onReleasedAmountbefore theIsZeroguard. A freshReleaseSchedulebuilt fromInitialReleaseSchedule()usessdk.Coin{}(empty denom) forReleasedAmount. This caused a misleading "denom mismatch" error when submitting a new-schedule governance proposal, blocking legitimate governance actions.Fix: Move denom and amount validation inside the
!IsZeroblock.Files changed
x/rewards/keeper/validation.go