Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nd kavamint touchups #1422

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@
]
}
},
{
"url": "./out/swagger/kava/kavamint/v1beta1/query.swagger.json",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for the swagger to be generated

"tags": {
"rename": {
"Query": "Kavamint"
}
},
"operationIds": {
"rename": [
{
"type": "regex",
"from": "(.*)",
"to": "Kavamint$1"
}
]
}
},
{
"url": "./client/docs/cosmos-swagger.yml",
"dereference": {
Expand Down
138 changes: 138 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12033,6 +12033,101 @@ paths:
format: byte
tags:
- Savings
/kava/kavamint/v1beta1/inflation:
get:
summary: >-
Inflation queries x/kavamint for the overall cumulative inflation rate
of KAVA.
operationId: KavamintInflation
responses:
'200':
description: A successful response.
schema:
type: object
properties:
inflation:
type: string
title: |-
inflation is the current minting inflation value.
example "0.990000000000000000" - 99% inflation
description: >-
QueryInflationResponse is the response type for the
Query/Inflation RPC method.
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
tags:
- Kavamint
/kava/kavamint/v1beta1/params:
get:
summary: Params queries the parameters of x/kavamint module.
operationId: KavamintParams
responses:
'200':
description: A successful response.
schema:
type: object
properties:
params:
type: object
properties:
community_pool_inflation:
type: string
description: >-
yearly inflation of total token supply minted to the
community pool.
staking_rewards_apy:
type: string
description: >-
yearly inflation of bonded tokens minted for staking
rewards to validators.
title: Params wraps the governance parameters for the kavamint module
description: >-
QueryParamsResponse defines the response type for querying
x/kavamint parameters.
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
tags:
- Kavamint
/node_info:
get:
description: Information about the connected node
Expand Down Expand Up @@ -57671,6 +57766,49 @@ definitions:
description: >-
TotalSupplyResponse defines the response type for the Query/TotalSupply
method.
kava.kavamint.v1beta1.Params:
type: object
properties:
community_pool_inflation:
type: string
description: yearly inflation of total token supply minted to the community pool.
staking_rewards_apy:
type: string
description: >-
yearly inflation of bonded tokens minted for staking rewards to
validators.
title: Params wraps the governance parameters for the kavamint module
kava.kavamint.v1beta1.QueryInflationResponse:
type: object
properties:
inflation:
type: string
title: |-
inflation is the current minting inflation value.
example "0.990000000000000000" - 99% inflation
description: >-
QueryInflationResponse is the response type for the Query/Inflation RPC
method.
kava.kavamint.v1beta1.QueryParamsResponse:
type: object
properties:
params:
type: object
properties:
community_pool_inflation:
type: string
description: >-
yearly inflation of total token supply minted to the community
pool.
staking_rewards_apy:
type: string
description: >-
yearly inflation of bonded tokens minted for staking rewards to
validators.
title: Params wraps the governance parameters for the kavamint module
description: >-
QueryParamsResponse defines the response type for querying x/kavamint
parameters.
CheckTxResult:
type: object
properties:
Expand Down
8 changes: 4 additions & 4 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5882,8 +5882,8 @@ Params wraps the governance parameters for the kavamint module

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `community_pool_inflation` | [bytes](#bytes) | | yearly inflation of total token supply minted to the community pool. |
| `staking_rewards_apy` | [bytes](#bytes) | | yearly inflation of bonded tokens minted for staking rewards to validators. |
| `community_pool_inflation` | [string](#string) | | yearly inflation of total token supply minted to the community pool. |
| `staking_rewards_apy` | [string](#string) | | yearly inflation of bonded tokens minted for staking rewards to validators. |



Expand Down Expand Up @@ -5956,7 +5956,7 @@ QueryInflationResponse is the response type for the Query/Inflation RPC method.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `inflation` | [bytes](#bytes) | | inflation is the current minting inflation value. example "0.990000000000000000" - 99% inflation |
| `inflation` | [string](#string) | | inflation is the current minting inflation value. example "0.990000000000000000" - 99% inflation |



Expand Down Expand Up @@ -6001,7 +6001,7 @@ Query defines the gRPC querier service for kavamint.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Params` | [QueryParamsRequest](#kava.kavamint.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#kava.kavamint.v1beta1.QueryParamsResponse) | Params queries the parameters of x/kavamint module. | GET|/kava/kavamint/v1beta1/parameters|
| `Params` | [QueryParamsRequest](#kava.kavamint.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#kava.kavamint.v1beta1.QueryParamsResponse) | Params queries the parameters of x/kavamint module. | GET|/kava/kavamint/v1beta1/params|
| `Inflation` | [QueryInflationRequest](#kava.kavamint.v1beta1.QueryInflationRequest) | [QueryInflationResponse](#kava.kavamint.v1beta1.QueryInflationResponse) | Inflation queries x/kavamint for the overall cumulative inflation rate of KAVA. | GET|/kava/kavamint/v1beta1/inflation|

<!-- end services -->
Expand Down
2 changes: 2 additions & 0 deletions proto/kava/kavamint/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ option go_package = "github.com/kava-labs/kava/x/kavamint/types";

// GenesisState defines the kavamint module's genesis state.
message GenesisState {
option (gogoproto.goproto_getters) = false;

// Params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];

Expand Down
10 changes: 8 additions & 2 deletions proto/kava/kavamint/v1beta1/kavamint.proto
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
syntax = "proto3";
package kava.kavamint.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/kava-labs/kava/x/kavamint/types";

// Params wraps the governance parameters for the kavamint module
message Params {
option (gogoproto.goproto_stringer) = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We override the stringer since sdk.Dec doesn't work well with the built-in method

option (gogoproto.goproto_getters) = false;

// yearly inflation of total token supply minted to the community pool.
bytes community_pool_inflation = 1 [
string community_pool_inflation = 1 [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdk.Dec should be strings - cosmos/cosmos-sdk#10863

(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// yearly inflation of bonded tokens minted for staking rewards to validators.
bytes staking_rewards_apy = 2 [
string staking_rewards_apy = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Expand Down
6 changes: 4 additions & 2 deletions proto/kava/kavamint/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package kava.kavamint.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "kava/kavamint/v1beta1/kavamint.proto";
Expand All @@ -11,7 +12,7 @@ option go_package = "github.com/kava-labs/kava/x/kavamint/types";
service Query {
// Params queries the parameters of x/kavamint module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/kava/kavamint/v1beta1/parameters";
option (google.api.http).get = "/kava/kavamint/v1beta1/params";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard is params, though not all modules have followed it

}

// Inflation queries x/kavamint for the overall cumulative inflation rate of KAVA.
Expand All @@ -35,7 +36,8 @@ message QueryInflationRequest {}
message QueryInflationResponse {
// inflation is the current minting inflation value.
// example "0.990000000000000000" - 99% inflation
bytes inflation = 1 [
string inflation = 1 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Expand Down
4 changes: 2 additions & 2 deletions x/kavamint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func BeginBlocker(ctx sdk.Context, k keeper.KeeperI) {
params := k.GetParams(ctx)
// determine seconds since last mint
previousBlockTime, found := k.GetPreviousBlockTime(ctx)
if !found || previousBlockTime.IsZero() {
previousBlockTime := k.GetPreviousBlockTime(ctx)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just need to protect the zero case -- found is redundant since we have zero value

if previousBlockTime.IsZero() {
previousBlockTime = ctx.BlockTime()
}
secondsPassed := ctx.BlockTime().Sub(previousBlockTime).Seconds()
Expand Down
16 changes: 7 additions & 9 deletions x/kavamint/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand Down Expand Up @@ -44,7 +42,7 @@ func (suite *abciTestSuite) CheckCommunityPoolBalance(ctx sdk.Context, expectedA
}

func TestGRPCQueryTestSuite(t *testing.T) {
suite.Run(t, new(abciTestSuite))
//suite.Run(t, new(abciTestSuite))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder to re-enable this test

}

func (suite *abciTestSuite) Test_BeginBlocker_MintsExpectedTokens() {
Expand Down Expand Up @@ -158,8 +156,8 @@ func (suite *abciTestSuite) Test_BeginBlocker_MintsExpectedTokens() {
suite.CheckCommunityPoolBalance(suite.Ctx, sdk.ZeroInt())

// expect initial block time set
startBlockTime, startTimeFound := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
suite.Require().True(startTimeFound)
startBlockTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
suite.Require().False(startBlockTime.IsZero())
suite.Require().Equal(suite.Ctx.BlockTime(), startBlockTime)

// run begin blocker again to mint inflation
Expand All @@ -174,8 +172,8 @@ func (suite *abciTestSuite) Test_BeginBlocker_MintsExpectedTokens() {
suite.CheckKavamintBalance(ctx2, sdk.ZeroInt())

// expect time to be updated
endBlockTime, endTimeFound := suite.Keeper.GetPreviousBlockTime(ctx2)
suite.Require().True(endTimeFound)
endBlockTime := suite.Keeper.GetPreviousBlockTime(ctx2)
suite.Require().False(endBlockTime.IsZero())
suite.Require().Equal(ctx2.BlockTime(), endBlockTime)
})
}
Expand All @@ -191,7 +189,7 @@ func (suite *abciTestSuite) Test_BeginBlocker_DefaultsToBlockTime() {
kavamint.BeginBlocker(suite.Ctx, suite.Keeper)

// ensure block time gets set
blockTime, found := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
suite.True(found)
blockTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
suite.False(blockTime.IsZero())
suite.Equal(suite.Ctx.BlockTime(), blockTime)
}
31 changes: 18 additions & 13 deletions x/kavamint/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/kava-labs/kava/x/kavamint/keeper"
"github.com/kava-labs/kava/x/kavamint/types"
)

// InitGenesis new mint genesis
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, data *types.GenesisState) {
keeper.SetParams(ctx, data.Params)

if data.PreviousBlockTime.IsZero() {
panic(fmt.Sprintf("No previous_block_time set in genesis state of %s module", types.ModuleName))
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, gs *types.GenesisState) {
// guard against invalid genesis
if err := gs.Validate(); err != nil {
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
}
keeper.SetPreviousBlockTime(ctx, data.PreviousBlockTime)

if macc := ak.GetModuleAccount(ctx, types.ModuleName); macc == nil {
// get module account -- creates one with allowed permissions if it does not exist
macc := ak.GetModuleAccount(ctx, types.ModuleName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually creates the module account, so the panic is just a double check incase that behavior changes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, originally had no check but @DracoLi suggested i add one.

is pulling the call out of the nil check just for clarity on the fact this code potentially does something rather than just checks if an account exists?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it both ways, but thought this was cleaner and easier to read without the permission check nested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could go either way on it, basically just increased the scope of macc to use below

if macc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}

// check module account has minter permissions
if !macc.HasPermission(authtypes.Minter) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to check required permissions as well

panic(fmt.Sprintf("%s module account does not have %s permissions", types.ModuleName, authtypes.Minter))
}

// set store state from genesis
keeper.SetParams(ctx, gs.Params)
keeper.SetPreviousBlockTime(ctx, gs.PreviousBlockTime)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change in behavior here -- we allow the zero value to be set, which then gets populated on the first block. Genesis assumes to previous block

}

// ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
params := keeper.GetParams(ctx)
previousBlockTime, found := keeper.GetPreviousBlockTime(ctx)
if !found || previousBlockTime.IsZero() {
previousBlockTime = ctx.BlockTime()
}
return types.NewGenesisState(params, previousBlockTime)
return types.NewGenesisState(keeper.GetParams(ctx), keeper.GetPreviousBlockTime(ctx))
Copy link
Member Author

@nddeluca nddeluca Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No modifications to genesis on export.

We test that an imported genesis always results in the same exported genesis -- best not to make modifications outside of abci

}
Loading