From a47f6412ba95bb5929e509a3e6a36d91d19ef9c9 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:10:19 +0530 Subject: [PATCH 1/7] updating params --- x/callback/types/params.go | 10 +++++----- x/cwerrors/types/params.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/callback/types/params.go b/x/callback/types/params.go index 4759bbb3..886c56b9 100644 --- a/x/callback/types/params.go +++ b/x/callback/types/params.go @@ -7,11 +7,11 @@ import ( ) var ( - DefaultCallbackGasLimit = uint64(1000000) - DefaultMaxBlockReservationLimit = uint64(3) - DefaultMaxFutureReservationLimit = uint64(10000) - DefaultBlockReservationFeeMultiplier = sdk.MustNewDecFromStr("1.0") - DefaultFutureReservationFeeMultiplier = sdk.MustNewDecFromStr("1.0") + DefaultCallbackGasLimit = uint64(1500000) + DefaultMaxBlockReservationLimit = uint64(10) + DefaultMaxFutureReservationLimit = uint64(302400) + DefaultBlockReservationFeeMultiplier = sdk.MustNewDecFromStr("0.0") + DefaultFutureReservationFeeMultiplier = sdk.MustNewDecFromStr("1000000000000.0") ) // NewParams creates a new Params instance. diff --git a/x/cwerrors/types/params.go b/x/cwerrors/types/params.go index 0b38b1bf..e7482f37 100644 --- a/x/cwerrors/types/params.go +++ b/x/cwerrors/types/params.go @@ -7,9 +7,9 @@ import ( ) var ( - DefaultErrorStoredTime = int64(302400) // roughly 21 days - DefaultSubscriptionFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 0) - DefaultSubscriptionPeriod = int64(302400) // roughly 21 days + DefaultErrorStoredTime = int64(302400) // roughly 21 days + DefaultSubscriptionFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000000000000000) // 1 ARCH (1e18 attoarch) + DefaultSubscriptionPeriod = int64(302400) // roughly 21 days ) // NewParams creates a new Params instance. From da71e2ebe3a62d7bc5aa226224d080f4ee8ecb04 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:11:08 +0530 Subject: [PATCH 2/7] cleanup --- x/cwica/types/params.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/x/cwica/types/params.go b/x/cwica/types/params.go index 4dc1d7eb..785d8c97 100644 --- a/x/cwica/types/params.go +++ b/x/cwica/types/params.go @@ -3,15 +3,10 @@ package types import ( "fmt" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "gopkg.in/yaml.v2" ) -var _ paramtypes.ParamSet = (*Params)(nil) - var ( - KeyMsgSendTxMaxMessages = []byte("MsgSendTxMaxMessages") DefaultMsgSendTxMaxMessages = uint64(5) ) @@ -27,17 +22,6 @@ func DefaultParams() Params { return NewParams(DefaultMsgSendTxMaxMessages) } -// ParamSetPairs get the params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair( - KeyMsgSendTxMaxMessages, - &p.MsgSendTxMaxMessages, - validateMsgSendTxMaxMessages, - ), - } -} - // Validate validates the set of params func (p Params) Validate() error { return validateMsgSendTxMaxMessages(p.GetMsgSendTxMaxMessages()) From 6127b71b1f9a64bc9a9612b630e5d6429d3ba706 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:34:30 +0530 Subject: [PATCH 3/7] undo default param changes --- x/callback/types/params.go | 10 +++++----- x/cwerrors/types/params.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/callback/types/params.go b/x/callback/types/params.go index 886c56b9..4759bbb3 100644 --- a/x/callback/types/params.go +++ b/x/callback/types/params.go @@ -7,11 +7,11 @@ import ( ) var ( - DefaultCallbackGasLimit = uint64(1500000) - DefaultMaxBlockReservationLimit = uint64(10) - DefaultMaxFutureReservationLimit = uint64(302400) - DefaultBlockReservationFeeMultiplier = sdk.MustNewDecFromStr("0.0") - DefaultFutureReservationFeeMultiplier = sdk.MustNewDecFromStr("1000000000000.0") + DefaultCallbackGasLimit = uint64(1000000) + DefaultMaxBlockReservationLimit = uint64(3) + DefaultMaxFutureReservationLimit = uint64(10000) + DefaultBlockReservationFeeMultiplier = sdk.MustNewDecFromStr("1.0") + DefaultFutureReservationFeeMultiplier = sdk.MustNewDecFromStr("1.0") ) // NewParams creates a new Params instance. diff --git a/x/cwerrors/types/params.go b/x/cwerrors/types/params.go index e7482f37..c4edf900 100644 --- a/x/cwerrors/types/params.go +++ b/x/cwerrors/types/params.go @@ -7,9 +7,9 @@ import ( ) var ( - DefaultErrorStoredTime = int64(302400) // roughly 21 days - DefaultSubscriptionFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000000000000000) // 1 ARCH (1e18 attoarch) - DefaultSubscriptionPeriod = int64(302400) // roughly 21 days + DefaultErrorStoredTime = int64(302400) // roughly 21 days + DefaultSubscriptionFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 0) // 1 ARCH (1e18 attoarch) + DefaultSubscriptionPeriod = int64(302400) // roughly 21 days ) // NewParams creates a new Params instance. From 2b4a004c68c42d4c10b3817f81480a41d4732d65 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:02:11 +0530 Subject: [PATCH 4/7] using collections to store cwica module params --- app/app.go | 2 +- x/cwica/genesis.go | 6 +++++- x/cwica/keeper/grpc_query.go | 24 ++++++++++++++++++++---- x/cwica/keeper/grpc_query_test.go | 7 +++++-- x/cwica/keeper/keeper.go | 26 ++++++++++++++++++++++++-- x/cwica/keeper/msg_server.go | 5 ++++- x/cwica/keeper/msg_server_test.go | 3 ++- x/cwica/keeper/params.go | 20 +++----------------- x/cwica/keeper/params_test.go | 4 +++- x/cwica/module.go | 2 +- x/cwica/types/keys.go | 10 +++------- 11 files changed, 71 insertions(+), 38 deletions(-) diff --git a/app/app.go b/app/app.go index d17e704c..fcb6700a 100644 --- a/app/app.go +++ b/app/app.go @@ -615,7 +615,7 @@ func NewArchwayApp( app.Keepers.CWFeesKeeper = cwfees.NewKeeper(appCodec, keys[cwfees.ModuleName], app.Keepers.WASMKeeper) - app.Keepers.CWICAKeeper = *cwicakeeper.NewKeeper( + app.Keepers.CWICAKeeper = cwicakeeper.NewKeeper( appCodec, keys[cwicatypes.StoreKey], app.Keepers.IBCKeeper.ChannelKeeper, diff --git a/x/cwica/genesis.go b/x/cwica/genesis.go index dc731900..a7c024f2 100644 --- a/x/cwica/genesis.go +++ b/x/cwica/genesis.go @@ -22,7 +22,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) // ExportGenesis returns the cwica module's exported genesis. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { genesis := types.DefaultGenesis() - genesis.Params = k.GetParams(ctx) + params, err := k.GetParams(ctx) + if err != nil { + panic(err) + } + genesis.Params = params return genesis } diff --git a/x/cwica/keeper/grpc_query.go b/x/cwica/keeper/grpc_query.go index 01d11437..db2ba31e 100644 --- a/x/cwica/keeper/grpc_query.go +++ b/x/cwica/keeper/grpc_query.go @@ -10,14 +10,30 @@ import ( "github.com/archway-network/archway/x/cwica/types" ) -var _ types.QueryServer = Keeper{} +var _ types.QueryServer = &QueryServer{} + +type QueryServer struct { + keeper Keeper +} + +// NewQueryServer creates a new gRPC query server. +func NewQueryServer(keeper Keeper) *QueryServer { + return &QueryServer{ + keeper: keeper, + } +} // Params implements the Query/Params gRPC method -func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { +func (qs *QueryServer) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } - ctx := sdk.UnwrapSDKContext(c) + params, err := qs.keeper.GetParams(sdk.UnwrapSDKContext(c)) + if err != nil { + return nil, status.Errorf(codes.NotFound, "could not fetch the module params: %s", err.Error()) + } - return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil + return &types.QueryParamsResponse{ + Params: params, + }, nil } diff --git a/x/cwica/keeper/grpc_query_test.go b/x/cwica/keeper/grpc_query_test.go index a93cbc4a..b0e6199b 100644 --- a/x/cwica/keeper/grpc_query_test.go +++ b/x/cwica/keeper/grpc_query_test.go @@ -3,6 +3,7 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" + cwicaKeeper "github.com/archway-network/archway/x/cwica/keeper" "github.com/archway-network/archway/x/cwica/types" ) @@ -14,13 +15,15 @@ func (s *KeeperTestSuite) TestParamsQuery() { err := keeper.SetParams(ctx, params) s.Require().NoError(err) + queryServer := cwicaKeeper.NewQueryServer(keeper) + // TEST CASE 1: invalid request - response, err := keeper.Params(wctx, nil) + response, err := queryServer.Params(wctx, nil) s.Require().Error(err) s.Require().Nil(response) // TEST CASE 2: successfully fetched the params - response, err = keeper.Params(wctx, &types.QueryParamsRequest{}) + response, err = queryServer.Params(wctx, &types.QueryParamsRequest{}) s.Require().NoError(err) s.Require().Equal(&types.QueryParamsResponse{Params: params}, response) } diff --git a/x/cwica/keeper/keeper.go b/x/cwica/keeper/keeper.go index 22956820..d4872f1a 100644 --- a/x/cwica/keeper/keeper.go +++ b/x/cwica/keeper/keeper.go @@ -3,6 +3,8 @@ package keeper import ( "fmt" + "cosmossdk.io/collections" + "github.com/archway-network/archway/internal/collcompat" "github.com/archway-network/archway/x/cwica/types" "github.com/cometbft/cometbft/libs/log" @@ -21,6 +23,11 @@ type ( icaControllerKeeper types.ICAControllerKeeper sudoKeeper types.WasmKeeper authority string + + Schema collections.Schema + + // Params key: ParamsKeyPrefix | value: Params + Params collections.Item[types.Params] } ) @@ -33,8 +40,10 @@ func NewKeeper( icaControllerKeeper types.ICAControllerKeeper, sudoKeeper types.WasmKeeper, authority string, -) *Keeper { - return &Keeper{ +) Keeper { + sb := collections.NewSchemaBuilder(collcompat.NewKVStoreService(storeKey)) + + k := Keeper{ Codec: cdc, storeKey: storeKey, channelKeeper: channelKeeper, @@ -43,7 +52,20 @@ func NewKeeper( icaControllerKeeper: icaControllerKeeper, sudoKeeper: sudoKeeper, authority: authority, + Params: collections.NewItem( + sb, + types.ParamsKeyPrefix, + "params", + collcompat.ProtoValue[types.Params](cdc), + ), + } + + schema, err := sb.Build() + if err != nil { + panic(err) } + k.Schema = schema + return k } func (k *Keeper) Logger(ctx sdk.Context) log.Logger { diff --git a/x/cwica/keeper/msg_server.go b/x/cwica/keeper/msg_server.go index 66be26f9..1a4842e4 100644 --- a/x/cwica/keeper/msg_server.go +++ b/x/cwica/keeper/msg_server.go @@ -88,7 +88,10 @@ func (k Keeper) SendTx(goCtx context.Context, msg *types.MsgSendTx) (*types.MsgS return nil, errors.Wrapf(types.ErrNotContract, "%s is not a contract address", msg.ContractAddress) } - params := k.GetParams(ctx) + params, err := k.GetParams(ctx) + if err != nil { + return nil, errors.Wrap(err, "failed to GetParams") + } if uint64(len(msg.Msgs)) > params.GetMsgSendTxMaxMessages() { return nil, fmt.Errorf( "MsgSubmitTx contains more messages than allowed, has=%d, max=%d", diff --git a/x/cwica/keeper/msg_server_test.go b/x/cwica/keeper/msg_server_test.go index 65f27e23..35a3135a 100644 --- a/x/cwica/keeper/msg_server_test.go +++ b/x/cwica/keeper/msg_server_test.go @@ -107,7 +107,8 @@ func (s *KeeperTestSuite) TestSendTx() { contractAddress.String(), contractAdminAcc.Address.String(), ) - params := cwicaKeeper.GetParams(ctx) + params, err := cwicaKeeper.GetParams(ctx) + s.Require().NoError(err) maxMsgs := params.GetMsgSendTxMaxMessages() submitMsg.Msgs = make([]*codectypes.Any, maxMsgs+1) s.Require().True(wmKeeper.HasContractInfo(ctx, contractAddress)) diff --git a/x/cwica/keeper/params.go b/x/cwica/keeper/params.go index 655ec907..0ac6ddb5 100644 --- a/x/cwica/keeper/params.go +++ b/x/cwica/keeper/params.go @@ -7,25 +7,11 @@ import ( ) // GetParams get all parameters as types.Params -func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ParamsKey) - if bz == nil { - return params - } - - k.Codec.MustUnmarshal(bz, ¶ms) - return params +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params, err error) { + return k.Params.Get(ctx) } // SetParams set the params func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { - store := ctx.KVStore(k.storeKey) - bz, err := k.Codec.Marshal(¶ms) - if err != nil { - return err - } - - store.Set(types.ParamsKey, bz) - return nil + return k.Params.Set(ctx, params) } diff --git a/x/cwica/keeper/params_test.go b/x/cwica/keeper/params_test.go index ff99772a..71ce37f9 100644 --- a/x/cwica/keeper/params_test.go +++ b/x/cwica/keeper/params_test.go @@ -12,5 +12,7 @@ func (s *KeeperTestSuite) TestGetParams() { err := k.SetParams(ctx, params) s.Require().NoError(err) - s.Require().EqualValues(params, k.GetParams(ctx)) + p, err := k.GetParams(ctx) + s.Require().NoError(err) + s.Require().EqualValues(params, p) } diff --git a/x/cwica/module.go b/x/cwica/module.go index 7c8ceea8..26b0224a 100644 --- a/x/cwica/module.go +++ b/x/cwica/module.go @@ -140,7 +140,7 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) } diff --git a/x/cwica/types/keys.go b/x/cwica/types/keys.go index 94644022..34c5e643 100644 --- a/x/cwica/types/keys.go +++ b/x/cwica/types/keys.go @@ -1,5 +1,7 @@ package types +import "cosmossdk.io/collections" + const ( // ModuleName defines the module name ModuleName = "cwica" @@ -14,12 +16,6 @@ const ( QuerierRoute = ModuleName ) -const ( - // params key - prefixParamsKey = iota + 1 -) - var ( - // params store key - ParamsKey = []byte{prefixParamsKey} + ParamsKeyPrefix = collections.NewPrefix(1) ) From caacd0f026c3028772fa2b0d8f8be8100550006f Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:02:27 +0530 Subject: [PATCH 5/7] setting the default params in the upgrade handler --- app/upgrades/7_0_0/upgrades.go | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/upgrades/7_0_0/upgrades.go b/app/upgrades/7_0_0/upgrades.go index 75e08caa..d7215470 100644 --- a/app/upgrades/7_0_0/upgrades.go +++ b/app/upgrades/7_0_0/upgrades.go @@ -37,6 +37,46 @@ var Upgrade = upgrades.Upgrade{ return nil, err } + ctx.Logger().Info("Setting default params for the new modules") + // Setting callback params + callbackParams, err := keepers.CallbackKeeper.GetParams(ctx) + if err != nil { + return nil, err + } + callbackParams.CallbackGasLimit = 150000 + callbackParams.MaxBlockReservationLimit = 10 + callbackParams.MaxFutureReservationLimit = 432000 // roughly 30 days + callbackParams.BlockReservationFeeMultiplier = sdk.MustNewDecFromStr("0.0") + callbackParams.FutureReservationFeeMultiplier = sdk.MustNewDecFromStr("1000000000000.0") + err = keepers.CallbackKeeper.SetParams(ctx, callbackParams) + if err != nil { + return nil, err + } + + // Setting cwerrors params + cwerrorsParams, err := keepers.CWErrorsKeeper.GetParams(ctx) + if err != nil { + return nil, err + } + cwerrorsParams.ErrorStoredTime = 302400 // roughly 21 days + cwerrorsParams.SubscriptionFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000000000000000) // 1 ARCH (1e18 attoarch) + cwerrorsParams.SubscriptionPeriod = 302400 // roughly 21 days + err = keepers.CWErrorsKeeper.SetParams(ctx, cwerrorsParams) + if err != nil { + return nil, err + } + + // Setting cwica params + cwicaParams, err := keepers.CWICAKeeper.GetParams(ctx) + if err != nil { + return nil, err + } + cwicaParams.MsgSendTxMaxMessages = 5 + err = keepers.CWICAKeeper.SetParams(ctx, cwicaParams) + if err != nil { + return nil, err + } + ctx.Logger().Info(upgrades.ArchwayLogo + NameAsciiArt) return migrations, nil } From e69caef025ceedf82206dece016d5b7a080bc472 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:04:23 +0530 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94cf9f79..a13d5d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Contains all the PRs that improved the code without changing the behaviors. ### Changed - [#505](https://github.com/archway-network/archway/pull/505) - Update release process to account for release candidates on Titus +- [#558](https://github.com/archway-network/archway/pull/558) - Updated the new modules default params in upgrade handler ### Fixed - [#537](https://github.com/archway-network/archway/pull/537) - Fix issue with callback failing when module param is changed From 66d75dc892bbdbe91cd875b1116ecdab7e8fe9ee Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:18:51 +0530 Subject: [PATCH 7/7] =?UTF-8?q?linting=20=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- x/cwica/keeper/ibc_handlers.go | 1 - x/cwica/keeper/keeper.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/x/cwica/keeper/ibc_handlers.go b/x/cwica/keeper/ibc_handlers.go index 6b662608..7a2ac48c 100644 --- a/x/cwica/keeper/ibc_handlers.go +++ b/x/cwica/keeper/ibc_handlers.go @@ -84,7 +84,6 @@ func (k *Keeper) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Pack if err != nil { k.Logger(ctx).Debug("HandleAcknowledgement: failed to Sudo contract on packet acknowledgement", "error", err) } - } else { // if error from the counterparty chain packetMsg, err := json.Marshal(packet) if err != nil { diff --git a/x/cwica/keeper/keeper.go b/x/cwica/keeper/keeper.go index d4872f1a..d3669431 100644 --- a/x/cwica/keeper/keeper.go +++ b/x/cwica/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "fmt" "cosmossdk.io/collections" + "github.com/archway-network/archway/internal/collcompat" "github.com/archway-network/archway/x/cwica/types"