Skip to content

Commit

Permalink
feat: canto cosmos-sdk v0.50.1 bump up - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Dec 4, 2023
1 parent da939e2 commit 56013ce
Show file tree
Hide file tree
Showing 191 changed files with 2,661 additions and 2,514 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-list --tags="v*" "HEAD..origin"))
DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1)
VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//')
TMVERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::')
TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
GOPATH ?= $(shell $(GO) env GOPATH)
Expand Down Expand Up @@ -91,7 +91,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=canto \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TMVERSION)
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TMVERSION)

# DB backend selection
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
Expand Down Expand Up @@ -532,7 +532,7 @@ proto-update-deps:
## Importing of tendermint protobuf definitions currently requires the
## use of `sed` in order to build properly with cosmos-sdk's proto file layout
## (which is the standard Buf.build FILE_LAYOUT)
## Issue link: https://github.com/tendermint/tendermint/issues/5021
## Issue link: https://github.com/cometbft/cometbft/issues/5021
@mkdir -p $(TM_ABCI_TYPES)
@curl -sSL $(TM_URL)/abci/types.proto > $(TM_ABCI_TYPES)/types.proto

Expand Down
5 changes: 3 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand Down Expand Up @@ -32,7 +33,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newCosmosAnteHandlerEip712(options)
default:
return ctx, sdkerrors.Wrapf(
return ctx, errorsmod.Wrapf(
sdkerrors.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
Expand All @@ -51,7 +52,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
anteHandler = newCosmosAnteHandler(options)
}
default:
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
return ctx, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
}

return anteHandler(ctx, tx, sim)
Expand Down
11 changes: 6 additions & 5 deletions app/ante/comission.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package ante

import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var minCommission = sdk.NewDecWithPrec(5, 2) // 5%
var minCommission = sdkmath.LegacyNewDecWithPrec(5, 2) // 5%

// TODO: remove once Cosmos SDK is upgraded to v0.46

Expand Down Expand Up @@ -53,7 +54,7 @@ func (vcd ValidatorCommissionDecorator) validateAuthz(ctx sdk.Context, execMsg *
var innerMsg sdk.Msg
err := vcd.cdc.UnpackAny(v, &innerMsg)
if err != nil {
return sdkerrors.Wrap(err, "cannot unmarshal authz exec msgs")
return errorsmod.Wrap(err, "cannot unmarshal authz exec msgs")
}

if err := vcd.validateMsg(ctx, innerMsg); err != nil {
Expand All @@ -69,13 +70,13 @@ func (vcd ValidatorCommissionDecorator) validateMsg(_ sdk.Context, msg sdk.Msg)
switch msg := msg.(type) {
case *stakingtypes.MsgCreateValidator:
if msg.Commission.Rate.LT(minCommission) {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"validator commission %s be lower than minimum of %s", msg.Commission.Rate, minCommission)
}
case *stakingtypes.MsgEditValidator:
if msg.CommissionRate != nil && msg.CommissionRate.LT(minCommission) {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"validator commission %s be lower than minimum of %s", msg.CommissionRate, minCommission)
}
Expand Down
5 changes: 4 additions & 1 deletion app/ante/cosmos/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func (ald AuthzLimiterDecorator) checkDisabledMsgs(msgs []sdk.Msg, isAuthzInnerM
return err
}
case *authz.MsgGrant:
authorization := msg.GetAuthorization()
authorization, err := msg.GetAuthorization()
if err != nil {
return err
}

url := authorization.MsgTypeURL()
if ald.isDisabledMsg(url) {
Expand Down
19 changes: 10 additions & 9 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package ante

import (
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v3/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"
evmtypes "github.com/evmos/ethermint/x/evm/types"
Expand All @@ -28,7 +30,7 @@ type HandlerOptions struct {
EvmKeeper ethante.EVMKeeper
FeegrantKeeper ante.FeegrantKeeper
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
Cdc codec.BinaryCodec
MaxTxGasWanted uint64
Simulation bool
Expand All @@ -37,24 +39,23 @@ type HandlerOptions struct {
// Validate checks if the keepers are defined
func (options HandlerOptions) Validate() error {
if options.AccountKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.FeeMarketKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "fee market keeper is required for AnteHandler")
return errorsmod.Wrap(sdkerrors.ErrLogic, "fee market keeper is required for AnteHandler")
}
if options.EvmKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "evm keeper is required for AnteHandler")
return errorsmod.Wrap(sdkerrors.ErrLogic, "evm keeper is required for AnteHandler")
}
return nil
}

// newCosmosAnteHandler creates the default ante handler for Ethereum transactions
func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first
Expand Down
36 changes: 21 additions & 15 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
protov2 "google.golang.org/protobuf/proto"

sdkmath "cosmossdk.io/math"
"github.com/Canto-Network/Canto/v7/app"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
client "github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -19,11 +26,6 @@ import (
"github.com/evmos/ethermint/encoding"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/version"
)

var s *AnteTestSuite
Expand All @@ -43,7 +45,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
consAddress := sdk.ConsAddress(privCons.PubKey().Address())

suite.app = app.Setup(isCheckTx, feemarkettypes.DefaultGenesisState())
suite.ctx = suite.app.BaseApp.NewContext(isCheckTx, tmproto.Header{
suite.ctx = suite.app.BaseApp.NewContextLegacy(isCheckTx, tmproto.Header{
Height: 1,
ChainID: "canto_9001-1",
Time: time.Now().UTC(),
Expand Down Expand Up @@ -87,20 +89,23 @@ func (suite *AnteTestSuite) Commit() {
// Commit commits a block at a given time.
func (suite *AnteTestSuite) CommitAfter(t time.Duration) {
header := suite.ctx.BlockHeader()
suite.app.EndBlock(abci.RequestEndBlock{Height: header.Height})
_ = suite.app.Commit()
suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: header.Height,
})
suite.app.Commit()

header.Height += 1
header.Time = header.Time.Add(t)
suite.app.BeginBlock(abci.RequestBeginBlock{
Header: header,
suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: header.Height,
Time: header.Time,
})

// update ctx
suite.ctx = suite.app.BaseApp.NewContext(false, header)
suite.ctx = suite.app.BaseApp.NewContextLegacy(false, header)
}

func (s *AnteTestSuite) CreateTestTxBuilder(gasPrice sdk.Int, denom string, msgs ...sdk.Msg) client.TxBuilder {
func (s *AnteTestSuite) CreateTestTxBuilder(gasPrice sdkmath.Int, denom string, msgs ...sdk.Msg) client.TxBuilder {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
gasLimit := uint64(1000000)

Expand Down Expand Up @@ -130,7 +135,7 @@ func (s *AnteTestSuite) CreateEthTestTxBuilder(msgEthereumTx *evmtypes.MsgEthere
txData, err := evmtypes.UnpackTxData(msgEthereumTx.Data)
s.Require().NoError(err)

fees := sdk.Coins{{Denom: s.denom, Amount: sdk.NewIntFromBigInt(txData.Fee())}}
fees := sdk.Coins{{Denom: s.denom, Amount: sdkmath.NewIntFromBigInt(txData.Fee())}}
builder.SetFeeAmount(fees)
builder.SetGasLimit(msgEthereumTx.GetGas())

Expand Down Expand Up @@ -172,5 +177,6 @@ var _ sdk.Tx = &invalidTx{}

type invalidTx struct{}

func (invalidTx) GetMsgs() []sdk.Msg { return []sdk.Msg{nil} }
func (invalidTx) ValidateBasic() error { return nil }
func (invalidTx) GetMsgs() []sdk.Msg { return []sdk.Msg{nil} }
func (invalidTx) ValidateBasic() error { return nil }
func (invalidTx) GetMsgsV2() ([]protov2.Message, error) { return nil, nil }
Loading

0 comments on commit 56013ce

Please sign in to comment.