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

chore: Bump cosmos-sdk to v50 & IBC to v8 #676

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'go.mod'
- 'go.sum'
- '.golangci.yml'
- '!**.pb.go'
- '!statik.go'
pull_request:
types:
- opened
Expand All @@ -19,6 +21,8 @@ on:
- 'go.sum'
- '.golangci.yml'
- '.github/workflows/golang.yml'
- '!**.pb.go'
- '!statik.go'

permissions:
contents: read
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
run: git fetch --force --tags
- name: Generate release note
run: |
chmod +x ./contrib/scripts/release-note.sh
./contrib/scripts/release-note.sh ${GITHUB_REF#refs/*/}
chmod +x ./scripts/release-note.sh
./scripts/release-note.sh ${GITHUB_REF#refs/*/}
- name: Setup release environment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ out
typechain-types
swagger-proto
tmp-swagger-gen
tests/scripts/.env
tests/scripts/.env
third_party
40 changes: 31 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m

# Include test files or not.
# Default: true
tests: true

# Define the Go version limit.
# Mainly related to generics support since go1.23.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.23
go: '1.23'
sort-results: true
allow-parallel-runners: true

issues:
exclude-files:
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.pulsar\\.go$"

linters:
enable:
Expand All @@ -26,8 +25,21 @@ linters:
- dogsled
- gosec
- errcheck
# - goconst
- gosimple
- govet
- ineffassign
- misspell
# - nakedret
- nolintlint
- staticcheck
- revive
- typecheck
- unused

linters-settings:
staticcheck:
checks: ["all", "-SA1019"]
stylecheck:
checks: ["all", "-ST1003"]
gocyclo:
Expand All @@ -45,3 +57,13 @@ linters-settings:
errcheck:
check-type-assertions: false
check-blank: false
revive:
# https://golangci-lint.run/usage/linters/#revive
enable-all-rules: false
rules:
- name: var-naming
disabled: false
arguments:
- [ "ID", "IDS", "URL", "JSON", "RPC" ] # AllowList
- [ "" ] # DenyList
- - upperCaseConst: true
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ lint-install:
fi

check-no-lint:
@if [ $$(find . -name '*.go' -type f | xargs grep 'nolint\|#nosec' | wc -l) -ne 42 ]; then \
@if [ $$(find . -name '*.go' -type f | xargs grep 'nolint\|#nosec' | wc -l) -ne 11 ]; then \
echo "\033[91m--> increase or decrease nolint, please recheck them\033[0m"; \
echo "\033[91m--> list nolint: \`find . -name '*.go' -type f | xargs grep 'nolint\|#nosec'\`\033[0m"; \
exit 1;\
Expand Down Expand Up @@ -198,39 +198,36 @@ proto-all: proto-format proto-gen proto-swagger-gen

proto-format:
@echo "Formatting Protobuf files"
@$(protoImage) sh ./contrib/protoc/format.sh
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;

proto-lint:
@$(protoImage) buf lint

proto-gen:
@echo "Generating Protobuf files"
@$(protoImage) sh ./contrib/protoc/gen.sh
@$(protoImage) sh ./scripts/protocgen.sh

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@$(protoImage) sh ./contrib/protoc/swagger-gen.sh
@$(protoImage) sh ./scripts/protoc-swagger-gen.sh
$(MAKE) update-swagger-docs

proto-fork:
@echo "Forking Protobuf files"
@docker run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
-e BUF_NAME=${BUF_NAME} -e BUF_TOKEN=${BUF_TOKEN} -e BUF_ORG=${BUF_ORG} \
sh ./contrib/protoc/fork.sh

proto-update-deps:
@echo "Updating Protobuf dependencies"
@docker run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update

.PHONY: proto-format proto-gen proto-swagger-gen proto-fork proto-update-deps
.PHONY: proto-format proto-lint proto-gen proto-swagger-gen proto-update-deps

statik: $(STATIK)
$(STATIK):
@echo "Installing statik..."
@go install github.com/rakyll/statik@latest

update-swagger-docs: statik
@$(GOPATH)/bin/statik -src=docs/swagger-ui -dest=docs -f -m
@if [ "$(shell sed -n '7p' docs/swagger-ui/swagger.yaml)" != "schemes:" ]; then \
perl -pi -e "print \"host: fx-rest.functionx.io\nschemes:\n - https\n\" if $$.==6 " ./docs/swagger-ui/swagger.yaml; \
fi
@$(GOPATH)/bin/statik -src=docs/swagger-ui -dest=docs -f -m

.PHONY: statik update-swagger-docs

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

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -25,7 +26,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
return newEthAnteHandler(ctx, options)(ctx, tx, sim)
return newEthAnteHandler(options)(ctx, tx, sim)
default:
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
Expand All @@ -49,7 +50,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
// 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 @@ -72,7 +73,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
3 changes: 1 addition & 2 deletions ante/eth_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
evmante "github.com/evmos/ethermint/app/ante"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)
Expand All @@ -27,7 +26,7 @@ func (d TxListenerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
if ctx.IsCheckTx() && !simulate && d.pendingTxListener != nil {
for _, msg := range tx.GetMsgs() {
if ethTx, ok := msg.(*evmtypes.MsgEthereumTx); ok {
d.pendingTxListener(common.HexToHash(ethTx.Hash))
d.pendingTxListener(ethTx.Hash())
}
}
}
Expand Down
27 changes: 0 additions & 27 deletions ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,8 @@ package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
)

// AccountKeeper defines the expected account keeper interface
type AccountKeeper interface {
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
GetModuleAddress(moduleName string) sdk.AccAddress
GetAllAccounts(ctx sdk.Context) (accounts []authtypes.AccountI)
IterateAccounts(ctx sdk.Context, cb func(account authtypes.AccountI) bool)
GetSequence(sdk.Context, sdk.AccAddress) (uint64, error)
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
SetAccount(ctx sdk.Context, account authtypes.AccountI)
RemoveAccount(ctx sdk.Context, account authtypes.AccountI)
GetParams(ctx sdk.Context) (params authtypes.Params)
}

// FeegrantKeeper defines the expected feegrant keeper.
type FeegrantKeeper interface {
UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error
}

// FeeMarketKeeper defines the expected keeper interface used on the AnteHandler
type FeeMarketKeeper interface {
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
GetBaseFeeEnabled(ctx sdk.Context) bool
}

type Govkeeper interface {
GetDisabledMsgs(ctx sdk.Context) []string
}
110 changes: 83 additions & 27 deletions ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@ package ante

import (
errorsmod "cosmossdk.io/errors"
txsigning "cosmossdk.io/x/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"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/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"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethante "github.com/evmos/ethermint/app/ante"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper, EVM Keeper and Fee Market Keeper.
type HandlerOptions struct {
AccountKeeper AccountKeeper
AccountKeeper evmtypes.AccountKeeper
BankKeeper authtypes.BankKeeper
FeegrantKeeper FeegrantKeeper
FeegrantKeeper ante.FeegrantKeeper
EvmKeeper ethante.EVMKeeper
FeeMarketKeeper FeeMarketKeeper
FeeMarketKeeper evmtypes.FeeMarketKeeper
IbcKeeper *ibckeeper.Keeper
GovKeeper Govkeeper
SignModeHandler authsigning.SignModeHandler
SignModeHandler *txsigning.HandlerMap
SigGasConsumer ante.SignatureVerificationGasConsumer
TxFeeChecker ante.TxFeeChecker
MaxTxGasWanted uint64
InterceptMsgTypes map[int64][]string
DisabledAuthzMsgs []string
PendingTxListener ethante.PendingTxListener

UnsafeUnorderedTx bool
}

func (options HandlerOptions) Validate() error {
Expand Down Expand Up @@ -56,29 +60,81 @@ func (options HandlerOptions) Validate() error {
return nil
}

func newEthAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandler {
evmParams := options.EvmKeeper.GetParams(ctx)
evmDenom := evmParams.EvmDenom
chainID := options.EvmKeeper.ChainID()
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
baseFee := options.EvmKeeper.GetBaseFee(ctx, ethCfg)
func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
decorators := []sdk.AnteDecorator{
ethante.NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first
ethante.NewEthMempoolFeeDecorator(evmDenom, baseFee), // Check eth effective gas price against minimal-gas-prices
ethante.NewEthMinGasPriceDecorator(options.FeeMarketKeeper, baseFee), // Check eth effective gas price against the global MinGasPrice
ethante.NewEthValidateBasicDecorator(&evmParams, baseFee),
ethante.NewEthSigVerificationDecorator(chainID),
ethante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper, evmDenom),
ethante.NewCanTransferDecorator(options.EvmKeeper, baseFee, &evmParams, ethCfg),
NewEthPubKeyDecorator(options.AccountKeeper),
ethante.NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted, ethCfg, evmDenom, baseFee),
ethante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator.
ethante.NewGasWantedDecorator(options.FeeMarketKeeper, ethCfg),
ethante.NewEthEmitEventDecorator(options.EvmKeeper), // emit eth tx hash and index at the very last ante handler.
newTxListenerDecorator(options.PendingTxListener),
}
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
blockCfg, err := options.EvmKeeper.EVMBlockConfig(ctx, options.EvmKeeper.ChainID())
if err != nil {
return ctx, errorsmod.Wrap(errortypes.ErrLogic, err.Error())
}
evmParams := &blockCfg.Params
evmDenom := evmParams.EvmDenom
feemarketParams := &blockCfg.FeeMarketParams
baseFee := blockCfg.BaseFee
rules := blockCfg.Rules

// all transactions must implement FeeTx
_, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType, "invalid transaction type %T, expected sdk.FeeTx", tx)
}

// We need to setup an empty gas config so that the gas is consistent with Ethereum.
ctx, err = ethante.SetupEthContext(ctx)
if err != nil {
return ctx, err
}

if err = ethante.CheckEthMempoolFee(ctx, tx, simulate, baseFee, evmDenom); err != nil {
return ctx, err
}

if err = ethante.CheckEthMinGasPrice(tx, feemarketParams.MinGasPrice, baseFee); err != nil {
return ctx, err
}

if err = ethante.ValidateEthBasic(ctx, tx, evmParams, baseFee); err != nil {
return ctx, err
}

ethSigner := ethtypes.MakeSigner(blockCfg.ChainConfig, blockCfg.BlockNumber)
err = ethante.VerifyEthSig(tx, ethSigner)
if err != nil {
return ctx, err
}

// AccountGetter cache the account objects during the ante handler execution,
// it's safe because there's no store branching in the ante handlers.
accountGetter := ethante.NewCachedAccountGetter(ctx, options.AccountKeeper)

if err = ethante.VerifyEthAccount(ctx, tx, options.EvmKeeper, evmDenom, accountGetter); err != nil {
return ctx, err
}

if err = ethante.CheckEthCanTransfer(ctx, tx, baseFee, rules, options.EvmKeeper, evmParams); err != nil {
return ctx, err
}

ctx, err = ethante.CheckEthGasConsume(
ctx, tx, rules, options.EvmKeeper,
baseFee, options.MaxTxGasWanted, evmDenom,
)
if err != nil {
return ctx, err
}

if err = ethante.CheckAndSetEthSenderNonce(ctx, tx, options.AccountKeeper, options.UnsafeUnorderedTx, accountGetter); err != nil {
return ctx, err
}

if len(decorators) > 0 {
return sdk.ChainAnteDecorators(decorators...)(ctx, tx, simulate)
}
return ctx, nil
}
decorators = append(decorators, newTxListenerDecorator(options.PendingTxListener))
return sdk.ChainAnteDecorators(decorators...)
}

func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
Expand Down
Loading
Loading