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

Upgrade cosmos-sdk in irishub to v0.50.10 #2975

Merged
merged 16 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 9 additions & 8 deletions app/ante/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ante
import (
"strings"

sdkerrors "cosmossdk.io/errors"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consolidate error handling imports

The file currently imports both sdkerrors and errortypes which can lead to confusion. In Cosmos SDK v0.50.x, the recommended approach is to use cosmossdk.io/errors exclusively.

-sdkerrors "cosmossdk.io/errors"
-errortypes "github.com/cosmos/cosmos-sdk/types/errors"
+sdkerrors "cosmossdk.io/errors"

Then update all error usages to use sdkerrors.ErrXXX instead of errortypes.ErrXXX.

Also applies to: 8-8

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"

coinswaptypes "mods.irisnet.org/modules/coinswap/types"
servicetypes "mods.irisnet.org/modules/service/types"
Expand Down Expand Up @@ -38,23 +39,23 @@ func (vtd ValidateTokenDecorator) AnteHandle(
switch msg := msg.(type) {
case *ibctransfertypes.MsgTransfer:
if containSwapCoin(msg.Token) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "can't transfer coinswap liquidity tokens through the IBC module")
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't transfer coinswap liquidity tokens through the IBC module")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update error handling pattern

The current error wrapping pattern uses sdkerrors.Wrap(errortypes.ErrXXX, ...). With the migration to Cosmos SDK v0.50.x, we should use the new error types directly from cosmossdk.io/errors.

-return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't transfer coinswap liquidity tokens through the IBC module")
+return ctx, sdkerrors.ErrInvalidRequest.Wrap("can't transfer coinswap liquidity tokens through the IBC module")

Apply similar changes to all error handling instances in this file.

Also applies to: 46-46, 50-50, 54-54, 58-58, 84-84

}
case *tokentypesv1.MsgBurnToken:
if _, err := vtd.tk.GetToken(ctx, msg.Coin.Denom); err != nil {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "burnt failed, only native tokens can be burnt")
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "burnt failed, only native tokens can be burnt")
}
case *tokentypesv1beta1.MsgBurnToken:
if _, err := vtd.tk.GetToken(ctx, msg.Symbol); err != nil {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "burnt failed, only native tokens can be burnt")
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "burnt failed, only native tokens can be burnt")
}
case *govv1.MsgSubmitProposal:
if containSwapCoin(msg.InitialDeposit...) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal")
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal")
}
case *govv1.MsgDeposit:
if containSwapCoin(msg.Amount...) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal")
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal")
}
}
}
Expand All @@ -80,7 +81,7 @@ func (vsd ValidateServiceDecorator) AnteHandle(
switch msg := msg.(type) {
case *servicetypes.MsgCallService:
if msg.Repeated {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "currently does not support to create repeatable service invocation")
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "currently does not support to create repeatable service invocation")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

ethante "github.com/evmos/ethermint/app/ante"

Expand Down
2 changes: 1 addition & 1 deletion app/ante/reject_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (rmd RejectMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
case *vestingtypes.MsgCreateVestingAccount,
*vestingtypes.MsgCreatePermanentLockedAccount,
*vestingtypes.MsgCreatePeriodicVestingAccount:
return ctx, errortypes.Wrap(
return ctx, errorsmod.Wrap(
errortypes.ErrInvalidType,
"currently doesn't support creating vesting account")
Comment on lines +31 to 33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Migration to errorsmod.Wrap is incomplete across the codebase

The verification reveals inconsistent error handling patterns:

  • Several files still use the old errortypes import from github.com/cosmos/cosmos-sdk/types/errors:

    • modules/mint/keeper/msg_server.go
    • modules/evm/state_transition.go
    • modules/guardian/handler.go
    • modules/guardian/types/msgs.go
    • app/ante/decorators.go
    • app/ante/ante.go
  • Mixed usage of error wrapping:

    • Some files use errorsmod.Wrap (new pattern)
    • Others still use sdkerrors.Wrap with the old errortypes

The codebase should consistently use errorsmod from cosmossdk.io/errors for alignment with Cosmos SDK v0.50.x.

🔗 Analysis chain

LGTM! Error handling update aligns with Cosmos SDK v0.50.x

The change from errortypes.Wrap to errorsmod.Wrap is correct and consistent with Cosmos SDK v0.50.x error handling patterns.

Let's verify the consistency of error handling across the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining old error handling patterns
rg "errortypes\.Wrap" --type go

Length of output: 33


Script:

#!/bin/bash
# Let's check for both old and new error handling patterns to ensure consistency
echo "Checking for errortypes imports..."
rg "\"github.com/cosmos/cosmos-sdk/types/errors\"" --type go

echo -e "\nChecking for errorsmod imports..."
rg "\"cosmossdk.io/errors\"" --type go

echo -e "\nChecking for error wrapping patterns..."
rg "\.Wrap\(" --type go -A 1

Length of output: 4734

}
Expand Down
6 changes: 3 additions & 3 deletions app/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ante
import (
"fmt"

storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -20,7 +20,7 @@ const (
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
// by the concrete type.
func DefaultSigVerificationGasConsumer(
meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params,
meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params,
) error {
pubkey := sig.PubKey
switch pubkey := pubkey.(type) {
Expand All @@ -43,7 +43,7 @@ func DefaultSigVerificationGasConsumer(

// ConsumeMultisignatureVerificationGas consumes gas from a GasMeter for verifying a multisig pubkey signature
func ConsumeMultisignatureVerificationGas(
meter sdk.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey,
meter storetypes.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey,
params authtypes.Params, accSeq uint64,
) error {
size := sig.BitArray.Count()
Expand Down
31 changes: 14 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import (
"encoding/json"
"io"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/spf13/cast"

"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
Expand Down Expand Up @@ -214,7 +214,7 @@ func NewIrisApp(
// that in-memory capabilities get regenerated on app restart.
// Note that since this reads from the store, we can only perform it when
// `loadLatest` is set to true.
app.CapabilityKeeper.Seal()
//app.CapabilityKeeper.Seal()
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
}
return app
}
Expand All @@ -223,20 +223,17 @@ func NewIrisApp(
func (app *IrisApp) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *IrisApp) BeginBlocker(
ctx sdk.Context,
req abci.RequestBeginBlock,
) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
func (app *IrisApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
return app.mm.BeginBlock(ctx)
}

// EndBlocker application updates every end block
func (app *IrisApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
func (app *IrisApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
return app.mm.EndBlock(ctx)
}

// InitChainer application update at chain initialization
func (app *IrisApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
func (app *IrisApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
var genesisState iristypes.GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -303,7 +300,7 @@ func (app *IrisApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICo
// Register new tx routes from grpc-gateway.
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register node gRPC service for grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register grpc-gateway routes for all modules.
Expand All @@ -322,7 +319,7 @@ func (app *IrisApp) RegisterServices() {
if !ok {
panic("unable to cast mod into AppModule")
}
rpc.RegisterService(m, app.configurator, app.AppKeepers)
rpc.RegisterService(app.appCodec, m, app.configurator, app.AppKeepers)
}
}

Expand All @@ -338,7 +335,7 @@ func (app *IrisApp) RegisterTxService(clientCtx client.Context) {

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *IrisApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
cmtservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.interfaceRegistry,
Expand All @@ -349,8 +346,8 @@ func (app *IrisApp) RegisterTendermintService(clientCtx client.Context) {
// RegisterNodeService registers the node service.
//
// It takes a client context as a parameter and does not return anything.
func (app *IrisApp) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
func (app *IrisApp) RegisterNodeService(clientCtx client.Context, c config.Config) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), c)
}

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
Expand Down
48 changes: 33 additions & 15 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

storetypes "cosmossdk.io/store/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -25,7 +26,7 @@ func (app *IrisApp) ExportAppStateAndValidators(
modulesToExport []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContextLegacy(true, tmproto.Header{Height: app.LastBlockHeight()})

// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
Expand All @@ -38,7 +39,10 @@ func (app *IrisApp) ExportAppStateAndValidators(
service.PrepForZeroHeightGenesis(ctx, app.ServiceKeeper)
}

genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
genState, err := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down Expand Up @@ -84,13 +88,16 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
app.StakingKeeper.IterateValidators(
ctx,
func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, sdk.ValAddress(val.GetOperator()))
return false
},
)
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
if err != nil {
panic(err)
}
for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
Expand Down Expand Up @@ -119,12 +126,21 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
ctx,
func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, sdk.ValAddress(val.GetOperator()))
if err != nil {
panic(err)
}
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(nil)
}

wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)
if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
panic(err)
}

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, sdk.ValAddress(val.GetOperator())); err != nil {
panic(err)
}
return false
Expand Down Expand Up @@ -182,22 +198,24 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey))
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
if err != nil {
panic(err)
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
if err := app.StakingKeeper.SetValidator(ctx, validator); err != nil {
panic(err)
}
counter++
}

Expand All @@ -206,7 +224,7 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
return
}

_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
_, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
if err != nil {
log.Fatal(err)
}
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -232,6 +250,6 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
// ExportGenesis returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *IrisApp) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage {
func (app *IrisApp) ExportGenesis(ctx sdk.Context) (map[string]json.RawMessage, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle error returned by ExportGenesis

The ExportGenesis method now returns an error. Ensure that all calls to this method handle the error appropriately to prevent unintended behavior.

return app.mm.ExportGenesis(ctx, app.AppCodec())
}
Loading
Loading