Skip to content

Commit

Permalink
Private/cosmos v50 (#153)
Browse files Browse the repository at this point in the history
* cosmossdk.io/log

* cosmossdk.io/store

* cosmossdk.io/x/feegrant

* cosmossdk.io/x/evidence

* cosmossdk.io/x/upgrade

* ibc v8

* github.com/cosmos/ibc-go/modules/capability

* cosmos-sdk/client/grpc/cmtservice

* remove ibcclientclient, upgradeclient

* packet-forward-middleware v8

* bump cosmos-sdk v0.50.7

* formatting

* x/reward

* x/volunteer

* x/staking

* temp fix ante

* app.go

* fix app/keeper

* app/keeper cont.

* app/keeper cont.

* app/keeper cont.

* mintkeeper for reward

* app/keeper/keys.go

* remove past upgrade

* app/export.go

* app/modules.go

* app/params

* app/app.go

* app/helpers/test_helpers.go

* update buf deps

* cmd

* ante

* app.go cont.

* tests/integration/testutil

* temporary comment out for build

* apply cosmos.msg.v1.service proto annotation

* go1.23.0

* refine CreateTestInput

* apply custom getsigner

* x/reward test build

* cmd test build

* ante test build

* fix test ante

* tests build

* tests/e2e build

* tests all build

* fix tests/integration params

* fix tests/staking

* dockerfile

* fix e2e test validator address type

* fix GetVolunteerValidator

* fix test tests/integration/reward

* update go.mod

* update ethermint version

* update cosmos-sdk to v0.50.10-xpla

* update ledger-cosmos-go

* add buildtag cgo for ledger

* upgrade module for v1_7

* remove erc20 module

* update protobuf dependencies

* remove erc20 docs

* clean testcache before test

* formatting
  • Loading branch information
yoosah authored Nov 5, 2024
1 parent 1b19a1f commit 78fdb9d
Show file tree
Hide file tree
Showing 94 changed files with 169,879 additions and 40,741 deletions.
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.21.x]
go-version: [1.23.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.20.x
go-version: 1.23.x

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

### BUILD
FROM golang:1.21-alpine3.17 AS build
FROM golang:1.23-alpine AS build

# Create appuser.
RUN adduser -D -g '' valiuser
# Install required binaries
RUN apk add --update --no-cache zip git make cmake build-base linux-headers musl-dev libc-dev
RUN apk add --update --no-cache zip git make cmake build-base linux-headers musl-dev libc-dev binutils-gold

WORKDIR /
RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
Expand All @@ -23,11 +23,11 @@ WORKDIR /workspace
# Copy source files
COPY . .
# Download dependencies and CosmWasm libwasmvm if found.
RUN set -eux; \
RUN set -eux; \
export ARCH=$(uname -m); \
WASM_VERSION=$(go list -mod=readonly -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \
if [ ! -z "${WASM_VERSION}" ]; then \
wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
wget -O /lib/libwasmvm_muslc.${ARCH}.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
fi; \
go mod download;

Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ifeq ($(LEDGER_ENABLED),true)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
build_tags += ledger cgo
endif
else
UNAME_S = $(shell uname -s)
Expand All @@ -46,7 +46,7 @@ ifeq ($(LEDGER_ENABLED),true)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
build_tags += ledger cgo
endif
endif
endif
Expand Down Expand Up @@ -141,7 +141,8 @@ build-release-arm64: go.sum $(BUILDDIR)/

.PHONY: test
test: go.sum
go test -short ./...
go clean -testcache
go test -short -p 1 ./...

go.sum: go.mod
@go mod verify
Expand All @@ -150,7 +151,7 @@ go.sum: go.mod
###############################################################################
### Protobuf ###
###############################################################################
PROTO_VERSION=0.11.6
PROTO_VERSION=0.13.0
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)

Expand All @@ -170,3 +171,7 @@ proto-swagger-gen:

proto-lint:
$(PROTO_FORMATTER_IMAGE) buf lint --error-format=json

proto-update-deps:
@echo "Updating Protobuf dependencies"
$(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(PROTO_BUILDER_IMAGE) buf mod update
66 changes: 32 additions & 34 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,52 @@ import (
"fmt"
"runtime/debug"

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

corestoretypes "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
tmlog "github.com/cometbft/cometbft/libs/log"
tmlog "cosmossdk.io/log"
//storetypes "cosmossdk.io/store/types"
txsigning "cosmossdk.io/x/tx/signing"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
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/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/xpladev/ethermint/app/ante"
evmtypes "github.com/xpladev/ethermint/x/evm/types"

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

// HandlerOptions extend the SDK's AnteHandler opts by requiring the IBC
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
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
FeegrantKeeper authante.FeegrantKeeper
SignModeHandler *txsigning.HandlerMap
SigGasConsumer authante.SignatureVerificationGasConsumer
FeeMarketKeeper evmante.FeeMarketKeeper
MaxTxGasWanted uint64
TxFeeChecker authante.TxFeeChecker

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

AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
Codec codec.BinaryCodec
IBCKeeper *ibckeeper.Keeper
EvmKeeper evmante.EVMKeeper
VolunteerKeeper volunteerante.VolunteerKeeper
BypassMinFeeMsgTypes []string
FeeMarketKeeper evmante.FeeMarketKeeper
MaxTxGasWanted uint64
TxFeeChecker authante.TxFeeChecker
TXCounterStoreService corestoretypes.KVStoreService
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.
Expand All @@ -62,7 +61,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "bank keeper is required for AnteHandler")
}
if opts.SignModeHandler == nil {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "sign mode handler is required for ante builder")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "sign mode handler is required for AnteHandler")
}
if opts.IBCKeeper == nil {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "IBC keeper is required for AnteHandler")
Expand All @@ -74,7 +73,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "Feegrant keeper is required for AnteHandler")
}
if opts.FeeMarketKeeper == nil {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "Feemarket keeper is required for AnteHandler")
return nil, errorsmod.Wrap(errortypes.ErrLogic, "FeeMarket keeper is required for AnteHandler")
}
if opts.VolunteerKeeper == nil {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler")
Expand Down Expand Up @@ -125,7 +124,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
}

func newCosmosAnteHandler(opts HandlerOptions) sdk.AnteHandler {
var sigGasConsumer = opts.SigGasConsumer
sigGasConsumer := opts.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = SigVerificationGasConsumer
}
Expand All @@ -136,10 +135,9 @@ func newCosmosAnteHandler(opts HandlerOptions) sdk.AnteHandler {
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),
wasmkeeper.NewGasRegisterDecorator(opts.WasmKeeper.GetGasRegister()),
wasmkeeper.NewCountTXDecorator(opts.TXCounterStoreService),
authante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
NewMinGasPriceDecorator(opts.FeeMarketKeeper, opts.EvmKeeper, opts.BypassMinFeeMsgTypes),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
Expand All @@ -150,7 +148,7 @@ func newCosmosAnteHandler(opts HandlerOptions) sdk.AnteHandler {
authante.NewValidateSigCountDecorator(opts.AccountKeeper),
authante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
authante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
authante.NewIncrementSequenceDecorator(opts.AccountKeeper), // innermost AnteDecorator
authante.NewIncrementSequenceDecorator(opts.AccountKeeper),
ibcante.NewRedundantRelayDecorator(opts.IBCKeeper),
evmante.NewGasWantedDecorator(opts.EvmKeeper, opts.FeeMarketKeeper),
}
Expand Down
16 changes: 10 additions & 6 deletions ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
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"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/stretchr/testify/suite"

xplaapp "github.com/xpladev/xpla/app"
Expand All @@ -40,7 +40,7 @@ func (s *IntegrationTestSuite) SetupTest() {

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

ctx := app.BaseApp.NewContext(false, tmproto.Header{
ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{
ChainID: chainId,
Height: 1,
})
Expand All @@ -54,13 +54,16 @@ func (s *IntegrationTestSuite) SetupTest() {
s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
}

func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (authsigning.Tx, error) {
var sigsV2 []signing.SignatureV2
defaultSignMode, err := authsigning.APISignModeToInternal(s.clientCtx.TxConfig.SignModeHandler().DefaultMode())
s.Require().NoError(err)

for i, priv := range privs {
sigV2 := signing.SignatureV2{
PubKey: priv.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
SignMode: defaultSignMode,
Signature: nil,
},
Sequence: accSeqs[i],
Expand All @@ -75,13 +78,14 @@ func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums

sigsV2 = []signing.SignatureV2{}
for i, priv := range privs {
signerData := xauthsigning.SignerData{
signerData := authsigning.SignerData{
ChainID: chainID,
AccountNumber: accNums[i],
Sequence: accSeqs[i],
}
sigV2, err := tx.SignWithPrivKey(
s.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
s.ctx,
defaultSignMode,
signerData,
s.txBuilder,
priv,
Expand Down
9 changes: 6 additions & 3 deletions ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ante
import (
"math/big"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"

tmstrings "github.com/cometbft/cometbft/libs/strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -31,7 +34,7 @@ func NewMinGasPriceDecorator(fk ethermintante.FeeMarketKeeper, ek ethermintante.
func (mpd MinGasPriceDecorator) 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, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

minGasPrice := mpd.feesKeeper.GetParams(ctx).MinGasPrice
Expand All @@ -57,7 +60,7 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
gasLimit := sdk.NewDecFromBigInt(new(big.Int).SetUint64(gas))
gasLimit := sdkmath.LegacyNewDecFromBigInt(new(big.Int).SetUint64(gas))

for _, gp := range minGasPrices {
fee := gp.Amount.Mul(gasLimit).Ceil().RoundInt()
Expand All @@ -67,7 +70,7 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
}

if !feeCoins.IsAnyGTE(requiredFees) {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "provided fee < minimum global fee (%s < %s). Please increase the gas price.", feeCoins, requiredFees)
return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "provided fee < minimum global fee (%s < %s). Please increase the gas price.", feeCoins, requiredFees)
}

return next(ctx, tx, simulate)
Expand Down
13 changes: 8 additions & 5 deletions ante/fee_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package ante_test

import (
sdkmath "cosmossdk.io/math"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

feemarkettypes "github.com/xpladev/ethermint/x/feemarket/types"

"github.com/xpladev/xpla/ante"
)

func (s *IntegrationTestSuite) TestMinGasPriceDecorator() {
s.SetupTest()
s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder()

s.app.FeeMarketKeeper.SetParams(s.ctx, feemarkettypes.NewParams(true, 8, 2, 0, 0, sdk.NewDec(200), sdk.MustNewDecFromStr("1.5")))
s.app.FeeMarketKeeper.SetParams(s.ctx, feemarkettypes.NewParams(true, 8, 2, 0, 0, sdkmath.LegacyNewDec(200), sdkmath.LegacyMustNewDecFromStr("1.5")))

mpd := ante.NewMinGasPriceDecorator(
s.app.FeeMarketKeeper,
Expand All @@ -40,7 +43,7 @@ func (s *IntegrationTestSuite) TestMinGasPriceDecorator() {
s.Require().NoError(err)

// Set high gas price so standard test fee fails
feeAmt := sdk.NewDecCoinFromDec("uatom", sdk.NewDec(200).Quo(sdk.NewDec(100000)))
feeAmt := sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyNewDec(200).Quo(sdkmath.LegacyNewDec(100000)))
minGasPrice := []sdk.DecCoin{feeAmt}
s.ctx = s.ctx.WithMinGasPrices(minGasPrice).WithIsCheckTx(true)

Expand Down
12 changes: 7 additions & 5 deletions ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package ante
import (
"fmt"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand All @@ -34,7 +36,7 @@ const (
//
// - multisig (Cosmos SDK multisigs)
func SigVerificationGasConsumer(
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 @@ -45,7 +47,7 @@ func SigVerificationGasConsumer(

case *ed25519.PubKey:
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
return sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "ED25519 public keys are unsupported")
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "ED25519 public keys are unsupported")

case *secp256k1.PubKey:
meter.ConsumeGas(params.SigVerifyCostSecp256k1, "ante verify: secp256k1")
Expand All @@ -63,13 +65,13 @@ func SigVerificationGasConsumer(
return ConsumeMultisignatureVerificationGas(meter, multisignature, pubkey, params, sig.Sequence)

default:
return sdkerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "unrecognized/unsupported public key type: %T", pubkey)
return errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "unrecognized/unsupported public key type: %T", pubkey)
}
}

// 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
Loading

0 comments on commit 78fdb9d

Please sign in to comment.