From 89b9cbc81a71aa8b9098afa42503749beea2f4d5 Mon Sep 17 00:00:00 2001 From: Norman Meier Date: Thu, 11 Jan 2024 15:10:06 +0100 Subject: [PATCH 1/8] chore: run linter on CI Signed-off-by: Norman Meier --- .github/workflows/go.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 53085fd..fa59304 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Tidy go.mod run: go mod tidy @@ -22,6 +22,12 @@ jobs: - name: Check diff run: git diff --exit-code + - name: Install golangci-lint + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 + + - name: Lint + run: make lint + - name: Build run: make build From f2c3735d922a03f6b716e3ebe30bf58c2e21b8cc Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 11:17:02 +0800 Subject: [PATCH 2/8] fix few lint issues --- app/ante_handler.go | 19 ++++++++++--------- app/fee.go | 13 +++++++------ cmd/teritorid/cmd/richest_snapshot.go | 4 ++-- x/airdrop/handler.go | 3 ++- x/intertx/client/cli/tx.go | 4 ++-- x/intertx/ibc_module.go | 8 +++++--- x/intertx/keeper/msg_server.go | 5 ++--- x/intertx/types/msgs.go | 7 ++++--- 8 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app/ante_handler.go b/app/ante_handler.go index 311c0ad..c64bb02 100644 --- a/app/ante_handler.go +++ b/app/ante_handler.go @@ -1,6 +1,7 @@ package teritori import ( + "cosmossdk.io/errors" "cosmossdk.io/math" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -62,7 +63,7 @@ func (min MinCommissionDecorator) AnteHandle( // commission set below 5% c := msg.Commission if c.Rate.LT(minCommissionRate) { - return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%") + return errors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%") } case *stakingtypes.MsgEditValidator: // if commission rate is nil, it means only @@ -71,7 +72,7 @@ func (min MinCommissionDecorator) AnteHandle( break } if msg.CommissionRate.LT(minCommissionRate) { - return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%") + return errors.Wrap(sdkerrors.ErrUnauthorized, "commission can't be lower than 5%") } case *stakingtypes.MsgDelegate: val, err := min.getValidator(ctx, msg.ValidatorAddress) @@ -81,7 +82,7 @@ func (min MinCommissionDecorator) AnteHandle( projectedVotingPower := min.CalculateDelegateProjectedVotingPower(ctx, val, sdk.NewDecFromInt(msg.Amount.Amount)) if projectedVotingPower.GTE(maxVotingPower) { - return sdkerrors.Wrapf( + return errors.Wrapf( sdkerrors.ErrInvalidRequest, "This validator has a voting power of %s%%. Delegations not allowed to a validator whose post-delegation voting power is more than %s%%. Please delegate to a validator with less bonded tokens", projectedVotingPower, maxVotingPower) } @@ -102,7 +103,7 @@ func (min MinCommissionDecorator) AnteHandle( projectedVotingPower := min.CalculateRedelegateProjectedVotingPower(ctx, dstVal, delegateAmount) if projectedVotingPower.GTE(maxVotingPower) { - return sdkerrors.Wrapf( + return errors.Wrapf( sdkerrors.ErrInvalidRequest, "This validator has a voting power of %s%%. Delegations not allowed to a validator whose post-delegation voting power is more than %s%%. Please redelegate to a validator with less bonded tokens", projectedVotingPower, maxVotingPower) } @@ -116,7 +117,7 @@ func (min MinCommissionDecorator) AnteHandle( var innerMsg sdk.Msg err := min.cdc.UnpackAny(v, &innerMsg) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs") + return errors.Wrapf(sdkerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs") } err = validMsg(innerMsg) @@ -150,7 +151,7 @@ func (min MinCommissionDecorator) AnteHandle( func (min MinCommissionDecorator) getValidator(ctx sdk.Context, bech32ValAddr string) (stakingtypes.Validator, error) { valAddr, err := sdk.ValAddressFromBech32(bech32ValAddr) if err != nil { - return stakingtypes.Validator{}, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, bech32ValAddr) + return stakingtypes.Validator{}, errors.Wrap(sdkerrors.ErrInvalidAddress, bech32ValAddr) } val, found := min.sk.GetValidator(ctx, valAddr) @@ -198,15 +199,15 @@ func (min MinCommissionDecorator) CalculateRedelegateProjectedVotingPower(ctx sd // signer. func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") + return nil, errors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") + return nil, errors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return nil, errors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } var sigGasConsumer = options.SigGasConsumer diff --git a/app/fee.go b/app/fee.go index 385b7cf..91aa66d 100644 --- a/app/fee.go +++ b/app/fee.go @@ -3,6 +3,7 @@ package teritori import ( "fmt" + "cosmossdk.io/errors" airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper" airdroptypes "github.com/TERITORI/teritori-chain/x/airdrop/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,7 +35,7 @@ func NewDeductFeeDecorator(ak ante.AccountKeeper, bk types.BankKeeper, fk ante.F func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { - return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return ctx, errors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } if addr := dfd.ak.GetModuleAddress(types.FeeCollectorName); addr == nil { @@ -51,12 +52,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo // this works with only when feegrant enabled. if feeGranter != nil { if dfd.feegrantKeeper == nil { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled") + return ctx, errors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled") } else if !feeGranter.Equals(feePayer) { err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs()) if err != nil { - return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer) + return ctx, errors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer) } } @@ -85,7 +86,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo deductFeesFromAcc := dfd.ak.GetAccount(ctx, deductFeesFrom) if deductFeesFromAcc == nil { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom) + return ctx, errors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom) } // deduct the fees @@ -107,12 +108,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo // DeductFees deducts fees from the given account. func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins) error { if !fees.IsValid() { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) + return errors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) } err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) + return errors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) } return nil diff --git a/cmd/teritorid/cmd/richest_snapshot.go b/cmd/teritorid/cmd/richest_snapshot.go index ed5930c..c097881 100644 --- a/cmd/teritorid/cmd/richest_snapshot.go +++ b/cmd/teritorid/cmd/richest_snapshot.go @@ -4,7 +4,7 @@ import ( "encoding/csv" "encoding/json" "fmt" - "io/ioutil" + "io" "os" "sort" @@ -94,7 +94,7 @@ Example: } defer genesisJson.Close() - byteValue, _ := ioutil.ReadAll(genesisJson) + byteValue, _ := io.ReadAll(genesisJson) var genState GenesisState diff --git a/x/airdrop/handler.go b/x/airdrop/handler.go index f84e70f..ff3559b 100644 --- a/x/airdrop/handler.go +++ b/x/airdrop/handler.go @@ -3,6 +3,7 @@ package airdrop import ( "fmt" + "cosmossdk.io/errors" "github.com/TERITORI/teritori-chain/x/airdrop/keeper" "github.com/TERITORI/teritori-chain/x/airdrop/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,7 +36,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } } diff --git a/x/intertx/client/cli/tx.go b/x/intertx/client/cli/tx.go index 684ba9c..75462bd 100644 --- a/x/intertx/client/cli/tx.go +++ b/x/intertx/client/cli/tx.go @@ -2,7 +2,7 @@ package cli import ( "fmt" - "io/ioutil" + "os" "github.com/TERITORI/teritori-chain/x/intertx/types" "github.com/cosmos/cosmos-sdk/client" @@ -79,7 +79,7 @@ func getSubmitTxCmd() *cobra.Command { if err := cdc.UnmarshalInterfaceJSON([]byte(args[0]), &txMsg); err != nil { // check for file path if JSON input is not provided - contents, err := ioutil.ReadFile(args[0]) + contents, err := os.ReadFile(args[0]) if err != nil { return errors.Wrap(err, "neither JSON input nor path to .json file for sdk msg were provided") } diff --git a/x/intertx/ibc_module.go b/x/intertx/ibc_module.go index c781a9a..dd74a95 100644 --- a/x/intertx/ibc_module.go +++ b/x/intertx/ibc_module.go @@ -3,6 +3,8 @@ package intertx import ( "errors" + errorsmod "cosmossdk.io/errors" + proto "github.com/gogo/protobuf/proto" "github.com/TERITORI/teritori-chain/x/intertx/keeper" @@ -116,12 +118,12 @@ func (im IBCModule) OnAcknowledgementPacket( ) error { var ack channeltypes.Acknowledgement if err := channeltypes.SubModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 packet acknowledgement: %v", err) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 packet acknowledgement: %v", err) } txMsgData := &sdk.TxMsgData{} if err := proto.Unmarshal(ack.GetResult(), txMsgData); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %v", err) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %v", err) } switch len(txMsgData.Data) { @@ -167,7 +169,7 @@ func handleMsgData(ctx sdk.Context, msgData *sdk.MsgData) (string, error) { case sdk.MsgTypeURL(&banktypes.MsgSend{}): msgResponse := &banktypes.MsgSendResponse{} if err := proto.Unmarshal(msgData.Data, msgResponse); err != nil { - return "", sdkerrors.Wrapf(sdkerrors.ErrJSONUnmarshal, "cannot unmarshal send response message: %s", err.Error()) + return "", errorsmod.Wrapf(sdkerrors.ErrJSONUnmarshal, "cannot unmarshal send response message: %s", err.Error()) } return msgResponse.String(), nil diff --git a/x/intertx/keeper/msg_server.go b/x/intertx/keeper/msg_server.go index 3cd11a2..1f6a56e 100644 --- a/x/intertx/keeper/msg_server.go +++ b/x/intertx/keeper/msg_server.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cosmostypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -55,12 +54,12 @@ func (k msgServer) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*typ channelID, found := k.icaControllerKeeper.GetActiveChannelID(ctx, msg.ConnectionId, portID) if !found { - return nil, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) + return nil, errors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) } chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if !found { - return nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return nil, errors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } data, err := SerializeCosmosTx(k.Keeper.cdc, msg.Msgs) if err != nil { diff --git a/x/intertx/types/msgs.go b/x/intertx/types/msgs.go index 07aefd1..05fb892 100644 --- a/x/intertx/types/msgs.go +++ b/x/intertx/types/msgs.go @@ -4,6 +4,7 @@ import ( fmt "fmt" "strings" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -28,11 +29,11 @@ func NewMsgRegisterAccount(owner, connectionID string) *MsgRegisterAccount { // ValidateBasic implements sdk.Msg func (msg MsgRegisterAccount) ValidateBasic() error { if strings.TrimSpace(msg.Owner) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "missing sender address") + return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "missing sender address") } if _, err := sdk.AccAddressFromBech32(msg.Owner); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Owner) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Owner) } return nil @@ -123,7 +124,7 @@ func (msg MsgSubmitTx) GetSigners() []sdk.AccAddress { func (msg MsgSubmitTx) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Owner) if err != nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid owner address") + return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid owner address") } return nil From d30835a74de4a42ff9c158f8333e494ca5a465a6 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 11:21:29 +0800 Subject: [PATCH 3/8] lint --- x/airdrop/module.go | 2 +- x/airdrop/types/errors.go | 2 +- x/intertx/types/errors.go | 6 +++--- x/intertx/types/msgs.go | 3 --- x/mint/module.go | 8 ++++---- x/mint/types/errors.go | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/x/airdrop/module.go b/x/airdrop/module.go index 32659d1..73c65ae 100644 --- a/x/airdrop/module.go +++ b/x/airdrop/module.go @@ -155,7 +155,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { // ProposalContents returns all the gov content functions used to // simulate governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/airdrop/types/errors.go b/x/airdrop/types/errors.go index 9899b22..40ebb6e 100644 --- a/x/airdrop/types/errors.go +++ b/x/airdrop/types/errors.go @@ -1,7 +1,7 @@ package types import ( - "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/errors" ) // errors diff --git a/x/intertx/types/errors.go b/x/intertx/types/errors.go index 1ab267c..05f38f2 100644 --- a/x/intertx/types/errors.go +++ b/x/intertx/types/errors.go @@ -1,10 +1,10 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/errors" ) var ( - ErrIBCAccountAlreadyExist = sdkerrors.Register(ModuleName, 2, "interchain account already registered") - ErrIBCAccountNotExist = sdkerrors.Register(ModuleName, 3, "interchain account not exist") + ErrIBCAccountAlreadyExist = errors.Register(ModuleName, 2, "interchain account already registered") + ErrIBCAccountNotExist = errors.Register(ModuleName, 3, "interchain account not exist") ) diff --git a/x/intertx/types/msgs.go b/x/intertx/types/msgs.go index 05fb892..0a8513a 100644 --- a/x/intertx/types/msgs.go +++ b/x/intertx/types/msgs.go @@ -80,15 +80,12 @@ func PackTxMsgAny(sdkMsg sdk.Msg) (*codectypes.Any, error) { // UnpackInterfaces implements codectypes.UnpackInterfacesMessage func (msg MsgSubmitTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - var sdkMsg []sdk.Msg for _, any := range msg.Msgs { var msg sdk.Msg err := unpacker.UnpackAny(any, &msg) if err != nil { return err } - - sdkMsg = append(sdkMsg, msg) } return nil diff --git a/x/mint/module.go b/x/mint/module.go index 1b5d1a0..6fa640a 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -2,9 +2,9 @@ The `mint` module is responsible for creating tokens in a flexible way to reward validators, incentivize providing pool liquidity, provide funds for governance, and pay developers to maintain. - - Denom minting; reduction and reserve ratio settings - - Token distribution proportions - - Endblocker distribution settings + - Denom minting; reduction and reserve ratio settings + - Token distribution proportions + - Endblocker distribution settings */ package mint @@ -177,7 +177,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { } // ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/mint/types/errors.go b/x/mint/types/errors.go index e491acd..cd86808 100644 --- a/x/mint/types/errors.go +++ b/x/mint/types/errors.go @@ -1,7 +1,7 @@ package types import ( - "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/errors" ) // errors From d5f87dab2be6436e7b69e5d351b46b8f465d0d6a Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 18:02:39 +0800 Subject: [PATCH 4/8] lint --- app/app.go | 39 +++++++++++++------------- app/keepers/keepers.go | 5 ++-- app/test_helpers.go | 3 +- app/upgrades/v200/upgrades.go | 4 +-- cmd/teritorid/cmd/prepare_genesis.go | 6 ++-- x/intertx/ibc_module.go | 41 +--------------------------- x/intertx/keeper/msg_server.go | 19 ++----------- 7 files changed, 29 insertions(+), 88 deletions(-) diff --git a/app/app.go b/app/app.go index f5695ec..aabf4b1 100644 --- a/app/app.go +++ b/app/app.go @@ -80,7 +80,6 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -159,23 +158,23 @@ var ( // GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to // produce a list of enabled proposals to pass into wasmd app. -func GetEnabledProposals() []wasm.ProposalType { +func GetEnabledProposals() []wasmtypes.ProposalType { if EnableSpecificProposals == "" { if ProposalsEnabled == "true" { - return wasm.EnableAllProposals + return wasmtypes.EnableAllProposals } - return wasm.DisableAllProposals + return wasmtypes.DisableAllProposals } chunks := strings.Split(EnableSpecificProposals, ",") - proposals, err := wasm.ConvertToProposals(chunks) + proposals, err := wasmtypes.ConvertToProposals(chunks) if err != nil { panic(err) } return proposals } -func GetWasmOpts(appOpts servertypes.AppOptions) []wasm.Option { - var wasmOpts []wasm.Option +func GetWasmOpts(appOpts servertypes.AppOptions) []wasmkeeper.Option { + var wasmOpts []wasmkeeper.Option if cast.ToBool(appOpts.Get("telemetry.enabled")) { wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer)) } @@ -323,7 +322,7 @@ func NewTeritoriApp( ibcfeetypes.StoreKey, icahosttypes.StoreKey, airdroptypes.StoreKey, - wasm.StoreKey, + wasmtypes.StoreKey, consensusparamtypes.StoreKey, intertxtypes.StoreKey, crisistypes.StoreKey, @@ -363,7 +362,7 @@ func NewTeritoriApp( scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) - scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName) + scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName) // add keepers app.AccountKeeper = authkeeper.NewAccountKeeper( @@ -574,9 +573,9 @@ func NewTeritoriApp( // if we want to allow any custom callbacks availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2" wasmOpts := GetWasmOpts(appOpts) - app.WasmKeeper = wasm.NewKeeper( + app.WasmKeeper = wasmkeeper.NewKeeper( appCodec, - keys[wasm.StoreKey], + keys[wasmtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.StakingKeeper, @@ -598,7 +597,7 @@ func NewTeritoriApp( // register wasm gov proposal types enabledProposals := GetEnabledProposals() if len(enabledProposals) != 0 { - govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) + govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck } var wasmStack ibcporttypes.IBCModule @@ -611,7 +610,7 @@ func NewTeritoriApp( AddRoute(icahosttypes.SubModuleName, icaHostIBCModule). AddRoute(ibctransfertypes.ModuleName, transferIBCModule). AddRoute(intertxtypes.ModuleName, icaControllerStack). - AddRoute(wasm.ModuleName, wasmStack) + AddRoute(wasmtypes.ModuleName, wasmStack) app.IBCKeeper.SetRouter(ibcRouter) app.GovKeeper = *govKeeper.SetHooks( @@ -650,7 +649,7 @@ func NewTeritoriApp( groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), transferModule, icaModule, - wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasm.ModuleName)), + wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), packetforwardModule, interTxModule, @@ -684,7 +683,7 @@ func NewTeritoriApp( icatypes.ModuleName, packetforwardtypes.ModuleName, airdroptypes.ModuleName, - wasm.ModuleName, + wasmtypes.ModuleName, intertxtypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -711,7 +710,7 @@ func NewTeritoriApp( feegrant.ModuleName, authz.ModuleName, airdroptypes.ModuleName, - wasm.ModuleName, + wasmtypes.ModuleName, intertxtypes.ModuleName, ) @@ -744,7 +743,7 @@ func NewTeritoriApp( authz.ModuleName, packetforwardtypes.ModuleName, airdroptypes.ModuleName, - wasm.ModuleName, + wasmtypes.ModuleName, intertxtypes.ModuleName, ) @@ -784,7 +783,7 @@ func NewTeritoriApp( BankKeeper: app.BankKeeper, AirdropKeeper: &app.AirdropKeeper, IBCKeeper: app.IBCKeeper, - TxCounterStoreKey: keys[wasm.StoreKey], + TxCounterStoreKey: keys[wasmtypes.StoreKey], WasmConfig: wasmConfig, Cdc: appCodec, }, @@ -1027,11 +1026,11 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(minttypes.ModuleName) paramsKeeper.Subspace(distrtypes.ModuleName) paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) + paramsKeeper.Subspace(govtypes.ModuleName) paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) - paramsKeeper.Subspace(wasm.ModuleName) + paramsKeeper.Subspace(wasmtypes.ModuleName) paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 6a5e2f7..3db30f6 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -1,6 +1,7 @@ package keepers import ( + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper" intertxkeeper "github.com/TERITORI/teritori-chain/x/intertx/keeper" mintkeeper "github.com/TERITORI/teritori-chain/x/mint/keeper" @@ -26,8 +27,6 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - "github.com/CosmWasm/wasmd/x/wasm" - // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) @@ -67,6 +66,6 @@ type AppKeepers struct { ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper ScopedInterTxKeeper capabilitykeeper.ScopedKeeper - WasmKeeper wasm.Keeper + WasmKeeper wasmkeeper.Keeper ScopedWasmKeeper capabilitykeeper.ScopedKeeper } diff --git a/app/test_helpers.go b/app/test_helpers.go index b2176d5..fd8398c 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -5,7 +5,6 @@ import ( "time" sdkmath "cosmossdk.io/math" - "github.com/CosmWasm/wasmd/x/wasm" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto/secp256k1" @@ -26,7 +25,7 @@ import ( ) // InitNewApp initiate a new TeritoriApp object -func InitNewApp(opts ...wasm.Option) *TeritoriApp { +func InitNewApp() *TeritoriApp { db := dbm.NewMemDB() appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome diff --git a/app/upgrades/v200/upgrades.go b/app/upgrades/v200/upgrades.go index 740d10b..869b6d5 100644 --- a/app/upgrades/v200/upgrades.go +++ b/app/upgrades/v200/upgrades.go @@ -3,7 +3,6 @@ package v200 import ( "reflect" - "github.com/CosmWasm/wasmd/x/wasm" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/TERITORI/teritori-chain/app/keepers" minttypes "github.com/TERITORI/teritori-chain/x/mint/types" @@ -21,6 +20,7 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) +//nolint:all func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, @@ -48,7 +48,7 @@ func CreateUpgradeHandler( keyTable = govv1.ParamKeyTable() case distrtypes.ModuleName: keyTable = distrtypes.ParamKeyTable() - case wasm.ModuleName: + case wasmtypes.ModuleName: keyTable = wasmtypes.ParamKeyTable() case minttypes.ModuleName: keyTable = minttypes.ParamKeyTable() diff --git a/cmd/teritorid/cmd/prepare_genesis.go b/cmd/teritorid/cmd/prepare_genesis.go index 93a956c..b40b06c 100644 --- a/cmd/teritorid/cmd/prepare_genesis.go +++ b/cmd/teritorid/cmd/prepare_genesis.go @@ -410,8 +410,6 @@ func PrepareGenesis(clientCtx client.Context, appState map[string]json.RawMessag // distribution module genesis distributionGenState := distributiontypes.DefaultGenesisState() distributionGenState.Params = distributiontypes.DefaultParams() - distributionGenState.Params.BaseProposerReward = sdk.ZeroDec() - distributionGenState.Params.BonusProposerReward = sdk.ZeroDec() distributionGenState.FeePool.CommunityPool = sdk.NewDecCoinsFromCoins(communityPoolCoins...) distributionGenStateBz, err := cdc.MarshalJSON(distributionGenState) if err != nil { @@ -421,9 +419,9 @@ func PrepareGenesis(clientCtx client.Context, appState map[string]json.RawMessag // gov module genesis govGenState := govv1.DefaultGenesisState() - govGenState.DepositParams.MinDeposit = sdk.Coins{sdk.NewInt64Coin(appparams.BaseCoinUnit, 500_000_000)} // 500 TORI + govGenState.Params.MinDeposit = sdk.Coins{sdk.NewInt64Coin(appparams.BaseCoinUnit, 500_000_000)} // 500 TORI duration := time.Hour * 24 * 2 - govGenState.VotingParams.VotingPeriod = &duration // 2 days + govGenState.Params.VotingPeriod = &duration // 2 days govGenStateBz, err := cdc.MarshalJSON(govGenState) if err != nil { return nil, nil, fmt.Errorf("failed to marshal gov genesis state: %w", err) diff --git a/x/intertx/ibc_module.go b/x/intertx/ibc_module.go index dd74a95..1851b33 100644 --- a/x/intertx/ibc_module.go +++ b/x/intertx/ibc_module.go @@ -5,12 +5,9 @@ import ( errorsmod "cosmossdk.io/errors" - proto "github.com/gogo/protobuf/proto" - "github.com/TERITORI/teritori-chain/x/intertx/keeper" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -121,26 +118,7 @@ func (im IBCModule) OnAcknowledgementPacket( return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 packet acknowledgement: %v", err) } - txMsgData := &sdk.TxMsgData{} - if err := proto.Unmarshal(ack.GetResult(), txMsgData); err != nil { - return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %v", err) - } - - switch len(txMsgData.Data) { - case 0: - // TODO: handle for sdk 0.46.x - return nil - default: - for _, msgData := range txMsgData.Data { - response, err := handleMsgData(ctx, msgData) - if err != nil { - return err - } - - im.keeper.Logger(ctx).Info("message response in ICS-27 packet response", "response", response) - } - return nil - } + return nil } // OnTimeoutPacket implements the IBCModule interface. @@ -163,20 +141,3 @@ func (im IBCModule) NegotiateAppVersion( ) (string, error) { return "", nil } - -func handleMsgData(ctx sdk.Context, msgData *sdk.MsgData) (string, error) { - switch msgData.MsgType { - case sdk.MsgTypeURL(&banktypes.MsgSend{}): - msgResponse := &banktypes.MsgSendResponse{} - if err := proto.Unmarshal(msgData.Data, msgResponse); err != nil { - return "", errorsmod.Wrapf(sdkerrors.ErrJSONUnmarshal, "cannot unmarshal send response message: %s", err.Error()) - } - - return msgResponse.String(), nil - - // TODO: handle other messages - - default: - return "", nil - } -} diff --git a/x/intertx/keeper/msg_server.go b/x/intertx/keeper/msg_server.go index 1f6a56e..c3af06d 100644 --- a/x/intertx/keeper/msg_server.go +++ b/x/intertx/keeper/msg_server.go @@ -12,8 +12,6 @@ import ( icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) var _ types.MsgServer = msgServer{} @@ -47,20 +45,6 @@ func (k msgServer) RegisterAccount(goCtx context.Context, msg *types.MsgRegister func (k msgServer) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - portID, err := icatypes.NewControllerPortID(msg.Owner) - if err != nil { - return nil, err - } - - channelID, found := k.icaControllerKeeper.GetActiveChannelID(ctx, msg.ConnectionId, portID) - if !found { - return nil, errors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) - } - - chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) - if !found { - return nil, errors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") - } data, err := SerializeCosmosTx(k.Keeper.cdc, msg.Msgs) if err != nil { return nil, err @@ -74,7 +58,8 @@ func (k msgServer) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*typ // timeoutTimestamp set to max value with the unsigned bit shifted to sastisfy hermes timestamp conversion // it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp timeoutTimestamp := ctx.BlockTime().Add(time.Minute).UnixNano() - _, err = k.icaControllerKeeper.SendTx(ctx, chanCap, msg.ConnectionId, portID, packetData, uint64(timeoutTimestamp)) + msgServer := icacontrollerkeeper.NewMsgServerImpl(&k.icaControllerKeeper) + _, err = msgServer.SendTx(ctx, icacontrollertypes.NewMsgSendTx(msg.Owner, msg.ConnectionId, uint64(timeoutTimestamp), packetData)) if err != nil { return nil, err } From f07c766492de98909645a8d1c616c08cf4c74777 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 18:03:58 +0800 Subject: [PATCH 5/8] add gov module legacy router --- app/app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/app.go b/app/app.go index aabf4b1..bb9b249 100644 --- a/app/app.go +++ b/app/app.go @@ -599,6 +599,8 @@ func NewTeritoriApp( if len(enabledProposals) != 0 { govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck } + // Set legacy router for backwards compatibility with gov v1beta1 + app.GovKeeper.SetLegacyRouter(govRouter) var wasmStack ibcporttypes.IBCModule wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) From c639d95fafee7b639b890b692df1e7e0744039af Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 18:11:26 +0800 Subject: [PATCH 6/8] add ci lint timeout --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b6732fa..4b9cc00 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ format-tools: go install github.com/daixiang0/gci@v0.11.2 lint: format-tools - golangci-lint run --tests=false + golangci-lint run --tests=false --timeout=1m find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d format: format-tools From d2d0400f8b17004281db57a114852ee67f2a26d4 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 18:16:07 +0800 Subject: [PATCH 7/8] update timeout to 3min --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4b9cc00..4f2be03 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ format-tools: go install github.com/daixiang0/gci@v0.11.2 lint: format-tools - golangci-lint run --tests=false --timeout=1m + golangci-lint run --tests=false --timeout=3m find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d format: format-tools From 2e26e410dce64997aa03d8d6658e3fa090be9506 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 12 Jan 2024 18:17:13 +0800 Subject: [PATCH 8/8] update timeout to 180s --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4f2be03..dbb37c6 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ format-tools: go install github.com/daixiang0/gci@v0.11.2 lint: format-tools - golangci-lint run --tests=false --timeout=3m + golangci-lint run --tests=false --timeout=180s find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d format: format-tools