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

feat: strict inflation schedule #1578

Merged
merged 95 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
6b07ca8
feat: inflation rate change
mojtaba-esk Mar 31, 2023
dfb1120
fix: sdkerror
mojtaba-esk Mar 31, 2023
6cb8e4e
docs: specs updated according to the new changes
mojtaba-esk Mar 31, 2023
51f7584
fix: export DefaultBlocksPerYear
mojtaba-esk Mar 31, 2023
f171e73
Update x/mint/spec/04_params.md
rootulp Apr 19, 2023
2e1371c
feat: remove params from mint module
rootulp Apr 28, 2023
188f60a
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp Apr 28, 2023
83fc1b1
docs: remove specs and update README
rootulp Apr 28, 2023
7759fdb
Remove params from NewParams
rootulp Apr 28, 2023
e7d9521
misc: removals
rootulp Apr 30, 2023
c05b59e
chore: remove simultation param tests
rootulp May 2, 2023
0533368
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 2, 2023
9bc10fd
refactor: NextInflationRate
rootulp May 2, 2023
6265fac
refactor: inflation rate
rootulp May 2, 2023
b7451a9
fix: BlocksPerYear based on 15s block interval
rootulp May 2, 2023
417397f
refactor: remove InitialMinter, fix BlockProvision test
rootulp May 2, 2023
44166f2
refactor: remove param for params
rootulp May 2, 2023
14bb7a2
refactor: remove param for params
rootulp May 2, 2023
1a3c1fc
refactor: prefix with Calculate
rootulp May 2, 2023
6ffe053
refactor: rename Inflation -> InflationRate
rootulp May 2, 2023
c4dc102
refactor: event inflation rate
rootulp May 2, 2023
5830042
chore: clean up keeper
rootulp May 2, 2023
4aee6c1
docs: improve code comments
rootulp May 2, 2023
fc3dbba
fix: lint
rootulp May 2, 2023
b45c53a
proto-gen
rootulp May 4, 2023
b402ac1
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 4, 2023
e7856ab
feat: add yearsSinceGenesis and genesis time to minter
rootulp May 4, 2023
44e88a0
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 5, 2023
86576ac
format proto doc comment
rootulp May 5, 2023
e7d3692
refactor: improve names
rootulp May 5, 2023
1b13bc2
test: update TestCalculateInflationRate to use block time
rootulp May 5, 2023
4b4b3f7
test: make it easier to understand
rootulp May 5, 2023
94abfe8
fix: test
rootulp May 5, 2023
6e9d368
fix: DefaultMinter
rootulp May 5, 2023
437b070
improve comments
rootulp May 5, 2023
0a62308
test: genesis time
rootulp May 5, 2023
9367c33
feat: add genesis time to query RPC
rootulp May 5, 2023
f47f951
wire up legacy Querier
rootulp May 5, 2023
c8c7a4c
test: querier
rootulp May 5, 2023
c364545
test: gRPC
rootulp May 5, 2023
9b98581
document TODOs for tests that do not run
rootulp May 5, 2023
128d023
feat: wire CLI query genesis time
rootulp May 5, 2023
0bd4c30
fix: set genesis time at height=1
rootulp May 5, 2023
cc6a56b
feat: mint utia not stake
rootulp May 5, 2023
9e188a9
chore: remove genesis test
rootulp May 9, 2023
643e918
chore: remove simulation genesis
rootulp May 9, 2023
1315e95
fix TestGetCmdQueryAnnualProvisions
rootulp May 9, 2023
9945aa2
fix TestGetCmdQueryInflationRate
rootulp May 9, 2023
a603627
fix: TestQueryGRPC
rootulp May 9, 2023
f583d2c
fix all integration tests
rootulp May 9, 2023
b4a7711
fix protobuf lint
rootulp May 9, 2023
468e3c0
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 9, 2023
139c84f
fix lint
rootulp May 9, 2023
588b544
test: TestGenesisTime
rootulp May 10, 2023
567885d
refactor: TestGenesisTime into test cases
rootulp May 10, 2023
63c1af8
TestInflationRate
rootulp May 10, 2023
89d8301
fix: set genesis time first
rootulp May 10, 2023
6e75d2e
test annual provisions
rootulp May 10, 2023
1560592
fix: suite_test
rootulp May 10, 2023
3a22852
remove TODO in favor of issue
rootulp May 10, 2023
6ee8a55
fix: TestQueryGRPC
rootulp May 10, 2023
a78d02b
Update x/mint/abci_test.go
rootulp May 10, 2023
10da0c2
Update x/mint/abci_test.go
rootulp May 10, 2023
9621325
test: inflation rate for one year minute one min
rootulp May 10, 2023
fd0274e
feat: DaysPerYear 365.2425
rootulp May 10, 2023
e37a94b
improve README
rootulp May 10, 2023
6dd1fc3
chore: delete Params entirely
rootulp May 11, 2023
3eba0f0
refactor: validate minter
rootulp May 11, 2023
a40aa88
remove: paramSpace
rootulp May 11, 2023
d95bf00
attempt to replace minter.genesis_time w/ genesis state
rootulp May 12, 2023
ec39073
Revert "attempt to replace minter.genesis_time w/ genesis state"
rootulp May 12, 2023
389c9cf
refactor: extract individual helpers
rootulp May 12, 2023
1b0b7e4
refactor: extract mintBlockProvision
rootulp May 12, 2023
8058f05
feat: only update annual provisions once per year
rootulp May 12, 2023
c90bbf4
wip: block provision based on time elapsed between blocks
rootulp May 12, 2023
0f559ea
fix TestCalculateBlockProvision
rootulp May 12, 2023
ebd3775
chore: remove BlocksPerYear
rootulp May 12, 2023
9a311f2
update README
rootulp May 12, 2023
6812091
fix: remove debug print statement
rootulp May 12, 2023
3c36641
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 12, 2023
d619120
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 14, 2023
7c069e7
clarify README
rootulp May 14, 2023
2845340
test: do not call BeginBlocker twice
rootulp May 14, 2023
f2be69f
remove Mode
rootulp May 14, 2023
fb8171e
remove Params key
rootulp May 14, 2023
c4cb2dc
improve test
rootulp May 14, 2023
df8c7bd
HACKHACK fix test
rootulp May 15, 2023
9ef1ebf
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 15, 2023
2629bd7
feat: prefer nanoseconds over seconds
rootulp May 16, 2023
9d350bd
refactor: change return type of yearsSinceGenesis
rootulp May 16, 2023
803868b
improve constants
rootulp May 16, 2023
d99ec34
test: spend 1utia in community spend proposal
rootulp May 16, 2023
e8f8c9e
improve TestCalculateBlockProvisionError
rootulp May 16, 2023
c37d4aa
Merge branch 'main' into mojtaba/inflation-rate-change
rootulp May 17, 2023
bb2c067
Merge branch 'main' into mojtaba/inflation-rate-change
evan-forbes May 17, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ coverage.txt
tools-stamp
__debug_bin
profile.out
tmp/
run.sh
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"os"
"path/filepath"

"github.com/celestiaorg/celestia-app/x/mint"
mintkeeper "github.com/celestiaorg/celestia-app/x/mint/keeper"
minttypes "github.com/celestiaorg/celestia-app/x/mint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -53,9 +56,6 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta2 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
oldgovtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand Down
4 changes: 2 additions & 2 deletions app/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package app
import (
"encoding/json"

"github.com/celestiaorg/celestia-app/x/mint"
minttypes "github.com/celestiaorg/celestia-app/x/mint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
Expand All @@ -13,8 +15,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down
16 changes: 16 additions & 0 deletions proto/celestia/mint/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package celestia.mint.v1;

import "gogoproto/gogo.proto";
import "celestia/mint/v1/mint.proto";

option go_package = "github.com/celestiaorg/celestia-app/x/mint/types";

// GenesisState defines the mint module's genesis state.
message GenesisState {
// minter is a space for holding current inflation information.
Minter minter = 1 [(gogoproto.nullable) = false];

// params defines all the paramaters of the module.
Params params = 2 [(gogoproto.nullable) = false];
}
34 changes: 34 additions & 0 deletions proto/celestia/mint/v1/mint.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";
package celestia.mint.v1;

option go_package = "github.com/celestiaorg/celestia-app/x/mint/types";

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

// Minter represents the minting state.
message Minter {
// current annual inflation rate
string inflation = 1 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// current annual expected provisions
string annual_provisions = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// Params holds parameters for the mint module.
message Params {
option (gogoproto.goproto_stringer) = false;

// type of coin to mint
string mint_denom = 1;

// expected blocks per year
uint64 blocks_per_year = 2;
}
57 changes: 57 additions & 0 deletions proto/celestia/mint/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
syntax = "proto3";
package celestia.mint.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "celestia/mint/v1/mint.proto";

option go_package = "github.com/celestiaorg/celestia-app/x/mint/types";

// Query provides defines the gRPC querier service.
service Query {
// Params returns the total set of minting parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/mint/v1beta1/params";
}

// Inflation returns the current minting inflation value.
rpc Inflation(QueryInflationRequest) returns (QueryInflationResponse) {
option (google.api.http).get = "/cosmos/mint/v1beta1/inflation";
}

// AnnualProvisions current minting annual provisions value.
rpc AnnualProvisions(QueryAnnualProvisionsRequest) returns (QueryAnnualProvisionsResponse) {
option (google.api.http).get = "/cosmos/mint/v1beta1/annual_provisions";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}

// QueryInflationRequest is the request type for the Query/Inflation RPC method.
message QueryInflationRequest {}

// QueryInflationResponse is the response type for the Query/Inflation RPC
// method.
message QueryInflationResponse {
// inflation is the current minting inflation value.
bytes inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}

// QueryAnnualProvisionsRequest is the request type for the
// Query/AnnualProvisions RPC method.
message QueryAnnualProvisionsRequest {}

// QueryAnnualProvisionsResponse is the response type for the
// Query/AnnualProvisions RPC method.
message QueryAnnualProvisionsResponse {
// annual_provisions is the current minting annual provisions value.
bytes annual_provisions = 1
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}
7 changes: 7 additions & 0 deletions x/mint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--
order: 0
-->

# Mint

* [Mint](spec/README.md) - Creation of new units of staking token.
56 changes: 56 additions & 0 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package mint

import (
"time"

"github.com/celestiaorg/celestia-app/x/mint/keeper"
"github.com/celestiaorg/celestia-app/x/mint/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// BeginBlocker mints new tokens for the previous block.
func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculationFn) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

// fetch stored minter & params
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)

// recalculate inflation rate
totalStakingSupply := k.StakingTokenSupply(ctx)
bondedRatio := k.BondedRatio(ctx)
minter.Inflation = ic(ctx, minter, params, bondedRatio)

minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply)
k.SetMinter(ctx, minter)

// mint coins, update supply
mintedCoin := minter.BlockProvision(params)
mintedCoins := sdk.NewCoins(mintedCoin)

err := k.MintCoins(ctx, mintedCoins)
if err != nil {
panic(err)
}

// send the minted coins to the fee collector account
err = k.AddCollectedFees(ctx, mintedCoins)
if err != nil {
panic(err)
}

if mintedCoin.Amount.IsInt64() {
defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens")
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeMint,
sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()),
sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()),
sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()),
),
)
}
117 changes: 117 additions & 0 deletions x/mint/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-app/x/mint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
)

// GetQueryCmd returns the cli query commands for the minting module.
func GetQueryCmd() *cobra.Command {
mintingQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the minting module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

mintingQueryCmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryInflation(),
GetCmdQueryAnnualProvisions(),
)

return mintingQueryCmd
}

// GetCmdQueryParams implements a command to return the current minting
// parameters.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current minting parameters",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryParamsRequest{}
res, err := queryClient.Params(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryInflation implements a command to return the current minting
// inflation value.
func GetCmdQueryInflation() *cobra.Command {
cmd := &cobra.Command{
Use: "inflation",
Short: "Query the current minting inflation value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryInflationRequest{}
res, err := queryClient.Inflation(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintString(fmt.Sprintf("%s\n", res.Inflation))
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryAnnualProvisions implements a command to return the current minting
// annual provisions value.
func GetCmdQueryAnnualProvisions() *cobra.Command {
cmd := &cobra.Command{
Use: "annual-provisions",
Short: "Query the current minting annual provisions value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAnnualProvisionsRequest{}
res, err := queryClient.AnnualProvisions(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintString(fmt.Sprintf("%s\n", res.AnnualProvisions))
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
18 changes: 18 additions & 0 deletions x/mint/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build norace
// +build norace

package testutil

import (
"testing"

"github.com/cosmos/cosmos-sdk/testutil/network"

"github.com/stretchr/testify/suite"
)

func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}
Loading