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

applying cosmos sdk v0.47.x with related upstream codes #125

Merged
merged 31 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea5e443
feat: apply cosmos sdk v0.47.x
yoosah Mar 15, 2024
746fe42
fix: remove evmos dependency
yoosah Mar 15, 2024
a2e8c0f
fix: fix test function
yoosah Mar 15, 2024
b029f20
feat: refactor packet forward middleware and more
yoosah Mar 11, 2024
e86e7af
chore: align formatting
yoosah Mar 18, 2024
86fdadf
feat: bump cosmos sdk version
yoosah Mar 18, 2024
e4ab96a
feat: apply cosmwasm v0.45.0
yoosah Mar 19, 2024
069b9e6
chore: slightly refactor app.go and ante.go
yoosah Mar 20, 2024
98bda09
chore: refactor export.go
yoosah Mar 22, 2024
5bb2433
chore: update go version for workflow
yoosah Mar 25, 2024
9af0705
feat: bump wasmvm version to v1.5.1
yoosah Mar 25, 2024
a5c5a09
fix: add user id for workflow
yoosah Mar 25, 2024
426077c
chore: go-ethereum v1.10.26-xpla
JoowonYun Mar 19, 2024
cfebbe5
chore: cosmos-sdk v0.47.10-xpla
JoowonYun Mar 22, 2024
be1c7ca
refactor: app-cosmos ledger(xpla)
JoowonYun Mar 22, 2024
7717944
test: use test input StakingHandler
yoosah Mar 27, 2024
3d6b735
fix: revert v1_4 upgrade
yoosah Mar 27, 2024
8a634eb
feat: refactor upgrade handler
yoosah Mar 28, 2024
9a81de1
feat: apply v1_5 upgrade handler
yoosah Apr 1, 2024
01730b7
fix: update pfm version
yoosah Apr 1, 2024
630b1ac
fix: follow up staking module
JoowonYun Apr 2, 2024
994d91c
fix: remove redundant code
yoosah Apr 3, 2024
46d14a9
fix: chain id EIP155 number
yoosah Apr 3, 2024
23ec238
chore: add error check for RegisterGRPCGatewayRoutes
yoosah Apr 3, 2024
0182553
fix: remove deprecated param
yoosah Apr 3, 2024
d5c14e4
fix: slightly refactor integration test
yoosah Apr 3, 2024
9220cbf
feat: apply ethermint v0.23.0-xpla-rc2
yoosah Apr 3, 2024
546ccbc
feat: apply ethermint v0.23.0-xpla-rc3
yoosah Apr 4, 2024
9910b1b
feat: apply cosmos-sdk v0.47.10-xpla-rc0
JoowonYun Apr 5, 2024
18fab6c
chore: deprecated params module (#128)
JoowonYun Apr 11, 2024
248c222
feat: update go.mod
yoosah Apr 11, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
go-version: [1.19.x]
go-version: [1.20.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x

- name: End-to-end test
run: cd tests/e2e && go test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# docker run --rm -it --env-file=path/to/.env --name xpla-localnet xpladev/xpla

### BUILD
FROM golang:1.19-alpine AS build
FROM golang:1.20-alpine3.17 AS build

# Create appuser.
RUN adduser -D -g '' valiuser
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif
NAME := xpla
APPNAME := xplad
LEDGER_ENABLED ?= true
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7"
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') # grab everything after the space in "github.com/cometbft/cometbft v0.34.7"
BUILDDIR ?= $(CURDIR)/build
GO_VERSION ?= "1.19"

Expand Down Expand Up @@ -71,7 +71,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(NAME) \
-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=$(TM_VERSION)
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TM_VERSION)

ifeq (cleveldb,$(findstring cleveldb,$(CUSTOM_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
Expand Down Expand Up @@ -151,23 +151,23 @@ go.sum: go.mod
###############################################################################
### Protobuf ###
###############################################################################
PROTO_BUILDER_IMAGE=tendermintdev/sdk-proto-gen:v0.7
PROTO_FORMATTER_IMAGE=tendermintdev/docker-build-proto@sha256:aabcfe2fc19c31c0f198d4cd26393f5e5ca9502d7ea3feafbfe972448fee7cae
PROTO_VERSION=0.11.6
PROTO_BUILDER_IMAGE=ghcr.io/cosmos/proto-builder:$(PROTO_VERSION)
PROTO_FORMATTER_IMAGE=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace --user 0 $(PROTO_BUILDER_IMAGE)

proto-all: proto-format proto-lint proto-gen

proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILDER_IMAGE) sh ./scripts/protocgen.sh
$(PROTO_FORMATTER_IMAGE) sh ./scripts/protocgen.sh

proto-format:
@echo "Formatting Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace $(PROTO_FORMATTER_IMAGE) \
$(PROTO_FORMATTER_IMAGE) \
find ./ -name *.proto -exec clang-format -i {} \;

proto-swagger-gen:
@./scripts/protoc-swagger-openapi-gen.sh

proto-lint:
@$(DOCKER_BUF) lint --error-format=json
$(PROTO_FORMATTER_IMAGE) buf lint --error-format=json
116 changes: 65 additions & 51 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,80 @@ import (
"fmt"
"runtime/debug"

errorsmod "cosmossdk.io/errors"
tmlog "github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"

evmante "github.com/evmos/ethermint/app/ante"
evmtypes "github.com/evmos/ethermint/x/evm/types"
tmlog "github.com/tendermint/tendermint/libs/log"
evmante "github.com/xpladev/ethermint/app/ante"
evmtypes "github.com/xpladev/ethermint/x/evm/types"

volunteerkeeper "github.com/xpladev/xpla/x/volunteer/keeper"
volunteerante "github.com/xpladev/xpla/x/volunteer/ante"
)

// HandlerOptions extend the SDK's AnteHandler opts by requiring the IBC
// channel keeper.
type HandlerOptions struct {
AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
EvmKeeper evmante.EVMKeeper
FeegrantKeeper authante.FeegrantKeeper
VolunteerKeeper volunteerkeeper.Keeper
SignModeHandler authsigning.SignModeHandler
SigGasConsumer authante.SignatureVerificationGasConsumer
FeeMarketKeeper evmtypes.FeeMarketKeeper
MaxTxGasWanted uint64
Cdc codec.BinaryCodec
AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
EvmKeeper evmante.EVMKeeper
FeegrantKeeper authante.FeegrantKeeper
VolunteerKeeper volunteerante.VolunteerKeeper
ExtensionOptionChecker authante.ExtensionOptionChecker
SignModeHandler authsigning.SignModeHandler
SigGasConsumer authante.SignatureVerificationGasConsumer
FeeMarketKeeper evmante.FeeMarketKeeper
MaxTxGasWanted uint64
TxFeeChecker authante.TxFeeChecker

BypassMinFeeMsgTypes []string
TxCounterStoreKey sdk.StoreKey
TxCounterStoreKey storetypes.StoreKey
WasmKeeper *wasmkeeper.Keeper
WasmConfig wasmTypes.WasmConfig
}

var disabledAuthzMsgs = []string{
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
}

// NewAnteHandler returns an 'AnteHandler' that will run actions before a tx is sent to a module's handler.
func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "account keeper is required for AnteHandler")
}
if opts.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "bank keeper is required for AnteHandler")
}
if opts.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "sign mode handler is required for ante builder")
}
if opts.IBCKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "IBC keeper is required for AnteHandler")
}
if opts.EvmKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "EVM keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "EVM keeper is required for AnteHandler")
}
if opts.FeegrantKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "Feegrant keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "Feegrant keeper is required for AnteHandler")
}
if opts.FeeMarketKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "Feemarket keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "Feemarket keeper is required for AnteHandler")
}

sigGasConsumer := opts.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = authante.DefaultSigVerificationGasConsumer
if opts.VolunteerKeeper == nil {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler")
}

return func(
Expand All @@ -87,10 +97,13 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
anteHandler = newEthAnteHandler(opts)
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newCosmosAnteHandlerEip712(opts)
anteHandler = newLegacyCosmosAnteHandlerEip712(opts)
case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx":
// cosmos-sdk tx with dynamic fee extension
anteHandler = newCosmosAnteHandler(opts)
default:
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrUnknownExtensionOptions,
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
}
Expand All @@ -104,7 +117,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
case sdk.Tx:
anteHandler = newCosmosAnteHandler(opts)
default:
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx)
}

return anteHandler(ctx, tx, sim)
Expand All @@ -119,27 +132,26 @@ func newCosmosAnteHandler(opts HandlerOptions) sdk.AnteHandler {

anteDecorators := []sdk.AnteDecorator{
evmante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
),
NewRejectDelegateVolunteerValidatorDecorator(opts.VolunteerKeeper),
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
evmante.NewAuthzLimiterDecorator(disabledAuthzMsgs),
volunteerante.NewRejectDelegateVolunteerValidatorDecorator(opts.VolunteerKeeper),
authante.NewSetUpContextDecorator(), // second decorator. SetUpContext must be called before other decorators
authante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(opts.TxCounterStoreKey),
authante.NewRejectExtensionOptionsDecorator(),
wasmkeeper.NewGasRegisterDecorator(opts.WasmKeeper.GetGasRegister()),
NewMinGasPriceDecorator(opts.FeeMarketKeeper, opts.EvmKeeper, opts.BypassMinFeeMsgTypes),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
authante.NewValidateMemoDecorator(opts.AccountKeeper),
authante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
authante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper),
authante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
authante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
authante.NewValidateSigCountDecorator(opts.AccountKeeper),
authante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
authante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
authante.NewIncrementSequenceDecorator(opts.AccountKeeper), // innermost AnteDecorator
ibcante.NewAnteDecorator(opts.IBCKeeper),
ibcante.NewRedundantRelayDecorator(opts.IBCKeeper),
evmante.NewGasWantedDecorator(opts.EvmKeeper, opts.FeeMarketKeeper),
}
return sdk.ChainAnteDecorators(anteDecorators...)
Expand All @@ -153,42 +165,44 @@ func newEthAnteHandler(opts HandlerOptions) sdk.AnteHandler {
evmante.NewEthValidateBasicDecorator(opts.EvmKeeper),
evmante.NewEthSigVerificationDecorator(opts.EvmKeeper),
evmante.NewEthAccountVerificationDecorator(opts.AccountKeeper, opts.EvmKeeper),
evmante.NewCanTransferDecorator(opts.EvmKeeper),
evmante.NewEthGasConsumeDecorator(opts.EvmKeeper, opts.MaxTxGasWanted),
evmante.NewCanTransferDecorator(opts.EvmKeeper),
evmante.NewEthIncrementSenderSequenceDecorator(opts.AccountKeeper), // innermost AnteDecorator.
evmante.NewGasWantedDecorator(opts.EvmKeeper, opts.FeeMarketKeeper),
evmante.NewEthEmitEventDecorator(opts.EvmKeeper), // emit eth tx hash and index at the very last ante handler.
)
}

func newCosmosAnteHandlerEip712(opts HandlerOptions) sdk.AnteHandler {
// newCosmosAnteHandlerEip712 creates the ante handler for transactions signed with EIP712
func newLegacyCosmosAnteHandlerEip712(opts HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
evmante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
evmante.NewAuthzLimiterDecorator(disabledAuthzMsgs),
volunteerante.NewRejectDelegateVolunteerValidatorDecorator(opts.VolunteerKeeper),
authante.NewSetUpContextDecorator(),
// NOTE: extensions option decorator removed
// ante.NewRejectExtensionOptionsDecorator(),
authante.NewMempoolFeeDecorator(),
NewMinGasPriceDecorator(opts.FeeMarketKeeper, opts.EvmKeeper, opts.BypassMinFeeMsgTypes),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
NewMinGasPriceDecorator(opts.FeeMarketKeeper, opts.EvmKeeper, opts.BypassMinFeeMsgTypes), // Check eth effective gas price against the global MinGasPrice
authante.NewValidateMemoDecorator(opts.AccountKeeper),
authante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
authante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper),
authante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
// SetPubKeyDecorator must be called before all signature verification decorators
authante.NewSetPubKeyDecorator(opts.AccountKeeper),
authante.NewValidateSigCountDecorator(opts.AccountKeeper),
authante.NewSigGasConsumeDecorator(opts.AccountKeeper, opts.SigGasConsumer),
// Note: signature verification uses EIP instead of the cosmos signature validator
evmante.NewEip712SigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
//nolint: staticcheck
evmante.NewLegacyEip712SigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
authante.NewIncrementSequenceDecorator(opts.AccountKeeper),
ibcante.NewAnteDecorator(opts.IBCKeeper),
ibcante.NewRedundantRelayDecorator(opts.IBCKeeper),
evmante.NewGasWantedDecorator(opts.EvmKeeper, opts.FeeMarketKeeper),
)
}

func Recover(logger tmlog.Logger, err *error) {
if r := recover(); r != nil {
*err = sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r)
*err = errorsmod.Wrapf(errortypes.ErrPanic, "%v", r)

if e, ok := r.(error); ok {
logger.Error(
Expand Down
12 changes: 7 additions & 5 deletions ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"math/rand"
"testing"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

xplaapp "github.com/xpladev/xpla/app"
xplahelpers "github.com/xpladev/xpla/app/helpers"
Expand All @@ -35,15 +35,17 @@ func TestIntegrationTestSuite(t *testing.T) {
}

func (s *IntegrationTestSuite) SetupTest() {
chainId := fmt.Sprintf("test_%d-%d", rand.Intn(1000)+1, rand.Intn(10)+1)
// epoch number should not be 0
chainId := fmt.Sprintf("test_9001-%d", rand.Intn(9)+1)

app := xplahelpers.Setup(s.T(), chainId)

app := xplahelpers.Setup(s.T(), chainId, false, 1)
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: chainId,
Height: 1,
})

encodingConfig := simapp.MakeTestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)

Expand Down
Loading
Loading