Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions x/rewards/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,48 @@
"github.com/kiichain/kiichain/v7/x/rewards/types"
)

// RegisterInvariants registers all rewards module invariants with the invariant
// registry. Without registration the accounting check is never executed during
// simulation runs or crisis-module invocations.
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {

Check failure on line 15 in x/rewards/keeper/invariants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1019: sdk.InvariantRegistry is deprecated: the InvariantRegistry type is deprecated and will be removed once x/crisis is removed. (staticcheck)
ir.RegisterRoute(types.ModuleName, "module-accounting", ModuleAccountingInvariant(k))
}

// ModuleAccountingInvariant checks that the rewards module bank account holds at
// least the coins tracked by the CommunityPool. A deficit means phantom funds
// are recorded, which will cause BeginBlocker bank sends to fail and halt the chain.
func ModuleAccountingInvariant(k Keeper) sdk.Invariant {

Check failure on line 22 in x/rewards/keeper/invariants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1019: sdk.Invariant is deprecated: the Invariant type is deprecated and will be removed once x/crisis is removed. (staticcheck)
return func(ctx sdk.Context) (string, bool) {
rewardPool, err := k.RewardPool.Get(ctx)
if err != nil {
return sdk.FormatInvariant(

Check failure on line 26 in x/rewards/keeper/invariants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1019: sdk.FormatInvariant is deprecated: the FormatInvariant type is deprecated and will be removed once x/crisis is removed. (staticcheck)
types.ModuleName, "module-accounting",
"failed to retrieve reward pool from state",
), true
}

moduleAddr := authtypes.NewModuleAddress(types.ModuleName)
for _, poolCoin := range rewardPool.CommunityPool {
required := poolCoin.Amount.TruncateInt()
balance := k.bankKeeper.GetBalance(ctx, moduleAddr, poolCoin.Denom).Amount
if balance.LT(required) {
return sdk.FormatInvariant(

Check failure on line 37 in x/rewards/keeper/invariants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1019: sdk.FormatInvariant is deprecated: the FormatInvariant type is deprecated and will be removed once x/crisis is removed. (staticcheck)
types.ModuleName, "module-accounting",
fmt.Sprintf(
"rewards module bank balance is less than CommunityPool for denom %s: "+
"bank=%s community_pool=%s — phantom funds will cause a chain halt",
poolCoin.Denom, balance, required,
),
), true
}
}

return sdk.FormatInvariant(

Check failure on line 48 in x/rewards/keeper/invariants.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1019: sdk.FormatInvariant is deprecated: the FormatInvariant type is deprecated and will be removed once x/crisis is removed. (staticcheck)
types.ModuleName, "module-accounting", "rewards module accounting is consistent",
), false
}
}

// ValidateModuleAccounting checks that the rewards module account holds at least the coins tracked by the CommunityPool
func (k Keeper) ValidateModuleAccounting(ctx sdk.Context) error {
rewardPool, err := k.RewardPool.Get(ctx)
Expand Down
Loading