From 7567a558278860b479da44882de44156d0cbcb6a Mon Sep 17 00:00:00 2001 From: Kartik Bhat Date: Fri, 19 Apr 2024 09:20:27 -0400 Subject: [PATCH] Cosmos Gas Multiplier Params (#489) ## Describe your changes and provide context - Create cosmos gas multiplier params - Add back eventManager to cachekv ## Testing performed to validate your change - Validated on chain --------- Co-authored-by: Uday Patil --- go.mod | 19 +- proto/cosmos/params/types/types.proto | 6 + store/cachekv/mergeiterator.go | 23 +- store/cachekv/mergeiterator_test.go | 28 ++- store/cachekv/store.go | 7 +- store/types/gas.go | 29 +++ store/types/gas_test.go | 31 +++ x/auth/ante/expected_keepers.go | 2 + x/params/client/cli/query.go | 31 ++- x/params/keeper/genesis.go | 19 ++ x/params/keeper/genesis_test.go | 79 +++++++ x/params/keeper/keeper.go | 24 +- x/params/keeper/keeper_test.go | 19 ++ x/params/keeper/migrations.go | 23 ++ x/params/keeper/migrations_test.go | 22 ++ x/params/module.go | 22 +- x/params/types/genesis.go | 20 +- x/params/types/params.go | 34 +++ x/params/types/params_test.go | 18 ++ x/params/types/types.pb.go | 325 ++++++++++++++++++++++++-- 20 files changed, 723 insertions(+), 58 deletions(-) create mode 100644 x/params/keeper/genesis.go create mode 100644 x/params/keeper/genesis_test.go create mode 100644 x/params/keeper/migrations.go create mode 100644 x/params/keeper/migrations_test.go create mode 100644 x/params/types/params_test.go diff --git a/go.mod b/go.mod index 7b80d0536..08a2a6571 100644 --- a/go.mod +++ b/go.mod @@ -78,16 +78,13 @@ require ( github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect - github.com/danieljoos/wincred v1.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/dgraph-io/badger/v3 v3.2103.2 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/dvsekhvalnov/jose2go v1.5.0 // indirect github.com/felixge/httpsnoop v1.0.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/gin-gonic/gin v1.7.7 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect @@ -97,10 +94,8 @@ require ( github.com/golang/glog v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/btree v1.1.2 // indirect github.com/google/flatbuffers v1.12.1 // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/google/gofuzz v1.2.0 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect @@ -126,7 +121,6 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.7 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect @@ -150,13 +144,11 @@ require ( go.opencensus.io v0.23.0 // indirect golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sync v0.4.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/tools v0.6.0 // indirect google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/uint128 v1.2.0 // indirect @@ -172,6 +164,17 @@ require ( nhooyr.io/websocket v1.8.6 // indirect ) +require ( + github.com/danieljoos/wincred v1.1.2 // indirect + github.com/dvsekhvalnov/jose2go v1.5.0 // indirect + github.com/gin-gonic/gin v1.7.7 // indirect + github.com/google/btree v1.1.2 + github.com/google/gofuzz v1.2.0 // indirect + github.com/pelletier/go-toml/v2 v2.0.7 // indirect + golang.org/x/sync v0.4.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect +) + replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 diff --git a/proto/cosmos/params/types/types.proto b/proto/cosmos/params/types/types.proto index 9abb774fd..07d93652c 100644 --- a/proto/cosmos/params/types/types.proto +++ b/proto/cosmos/params/types/types.proto @@ -13,6 +13,12 @@ message FeesParams { [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"]; } +message CosmosGasParams { + uint64 cosmos_gas_multiplier_numerator = 1; + uint64 cosmos_gas_multiplier_denominator = 2; +} + message GenesisState { FeesParams fees_params = 1 [(gogoproto.nullable) = false]; + CosmosGasParams cosmos_gas_params = 2 [(gogoproto.nullable) = false]; } diff --git a/store/cachekv/mergeiterator.go b/store/cachekv/mergeiterator.go index a32dfb346..f13c4025c 100644 --- a/store/cachekv/mergeiterator.go +++ b/store/cachekv/mergeiterator.go @@ -16,10 +16,11 @@ import ( // // TODO: Optimize by memoizing. type cacheMergeIterator struct { - parent types.Iterator - cache types.Iterator - ascending bool - storeKey sdktypes.StoreKey + parent types.Iterator + cache types.Iterator + ascending bool + storeKey sdktypes.StoreKey + eventManager *sdktypes.EventManager } var _ types.Iterator = (*cacheMergeIterator)(nil) @@ -28,12 +29,14 @@ func NewCacheMergeIterator( parent, cache types.Iterator, ascending bool, storeKey sdktypes.StoreKey, + eventManager *sdktypes.EventManager, ) *cacheMergeIterator { iter := &cacheMergeIterator{ - parent: parent, - cache: cache, - ascending: ascending, - storeKey: storeKey, + parent: parent, + cache: cache, + ascending: ascending, + storeKey: storeKey, + eventManager: eventManager, } return iter @@ -135,12 +138,14 @@ func (iter *cacheMergeIterator) Value() []byte { // If parent is invalid, get the cache value. if !iter.parent.Valid() { value := iter.cache.Value() + iter.eventManager.EmitResourceAccessReadEvent("iterator", iter.storeKey, iter.cache.Key(), value) return value } // If cache is invalid, get the parent value. if !iter.cache.Valid() { value := iter.parent.Value() + iter.eventManager.EmitResourceAccessReadEvent("iterator", iter.storeKey, iter.parent.Key(), value) return value } @@ -151,9 +156,11 @@ func (iter *cacheMergeIterator) Value() []byte { switch cmp { case -1: // parent < cache value := iter.parent.Value() + iter.eventManager.EmitResourceAccessReadEvent("iterator", iter.storeKey, keyP, value) return value case 0, 1: // parent >= cache value := iter.cache.Value() + iter.eventManager.EmitResourceAccessReadEvent("iterator", iter.storeKey, keyC, value) return value default: panic("invalid comparison result") diff --git a/store/cachekv/mergeiterator_test.go b/store/cachekv/mergeiterator_test.go index b2648a865..00f065151 100644 --- a/store/cachekv/mergeiterator_test.go +++ b/store/cachekv/mergeiterator_test.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/dbadapter" "github.com/cosmos/cosmos-sdk/store/types" + sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" dbm "github.com/tendermint/tm-db" ) @@ -13,6 +14,7 @@ import ( func TestMangerIterator(t *testing.T) { // initiate mock kvstore mem := dbadapter.Store{DB: dbm.NewMemDB()} + eventManager := sdktypes.NewEventManager() kvstore := cachekv.NewStore(mem, types.NewKVStoreKey("CacheKvTest"), types.DefaultCacheSizeLimit) value := randSlice(defaultValueSizeBz) startKey := randSlice(32) @@ -27,13 +29,27 @@ func TestMangerIterator(t *testing.T) { cache := kvstore.Iterator(nil, nil) for ; cache.Valid(); cache.Next() { } - iter := cachekv.NewCacheMergeIterator(parent, cache, true, types.NewKVStoreKey("CacheKvTest")) + iter := cachekv.NewCacheMergeIterator(parent, cache, true, types.NewKVStoreKey("CacheKvTest"), eventManager) - // get the next value and it should not be nil - nextValue := iter.Value() - require.NotNil(t, nextValue) + // get the next value + iter.Value() + + // assert the resource access is still emitted correctly when the cache store is unavailable + require.Equal(t, "access_type", string(eventManager.Events()[0].Attributes[0].Key)) + require.Equal(t, "read", string(eventManager.Events()[0].Attributes[0].Value)) + require.Equal(t, "store_key", string(eventManager.Events()[0].Attributes[1].Key)) + require.Equal(t, "CacheKvTest", string(eventManager.Events()[0].Attributes[1].Value)) + + // assert event emission when cache is available + cache = kvstore.Iterator(keys[1], keys[2]) + iter = cachekv.NewCacheMergeIterator(parent, cache, true, types.NewKVStoreKey("CacheKvTest"), eventManager) // get the next value - nextValue = iter.Value() - require.NotNil(t, nextValue) + iter.Value() + + // assert the resource access is still emitted correctly when the cache store is available + require.Equal(t, "access_type", string(eventManager.Events()[0].Attributes[0].Key)) + require.Equal(t, "read", string(eventManager.Events()[0].Attributes[0].Value)) + require.Equal(t, "store_key", string(eventManager.Events()[0].Attributes[1].Key)) + require.Equal(t, "CacheKvTest", string(eventManager.Events()[0].Attributes[1].Value)) } diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 06d491d04..f9dee6cbb 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -56,6 +56,8 @@ func (store *Store) GetEvents() []abci.Event { // Implements Store func (store *Store) ResetEvents() { + store.mtx.Lock() + defer store.mtx.Unlock() store.eventManager = sdktypes.NewEventManager() } @@ -75,6 +77,7 @@ func (store *Store) getFromCache(key []byte) []byte { // Get implements types.KVStore. func (store *Store) Get(key []byte) (value []byte) { types.AssertValidKey(key) + store.eventManager.EmitResourceAccessReadEvent("get", store.storeKey, key, value) return store.getFromCache(key) } @@ -83,11 +86,13 @@ func (store *Store) Set(key []byte, value []byte) { types.AssertValidKey(key) types.AssertValidValue(value) store.setCacheValue(key, value, false, true) + store.eventManager.EmitResourceAccessWriteEvent("set", store.storeKey, key, value) } // Has implements types.KVStore. func (store *Store) Has(key []byte) bool { value := store.Get(key) + store.eventManager.EmitResourceAccessReadEvent("has", store.storeKey, key, value) return value != nil } @@ -189,7 +194,7 @@ func (store *Store) iterator(start, end []byte, ascending bool) types.Iterator { }() store.dirtyItems(start, end) cache = newMemIterator(start, end, store.sortedCache, store.deleted, ascending, store.eventManager, store.storeKey) - return NewCacheMergeIterator(parent, cache, ascending, store.storeKey) + return NewCacheMergeIterator(parent, cache, ascending, store.storeKey, store.eventManager) } func findStartIndex(strL []string, startQ string) int { diff --git a/store/types/gas.go b/store/types/gas.go index ef2283964..0a24db379 100644 --- a/store/types/gas.go +++ b/store/types/gas.go @@ -272,6 +272,35 @@ func (g *infiniteGasMeter) String() string { return fmt.Sprintf("InfiniteGasMeter:\n consumed: %d", g.consumed) } +type infiniteMultiplierGasMeter struct { + infiniteGasMeter + multiplierNumerator uint64 + multiplierDenominator uint64 +} + +func NewInfiniteMultiplierGasMeter(multiplierNumerator uint64, multiplierDenominator uint64) GasMeter { + return &infiniteMultiplierGasMeter{ + infiniteGasMeter: infiniteGasMeter{ + consumed: 0, + lock: &sync.Mutex{}, + }, + multiplierNumerator: multiplierNumerator, + multiplierDenominator: multiplierDenominator, + } +} + +func (g *infiniteMultiplierGasMeter) adjustGas(original Gas) Gas { + return original * g.multiplierNumerator / g.multiplierDenominator +} + +func (g *infiniteMultiplierGasMeter) ConsumeGas(amount Gas, descriptor string) { + g.infiniteGasMeter.ConsumeGas(g.adjustGas(amount), descriptor) +} + +func (g *infiniteMultiplierGasMeter) RefundGas(amount Gas, descriptor string) { + g.infiniteGasMeter.RefundGas(g.adjustGas(amount), descriptor) +} + type noConsumptionInfiniteGasMeter struct { infiniteGasMeter } diff --git a/store/types/gas_test.go b/store/types/gas_test.go index 683b99037..c02ecf969 100644 --- a/store/types/gas_test.go +++ b/store/types/gas_test.go @@ -107,6 +107,37 @@ func TestMultiplierGasMeter(t *testing.T) { } } +func TestInfiniteMultiplierGasMeter(t *testing.T) { + t.Parallel() + cases := []struct { + usage []Gas + multiplierNumerator uint64 + multiplierDenominator uint64 + }{ + {[]Gas{1, 2, 3, 4}, 1, 1}, + {[]Gas{40, 30, 20, 10}, 10, 1}, + {[]Gas{99998, 2, 100000}, 1, 2}, + {[]Gas{50000000, 40000000, 10000000}, 1, 1}, + {[]Gas{32768, 32767}, 1, 1}, + {[]Gas{32768, 32767, 1}, 1, 1}, + } + + for tcnum, tc := range cases { + meter := NewInfiniteMultiplierGasMeter(tc.multiplierNumerator, tc.multiplierDenominator) + used := uint64(0) + + for unum, usage := range tc.usage { + usage := usage + used += usage * tc.multiplierNumerator / tc.multiplierDenominator + require.NotPanics(t, func() { meter.ConsumeGas(usage, "") }, "Not exceeded limit but panicked. tc #%d, usage #%d", tcnum, unum) + require.Equal(t, used, meter.GasConsumed(), "Gas consumption not match. tc #%d, usage #%d", tcnum, unum) + require.Equal(t, used, meter.GasConsumedToLimit(), "Gas consumption (to limit) not match. tc #%d, usage #%d", tcnum, unum) + require.False(t, meter.IsPastLimit(), "Not exceeded limit but got IsPastLimit() true") + require.False(t, meter.IsOutOfGas(), "Not yet at limit but got IsOutOfGas() true") + } + } +} + func TestAddUint64Overflow(t *testing.T) { t.Parallel() testCases := []struct { diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index b4f1e4700..79af95e0a 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -24,4 +24,6 @@ type FeegrantKeeper interface { type ParamsKeeper interface { SetFeesParams(ctx sdk.Context, feesParams paramtypes.FeesParams) GetFeesParams(ctx sdk.Context) paramtypes.FeesParams + SetCosmosGasParams(ctx sdk.Context, cosmosGasParams paramtypes.CosmosGasParams) + GetCosmosGasParams(ctx sdk.Context) paramtypes.CosmosGasParams } diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go index 6be4455dc..cd057de86 100644 --- a/x/params/client/cli/query.go +++ b/x/params/client/cli/query.go @@ -23,6 +23,7 @@ func NewQueryCmd() *cobra.Command { cmd.AddCommand(NewQuerySubspaceParamsCmd()) cmd.AddCommand(NewQueryFeeParamsCmd()) + cmd.AddCommand(NewQueryCosmosGasParamsCmd()) cmd.AddCommand(NewQueryBlockParamsCmd()) return cmd @@ -57,7 +58,6 @@ func NewQuerySubspaceParamsCmd() *cobra.Command { return cmd } - func NewQueryFeeParamsCmd() *cobra.Command { cmd := &cobra.Command{ Use: "feesparams", @@ -87,6 +87,35 @@ func NewQueryFeeParamsCmd() *cobra.Command { return cmd } +func NewQueryCosmosGasParamsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "cosmosgasparams", + Short: "Query for cosmos gas params", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := proposal.NewQueryClient(clientCtx) + + params := proposal.QueryParamsRequest{Subspace: "params", Key: string(types.ParamStoreKeyCosmosGasParams)} + res, err := queryClient.Params(cmd.Context(), ¶ms) + if err != nil { + return err + } + + cosmosGasParams := types.CosmosGasParams{} + clientCtx.Codec.UnmarshalJSON([]byte(res.Param.Value), &cosmosGasParams) + + return clientCtx.PrintProto(&cosmosGasParams) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + func NewQueryBlockParamsCmd() *cobra.Command { cmd := &cobra.Command{ Use: "blockparams", diff --git a/x/params/keeper/genesis.go b/x/params/keeper/genesis.go new file mode 100644 index 000000000..69ac48c84 --- /dev/null +++ b/x/params/keeper/genesis.go @@ -0,0 +1,19 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// InitGenesis new mint genesis. +func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { + k.SetFeesParams(ctx, data.FeesParams) + k.SetCosmosGasParams(ctx, data.CosmosGasParams) +} + +// ExportGenesis returns a GenesisState for a given context and keeper. +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + feesParams := k.GetFeesParams(ctx) + cosmosGasParams := k.GetCosmosGasParams(ctx) + return types.NewGenesisState(feesParams, cosmosGasParams) +} diff --git a/x/params/keeper/genesis_test.go b/x/params/keeper/genesis_test.go new file mode 100644 index 000000000..d54db4e05 --- /dev/null +++ b/x/params/keeper/genesis_test.go @@ -0,0 +1,79 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/params/keeper" + "github.com/cosmos/cosmos-sdk/x/params/types" +) + +type GenesisTestSuite struct { + suite.Suite + ctx sdk.Context + keeper keeper.Keeper +} + +func (suite *GenesisTestSuite) SetupTest() { + checkTx := false + app := simapp.Setup(checkTx) + suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1}) + suite.keeper = app.ParamsKeeper +} + +func (suite *GenesisTestSuite) TestImportExportGenesis() { + feesParams := &types.FeesParams{ + GlobalMinimumGasPrices: sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDecWithPrec(1, 3))}, + } + cosmosGasParams := &types.CosmosGasParams{ + CosmosGasMultiplierNumerator: 1, + CosmosGasMultiplierDenominator: 2, + } + + suite.keeper.SetFeesParams(suite.ctx, *feesParams) + suite.keeper.SetCosmosGasParams(suite.ctx, *cosmosGasParams) + + genesis := suite.keeper.ExportGenesis(suite.ctx) + suite.Require().Equal( + &types.GenesisState{ + FeesParams: *feesParams, + CosmosGasParams: *cosmosGasParams, + }, + genesis, + ) +} + +func (suite *GenesisTestSuite) TestInitGenesis() { + validGenesis := &types.GenesisState{ + FeesParams: types.FeesParams{ + GlobalMinimumGasPrices: sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDecWithPrec(1, 1))}, + }, + CosmosGasParams: types.CosmosGasParams{ + CosmosGasMultiplierNumerator: 1, + CosmosGasMultiplierDenominator: 4, + }, + } + suite.keeper.InitGenesis(suite.ctx, validGenesis) + + suite.Require().Equal( + types.FeesParams{ + GlobalMinimumGasPrices: sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDecWithPrec(1, 1))}, + }, + suite.keeper.GetFeesParams(suite.ctx), + ) + suite.Require().Equal( + types.CosmosGasParams{ + CosmosGasMultiplierNumerator: 1, + CosmosGasMultiplierDenominator: 4, + }, + suite.keeper.GetCosmosGasParams(suite.ctx), + ) +} + +func TestGenesisTestSuite(t *testing.T) { + suite.Run(t, new(GenesisTestSuite)) +} diff --git a/x/params/keeper/keeper.go b/x/params/keeper/keeper.go index 13db365fc..671b9bfdb 100644 --- a/x/params/keeper/keeper.go +++ b/x/params/keeper/keeper.go @@ -49,7 +49,6 @@ func (k Keeper) GetFeesParams(ctx sdk.Context) types.FeesParams { if !subspace.Has(ctx, types.ParamStoreKeyFeesParams) { defaultParams := *types.DefaultFeesParams() - k.SetFeesParams(ctx, defaultParams) return defaultParams } @@ -59,6 +58,29 @@ func (k Keeper) GetFeesParams(ctx sdk.Context) types.FeesParams { return feesParams } +func (k Keeper) SetCosmosGasParams(ctx sdk.Context, cosmosGasParams types.CosmosGasParams) { + cosmosGasParams.Validate() + subspace, exist := k.GetSubspace(types.ModuleName) + if !exist { + panic("subspace params should exist") + } + subspace.Set(ctx, types.ParamStoreKeyCosmosGasParams, cosmosGasParams) +} + +func (k Keeper) GetCosmosGasParams(ctx sdk.Context) types.CosmosGasParams { + subspace, _ := k.GetSubspace(types.ModuleName) + + var cosmosGasParams types.CosmosGasParams + if !subspace.Has(ctx, types.ParamStoreKeyCosmosGasParams) { + defaultParams := *types.DefaultCosmosGasParams() + return defaultParams + } + + bz := subspace.GetRaw(ctx, types.ParamStoreKeyCosmosGasParams) + json.Unmarshal(bz, &cosmosGasParams) + return cosmosGasParams +} + // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+proposal.ModuleName) diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index 44c8223f2..5e9fca8d8 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "fmt" "reflect" "testing" @@ -261,3 +262,21 @@ func TestJSONUpdate(t *testing.T) { space.Get(ctx, key, ¶m) require.Equal(t, paramJSON{40964096, "goodbyeworld"}, param) } + +func TestUpdateCosmosGasParams(t *testing.T) { + _, ctx, _, _, keeper := testComponents() + // Set to default + defaultParams := types.DefaultCosmosGasParams() + fmt.Printf("default params %+v\n", defaultParams) + keeper.SetCosmosGasParams(ctx, *defaultParams) + cosmosGasParams := keeper.GetCosmosGasParams(ctx) + require.Equal(t, defaultParams.CosmosGasMultiplierNumerator, cosmosGasParams.CosmosGasMultiplierNumerator) + require.Equal(t, defaultParams.CosmosGasMultiplierDenominator, cosmosGasParams.CosmosGasMultiplierDenominator) + + // Update to 1/4 + keeper.SetCosmosGasParams(ctx, types.NewCosmosGasParams(1, 4)) + + cosmosGasParams = keeper.GetCosmosGasParams(ctx) + require.Equal(t, uint64(1), cosmosGasParams.CosmosGasMultiplierNumerator) + require.Equal(t, uint64(4), cosmosGasParams.CosmosGasMultiplierDenominator) +} diff --git a/x/params/keeper/migrations.go b/x/params/keeper/migrations.go new file mode 100644 index 000000000..171468a0e --- /dev/null +++ b/x/params/keeper/migrations.go @@ -0,0 +1,23 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + defaultGenesis := types.DefaultGenesis() + m.keeper.SetCosmosGasParams(ctx, defaultGenesis.CosmosGasParams) + return nil +} diff --git a/x/params/keeper/migrations_test.go b/x/params/keeper/migrations_test.go new file mode 100644 index 000000000..e816b4bdc --- /dev/null +++ b/x/params/keeper/migrations_test.go @@ -0,0 +1,22 @@ +package keeper_test + +import ( + "testing" + + pk "github.com/cosmos/cosmos-sdk/x/params/keeper" + "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/stretchr/testify/require" +) + +func TestMigrate1to2(t *testing.T) { + _, ctx, _, _, keeper := testComponents() + m := pk.NewMigrator(keeper) + err := m.Migrate1to2(ctx) + require.Nil(t, err) + cosmosGasParams := keeper.GetCosmosGasParams(ctx) + // ensure set to defaults + defaultParams := types.DefaultGenesis() + require.Equal(t, defaultParams.CosmosGasParams.CosmosGasMultiplierNumerator, cosmosGasParams.CosmosGasMultiplierNumerator) + require.Equal(t, defaultParams.CosmosGasParams.CosmosGasMultiplierDenominator, cosmosGasParams.CosmosGasMultiplierDenominator) +} diff --git a/x/params/module.go b/x/params/module.go index 9b88452f3..4d41565db 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -97,12 +97,19 @@ func NewAppModule(k keeper.Keeper) AppModule { func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} -func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { - defaultGenesis := types.DefaultGenesis() - am.keeper.SetFeesParams(ctx, defaultGenesis.FeesParams) +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(gs, &genesisState) + + am.keeper.InitGenesis(ctx, &genesisState) return []abci.ValidatorUpdate{} } +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + func (AppModule) Route() sdk.Route { return sdk.Route{} } // GenerateGenesisState performs a no-op. @@ -120,6 +127,8 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // module-specific gRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper) + m := keeper.NewMigrator(am.keeper) + _ = cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2) } // ProposalContents returns all the params content functions used to @@ -141,10 +150,5 @@ func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weig return nil } -// ExportGenesis performs a no-op. -func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMessage { - return nil -} - // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return 2 } diff --git a/x/params/types/genesis.go b/x/params/types/genesis.go index 9707c5840..a8b705d5b 100644 --- a/x/params/types/genesis.go +++ b/x/params/types/genesis.go @@ -12,13 +12,31 @@ func DefaultFeesParams() *FeesParams { } } +func DefaultCosmosGasParams() *CosmosGasParams { + return &CosmosGasParams{ + CosmosGasMultiplierNumerator: 1, + CosmosGasMultiplierDenominator: 1, + } +} + // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - FeesParams: *DefaultFeesParams(), + FeesParams: *DefaultFeesParams(), + CosmosGasParams: *DefaultCosmosGasParams(), + } +} + +func NewGenesisState(feesParams FeesParams, cosmosGasParams CosmosGasParams) *GenesisState { + return &GenesisState{ + FeesParams: feesParams, + CosmosGasParams: cosmosGasParams, } } func (gs GenesisState) Validate() error { + if err := gs.CosmosGasParams.Validate(); err != nil { + return err + } return gs.FeesParams.Validate() } diff --git a/x/params/types/params.go b/x/params/types/params.go index 49e0daea1..083e28d91 100644 --- a/x/params/types/params.go +++ b/x/params/types/params.go @@ -1,12 +1,14 @@ package types import ( + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" ) var ParamStoreKeyFeesParams = []byte("FeesParams") +var ParamStoreKeyCosmosGasParams = []byte("CosmosGasParams") func NewFeesParams(minGasPrices sdk.DecCoins) FeesParams { return FeesParams{ @@ -18,6 +20,7 @@ func NewFeesParams(minGasPrices sdk.DecCoins) FeesParams { func ParamKeyTable() KeyTable { return NewKeyTable( NewParamSetPair(ParamStoreKeyFeesParams, &FeesParams{}, validateFeesParams), + NewParamSetPair(ParamStoreKeyCosmosGasParams, &CosmosGasParams{}, validateCosmosGasParams), ) } @@ -41,3 +44,34 @@ func validateFeesParams(i interface{}) error { } return nil } + +func NewCosmosGasParams(multiplierNumerator uint64, multiplierDenominator uint64) CosmosGasParams { + return CosmosGasParams{ + CosmosGasMultiplierNumerator: multiplierNumerator, + CosmosGasMultiplierDenominator: multiplierDenominator, + } +} + +func (cg *CosmosGasParams) Validate() error { + if cg.CosmosGasMultiplierNumerator == 0 { + return errors.New("cosmos gas multiplier numerator can not be 0") + } + + if cg.CosmosGasMultiplierDenominator == 0 { + return errors.New("cosmos gas multiplier denominator can not be 0") + } + + return nil +} + +func validateCosmosGasParams(i interface{}) error { + v, ok := i.(CosmosGasParams) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if err := v.Validate(); err != nil { + return err + } + return nil +} diff --git a/x/params/types/params_test.go b/x/params/types/params_test.go new file mode 100644 index 000000000..aa72f6120 --- /dev/null +++ b/x/params/types/params_test.go @@ -0,0 +1,18 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCosmosGasParams(t *testing.T) { + // Verify validation: numerator and denominator != 0 + invalidCosmosGasParam := NewCosmosGasParams(0, 1) + err := invalidCosmosGasParam.Validate() + require.NotNil(t, err) + + invalidCosmosGasParam = NewCosmosGasParams(1, 0) + err = invalidCosmosGasParam.Validate() + require.NotNil(t, err) +} diff --git a/x/params/types/types.pb.go b/x/params/types/types.pb.go index 452b35311..40b067edd 100644 --- a/x/params/types/types.pb.go +++ b/x/params/types/types.pb.go @@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Defines fee params that are controlled through governance type FeesParams struct { - GlobalMinimumGasPrices github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=global_minimum_gas_prices,json=GlobalMinimumGasPrices,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"global_minimum_gas_prices"` + GlobalMinimumGasPrices github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=global_minimum_gas_prices,json=globalMinimumGasPrices,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"global_minimum_gas_prices"` } func (m *FeesParams) Reset() { *m = FeesParams{} } @@ -70,15 +70,68 @@ func (m *FeesParams) GetGlobalMinimumGasPrices() github_com_cosmos_cosmos_sdk_ty return nil } +type CosmosGasParams struct { + CosmosGasMultiplierNumerator uint64 `protobuf:"varint,1,opt,name=cosmos_gas_multiplier_numerator,json=cosmosGasMultiplierNumerator,proto3" json:"cosmos_gas_multiplier_numerator,string,omitempty"` + CosmosGasMultiplierDenominator uint64 `protobuf:"varint,2,opt,name=cosmos_gas_multiplier_denominator,json=cosmosGasMultiplierDenominator,proto3" json:"cosmos_gas_multiplier_denominator,string,omitempty"` +} + +func (m *CosmosGasParams) Reset() { *m = CosmosGasParams{} } +func (m *CosmosGasParams) String() string { return proto.CompactTextString(m) } +func (*CosmosGasParams) ProtoMessage() {} +func (*CosmosGasParams) Descriptor() ([]byte, []int) { + return fileDescriptor_56d782f42fecdb16, []int{1} +} +func (m *CosmosGasParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CosmosGasParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CosmosGasParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CosmosGasParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_CosmosGasParams.Merge(m, src) +} +func (m *CosmosGasParams) XXX_Size() int { + return m.Size() +} +func (m *CosmosGasParams) XXX_DiscardUnknown() { + xxx_messageInfo_CosmosGasParams.DiscardUnknown(m) +} + +var xxx_messageInfo_CosmosGasParams proto.InternalMessageInfo + +func (m *CosmosGasParams) GetCosmosGasMultiplierNumerator() uint64 { + if m != nil { + return m.CosmosGasMultiplierNumerator + } + return 0 +} + +func (m *CosmosGasParams) GetCosmosGasMultiplierDenominator() uint64 { + if m != nil { + return m.CosmosGasMultiplierDenominator + } + return 0 +} + type GenesisState struct { - FeesParams FeesParams `protobuf:"bytes,1,opt,name=fees_params,json=feesParams,proto3" json:"fees_params"` + FeesParams FeesParams `protobuf:"bytes,1,opt,name=fees_params,json=feesParams,proto3" json:"fees_params"` + CosmosGasParams CosmosGasParams `protobuf:"bytes,2,opt,name=cosmos_gas_params,json=cosmosGasParams,proto3" json:"cosmos_gas_params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } func (m *GenesisState) String() string { return proto.CompactTextString(m) } func (*GenesisState) ProtoMessage() {} func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_56d782f42fecdb16, []int{1} + return fileDescriptor_56d782f42fecdb16, []int{2} } func (m *GenesisState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -114,34 +167,49 @@ func (m *GenesisState) GetFeesParams() FeesParams { return FeesParams{} } +func (m *GenesisState) GetCosmosGasParams() CosmosGasParams { + if m != nil { + return m.CosmosGasParams + } + return CosmosGasParams{} +} + func init() { proto.RegisterType((*FeesParams)(nil), "cosmos.params.v1beta1.FeesParams") + proto.RegisterType((*CosmosGasParams)(nil), "cosmos.params.v1beta1.CosmosGasParams") proto.RegisterType((*GenesisState)(nil), "cosmos.params.v1beta1.GenesisState") } func init() { proto.RegisterFile("cosmos/params/types/types.proto", fileDescriptor_56d782f42fecdb16) } var fileDescriptor_56d782f42fecdb16 = []byte{ - // 294 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x85, 0x92, - 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xa2, 0x10, 0x05, 0x7a, 0x10, 0x05, 0x7a, 0x65, 0x86, - 0x49, 0xa9, 0x25, 0x89, 0x86, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x15, 0xfa, 0x20, 0x16, - 0x44, 0xb1, 0x94, 0x1c, 0xd4, 0xb4, 0xa4, 0xc4, 0xe2, 0x54, 0x7d, 0xa8, 0x52, 0xfd, 0xe4, 0xfc, - 0xcc, 0x3c, 0x88, 0xbc, 0xd2, 0x04, 0x46, 0x2e, 0x2e, 0xb7, 0xd4, 0xd4, 0xe2, 0x00, 0xb0, 0x61, - 0x42, 0x8d, 0x8c, 0x5c, 0xc2, 0xe9, 0x39, 0xf9, 0x49, 0x89, 0x39, 0xf1, 0xb9, 0x99, 0x79, 0x99, - 0xb9, 0xa5, 0xb9, 0xf1, 0x69, 0xa9, 0xa9, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x32, - 0x7a, 0x50, 0xab, 0x41, 0xa6, 0xc1, 0x2c, 0xd6, 0x73, 0x49, 0x4d, 0x76, 0xce, 0xcf, 0xcc, 0x73, - 0x32, 0x3e, 0x71, 0x4f, 0x9e, 0x61, 0xd5, 0x7d, 0x79, 0xed, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, - 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xa8, 0xed, 0x10, 0x4a, 0xb7, 0x38, 0x25, 0x1b, 0xea, 0x13, 0xa8, - 0x9e, 0xe2, 0x20, 0x41, 0x88, 0x6d, 0xbe, 0x10, 0xcb, 0x40, 0x2e, 0x51, 0x8a, 0xe0, 0xe2, 0x71, - 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0x0e, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xf2, 0xe0, 0xe2, 0x06, - 0xb9, 0x21, 0x1e, 0xe2, 0x5f, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x45, 0x3d, 0xac, 0xa1, - 0xa0, 0x87, 0xf0, 0x8b, 0x13, 0x0b, 0xc8, 0x3d, 0x41, 0x5c, 0x69, 0x08, 0x11, 0xcf, 0x15, 0x8f, - 0xe4, 0x18, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, - 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x0a, 0xbf, 0xbb, 0x2b, - 0x50, 0x22, 0x24, 0x89, 0x0d, 0x1c, 0x7c, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xb8, - 0xa2, 0x52, 0xae, 0x01, 0x00, 0x00, + // 401 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xbf, 0xae, 0xd3, 0x30, + 0x14, 0xc6, 0xe3, 0x52, 0x31, 0xb8, 0x48, 0x15, 0x11, 0xa0, 0x52, 0x55, 0xee, 0x9f, 0x01, 0x55, + 0x42, 0x38, 0x6a, 0xfb, 0x06, 0x6d, 0xa1, 0x74, 0x28, 0xaa, 0xca, 0x82, 0x58, 0x22, 0x27, 0x75, + 0x83, 0x45, 0x1c, 0x47, 0xb1, 0x83, 0xe0, 0x1d, 0x18, 0xd8, 0x19, 0x59, 0x10, 0x23, 0x4f, 0xd1, + 0xb1, 0x23, 0x13, 0xa0, 0xf4, 0x45, 0x50, 0x6c, 0x87, 0xde, 0x5b, 0xf5, 0xde, 0x25, 0x89, 0x9c, + 0xef, 0xfc, 0xce, 0xe7, 0xf3, 0x1d, 0xd8, 0x0d, 0x85, 0xe4, 0x42, 0x7a, 0x29, 0xc9, 0x08, 0x97, + 0x9e, 0xfa, 0x94, 0x52, 0xfb, 0xc4, 0x69, 0x26, 0x94, 0x70, 0x1f, 0x1a, 0x01, 0x36, 0x02, 0xfc, + 0x61, 0x14, 0x50, 0x45, 0x46, 0xed, 0x07, 0x91, 0x88, 0x84, 0x56, 0x78, 0xe5, 0x97, 0x11, 0xb7, + 0x91, 0xa5, 0x05, 0x44, 0x52, 0xcf, 0x4a, 0xbd, 0x50, 0xb0, 0xc4, 0xfc, 0x1f, 0x7c, 0x05, 0x10, + 0xbe, 0xa0, 0x54, 0xae, 0x35, 0xcc, 0xfd, 0x0c, 0xe0, 0xe3, 0x28, 0x16, 0x01, 0x89, 0x7d, 0xce, + 0x12, 0xc6, 0x73, 0xee, 0x47, 0x44, 0xfa, 0x69, 0xc6, 0x42, 0x2a, 0x5b, 0xa0, 0x77, 0x67, 0xd8, + 0x18, 0x77, 0xb0, 0x35, 0x50, 0x32, 0xab, 0xf6, 0x78, 0x4e, 0xc3, 0x99, 0x60, 0xc9, 0x74, 0xb2, + 0xff, 0xdd, 0x75, 0x7e, 0xfc, 0xe9, 0x3e, 0x8d, 0x98, 0x7a, 0x97, 0x07, 0x38, 0x14, 0xdc, 0xb3, + 0x1e, 0xcc, 0xeb, 0x99, 0xdc, 0xbe, 0xb7, 0xf7, 0xb1, 0x35, 0x72, 0xf3, 0xc8, 0xf4, 0x5c, 0x99, + 0x96, 0x0b, 0x22, 0xd7, 0xba, 0xe1, 0xe0, 0x1b, 0x80, 0xcd, 0x99, 0xae, 0x2a, 0xcf, 0x8c, 0xc5, + 0xe7, 0xd5, 0x84, 0xb4, 0x33, 0x9e, 0xc7, 0x8a, 0xa5, 0x31, 0xa3, 0x99, 0x9f, 0xe4, 0x9c, 0x66, + 0x44, 0x89, 0xac, 0x05, 0x7a, 0x60, 0x58, 0xdf, 0x74, 0xc2, 0xaa, 0x72, 0xf5, 0x5f, 0xf4, 0xaa, + 0xd2, 0xb8, 0x4b, 0xd8, 0xbf, 0x8c, 0xd9, 0xd2, 0x44, 0x70, 0x96, 0x68, 0x50, 0x4d, 0x83, 0xd0, + 0x05, 0xd0, 0xfc, 0xa4, 0x1a, 0xfc, 0x04, 0xf0, 0xde, 0x82, 0x26, 0x54, 0x32, 0xf9, 0x5a, 0x11, + 0x45, 0xdd, 0x97, 0xb0, 0xb1, 0xa3, 0x54, 0xfa, 0x26, 0x21, 0x6d, 0xa7, 0x31, 0xee, 0xe3, 0x8b, + 0xb9, 0xe1, 0xd3, 0xf4, 0xa7, 0xf5, 0x72, 0x76, 0x1b, 0xb8, 0x3b, 0xe5, 0xf1, 0x06, 0xde, 0xbf, + 0xe2, 0xd2, 0xf2, 0x6a, 0x9a, 0xf7, 0xe4, 0x06, 0xde, 0xd9, 0xbc, 0x2c, 0xb4, 0x19, 0x9e, 0x1d, + 0x2f, 0xbf, 0x17, 0x08, 0xec, 0x0b, 0x04, 0x0e, 0x05, 0x02, 0x7f, 0x0b, 0x04, 0xbe, 0x1c, 0x91, + 0x73, 0x38, 0x22, 0xe7, 0xd7, 0x11, 0x39, 0x6f, 0x6f, 0x4f, 0xef, 0xe3, 0xb5, 0xe5, 0x0c, 0xee, + 0xea, 0x55, 0x9a, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x26, 0x95, 0xab, 0x38, 0xba, 0x02, 0x00, + 0x00, } func (this *FeesParams) Equal(that interface{}) bool { @@ -173,6 +241,33 @@ func (this *FeesParams) Equal(that interface{}) bool { } return true } +func (this *CosmosGasParams) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*CosmosGasParams) + if !ok { + that2, ok := that.(CosmosGasParams) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.CosmosGasMultiplierNumerator != that1.CosmosGasMultiplierNumerator { + return false + } + if this.CosmosGasMultiplierDenominator != that1.CosmosGasMultiplierDenominator { + return false + } + return true +} func (this *GenesisState) Equal(that interface{}) bool { if that == nil { return this == nil @@ -195,6 +290,9 @@ func (this *GenesisState) Equal(that interface{}) bool { if !this.FeesParams.Equal(&that1.FeesParams) { return false } + if !this.CosmosGasParams.Equal(&that1.CosmosGasParams) { + return false + } return true } func (m *FeesParams) Marshal() (dAtA []byte, err error) { @@ -234,6 +332,39 @@ func (m *FeesParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CosmosGasParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CosmosGasParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CosmosGasParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CosmosGasMultiplierDenominator != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.CosmosGasMultiplierDenominator)) + i-- + dAtA[i] = 0x10 + } + if m.CosmosGasMultiplierNumerator != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.CosmosGasMultiplierNumerator)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *GenesisState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -254,6 +385,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.CosmosGasParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 { size, err := m.FeesParams.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -293,6 +434,21 @@ func (m *FeesParams) Size() (n int) { return n } +func (m *CosmosGasParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CosmosGasMultiplierNumerator != 0 { + n += 1 + sovTypes(uint64(m.CosmosGasMultiplierNumerator)) + } + if m.CosmosGasMultiplierDenominator != 0 { + n += 1 + sovTypes(uint64(m.CosmosGasMultiplierDenominator)) + } + return n +} + func (m *GenesisState) Size() (n int) { if m == nil { return 0 @@ -301,6 +457,8 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.FeesParams.Size() n += 1 + l + sovTypes(uint64(l)) + l = m.CosmosGasParams.Size() + n += 1 + l + sovTypes(uint64(l)) return n } @@ -394,6 +552,94 @@ func (m *FeesParams) Unmarshal(dAtA []byte) error { } return nil } +func (m *CosmosGasParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CosmosGasParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CosmosGasParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosGasMultiplierNumerator", wireType) + } + m.CosmosGasMultiplierNumerator = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CosmosGasMultiplierNumerator |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosGasMultiplierDenominator", wireType) + } + m.CosmosGasMultiplierDenominator = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CosmosGasMultiplierDenominator |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *GenesisState) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -456,6 +702,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosGasParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CosmosGasParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:])