Skip to content

Commit

Permalink
Merge pull request #2975 from irisnet/feature/2960
Browse files Browse the repository at this point in the history
Upgrade cosmos-sdk in irishub to v0.50.10
  • Loading branch information
mitch1024 authored Dec 12, 2024
2 parents 72692e6 + e785d18 commit 5ee2f2c
Show file tree
Hide file tree
Showing 74 changed files with 1,203 additions and 824 deletions.
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"
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")
}
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")
}
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
58 changes: 40 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ 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/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"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 All @@ -28,6 +30,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -223,25 +226,24 @@ 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)
return nil, err
}
if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()); err != nil {
return nil, err
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down Expand Up @@ -303,7 +305,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 +324,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 +340,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 +351,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 All @@ -363,6 +365,26 @@ func (app *IrisApp) Init() {
iristypes.InjectCodec(app.legacyAmino, app.interfaceRegistry)
}

// AutoCliOpts returns the autocli options for the app.
func (app *IrisApp) AutoCliOpts() autocli.AppOptions {
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range app.mm.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
moduleName := moduleWithName.Name()
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
modules[moduleName] = appModule
}
}
}

return autocli.AppOptions{
Modules: modules,
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}

// NoOpMempoolOption returns a function that sets up a no-op mempool for the given BaseApp.
//
// The function takes a pointer to a BaseApp as a parameter and returns nothing.
Expand Down
52 changes: 36 additions & 16 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,18 @@ 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())
if _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, sdk.ValAddress(val.GetOperator())); err != nil {
panic(err)
}
return false
},
)

// 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 +128,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(err)
}

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 +200,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,9 +226,9 @@ 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)
panic(err)
}

/* Handle slashing state. */
Expand All @@ -232,6 +252,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) {
return app.mm.ExportGenesis(ctx, app.AppCodec())
}
Loading

0 comments on commit 5ee2f2c

Please sign in to comment.