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: update new module params for upgrade + refactor x/cwica params to use collections #558

Merged
merged 7 commits into from
Apr 11, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions app/upgrades/7_0_0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions x/cwerrors/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, 0) // 1 ARCH (1e18 attoarch)
DefaultSubscriptionPeriod = int64(302400) // roughly 21 days
)

// NewParams creates a new Params instance.
Expand Down
6 changes: 5 additions & 1 deletion x/cwica/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 20 additions & 4 deletions x/cwica/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions x/cwica/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
1 change: 0 additions & 1 deletion x/cwica/keeper/ibc_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 25 additions & 2 deletions x/cwica/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ 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"
Expand All @@ -21,6 +24,11 @@ type (
icaControllerKeeper types.ICAControllerKeeper
sudoKeeper types.WasmKeeper
authority string

Schema collections.Schema

// Params key: ParamsKeyPrefix | value: Params
Params collections.Item[types.Params]
}
)

Expand All @@ -33,8 +41,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,
Expand All @@ -43,7 +53,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 {
Expand Down
5 changes: 4 additions & 1 deletion x/cwica/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion x/cwica/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 3 additions & 17 deletions x/cwica/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
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(&params)
if err != nil {
return err
}

store.Set(types.ParamsKey, bz)
return nil
return k.Params.Set(ctx, params)
}
4 changes: 3 additions & 1 deletion x/cwica/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion x/cwica/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
10 changes: 3 additions & 7 deletions x/cwica/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "cosmossdk.io/collections"

const (
// ModuleName defines the module name
ModuleName = "cwica"
Expand All @@ -14,12 +16,6 @@ const (
QuerierRoute = ModuleName
)

const (
// params key
prefixParamsKey = iota + 1
)

var (
// params store key
ParamsKey = []byte{prefixParamsKey}
ParamsKeyPrefix = collections.NewPrefix(1)
)
16 changes: 0 additions & 16 deletions x/cwica/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand All @@ -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())
Expand Down
Loading