Skip to content

Commit

Permalink
Merge pull request #440 from neutron-org/feat/sdk-50
Browse files Browse the repository at this point in the history
feat: sdk v0.50
  • Loading branch information
pr0n00gler authored Jun 10, 2024
2 parents cdb3633 + 115633b commit a2baa8c
Show file tree
Hide file tree
Showing 692 changed files with 41,370 additions and 20,502 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: '~1.21'
go-version: '~1.22'
cache: false
- uses: actions/checkout@v3
- name: golangci-lint
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.21
- name: Set up Go 1.22
uses: actions/setup-go@v4
with:
go-version: ~1.21
go-version: ~1.22
id: go

- name: Check out code into the Go module directory
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ release/
data
.mutagen.yml
vendor/
.testchains
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ linters-settings:
# Default: false
extra-rules: true
nolintlint:
allow-unused: false
allow-unused: true
allow-leading-space: true
require-explanation: false
require-specific: false
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

FROM golang:1.21-bullseye
FROM golang:1.22-bullseye
RUN apt-get update && apt-get install -y jq xxd
EXPOSE 26656 26657 1317 9090
COPY --from=app . /opt/neutron
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.21"
ARG GO_VERSION="1.22"
ARG RUNNER_IMAGE="gcr.io/distroless/static"

# --------------------------------------------------------
Expand All @@ -27,12 +27,12 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
go mod download

# Cosmwasm - Download correct libwasmvm version
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a && \
-O /lib/libwasmvm_muslc.$(uname -m).a && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$(uname -m) | cut -d ' ' -f 1)
sha256sum /lib/libwasmvm_muslc.$(uname -m).a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$(uname -m) | cut -d ' ' -f 1)

# Copy the remaining files
COPY . .
Expand All @@ -42,7 +42,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go build \
-mod=readonly \
-tags "netgo,ledger,muslc" \
-tags ${BUILD_TAGS} \
-ldflags "-X github.com/cosmos/cosmos-sdk/version.Name="neutron" \
-X github.com/cosmos/cosmos-sdk/version.AppName="neutrond" \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
Expand Down
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
BINDIR ?= $(GOPATH)/bin
SIMAPP = ./app
GO_VERSION=1.21
GO_VERSION=1.22
GOLANGCI_LINT_VERSION=v1.55.2
BUILDDIR ?= $(CURDIR)/build

Expand Down Expand Up @@ -111,7 +111,7 @@ build-static-linux-amd64: go.sum $(BUILDDIR)/
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILD_TAGS=$(build_tags_comma_sep) \
--build-arg BUILD_TAGS=$(build_tags_comma_sep),muslc \
--platform linux/amd64 \
-t neutron-amd64 \
--load \
Expand All @@ -121,6 +121,23 @@ build-static-linux-amd64: go.sum $(BUILDDIR)/
$(DOCKER) cp neutronbinary:/bin/neutrond $(BUILDDIR)/neutrond-linux-amd64
$(DOCKER) rm -f neutronbinary

build-slinky-e2e-docker-image: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name neutronbuilder || true
$(DOCKER) buildx use neutronbuilder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILD_TAGS=$(build_tags_comma_sep),skip_ccv_msg_filter,muslc \
--build-arg RUNNER_IMAGE="alpine:3.18" \
--platform linux/amd64 \
-t neutron-node \
--load \
-f Dockerfile.builder .

slinky-e2e-test:
cd ./tests/slinky && go mod tidy && go test -v -race -timeout 20m -count=1 ./...

install-test-binary: check_version go.sum
go install -mod=readonly $(BUILD_FLAGS_TEST_BINARY) ./cmd/neutrond

Expand Down Expand Up @@ -151,6 +168,8 @@ distclean: clean


test: test-unit
@rm -rf ./.testchains

test-all: check test-race test-cover

test-unit:
Expand Down
105 changes: 58 additions & 47 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,57 @@
package app

import (
corestoretypes "cosmossdk.io/core/store"
"cosmossdk.io/errors"
"cosmossdk.io/log"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cometbft/cometbft/libs/log"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
gaiaerrors "github.com/cosmos/gaia/v11/types/errors"
globalfeeante "github.com/cosmos/gaia/v11/x/globalfee/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
consumerante "github.com/cosmos/interchain-security/v4/app/consumer/ante"
ibcconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
auctionante "github.com/skip-mev/block-sdk/x/auction/ante"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
consumerante "github.com/cosmos/interchain-security/v5/app/consumer/ante"
ibcconsumerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/consumer/keeper"
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"

globalfeeante "github.com/neutron-org/neutron/v4/x/globalfee/ante"
globalfeekeeper "github.com/neutron-org/neutron/v4/x/globalfee/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCKeeper *ibckeeper.Keeper
ConsumerKeeper ibcconsumerkeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey

// dependencies for the x/auction ante-handler
AuctionKeeper auctionkeeper.Keeper
TxEncoder sdk.TxEncoder
MEVLane auctionante.MEVLane

// globalFee
GlobalFeeSubspace paramtypes.Subspace
AccountKeeper feemarketante.AccountKeeper
IBCKeeper *ibckeeper.Keeper
ConsumerKeeper ibcconsumerkeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreService corestoretypes.KVStoreService
FeeMarketKeeper feemarketante.FeeMarketKeeper
}

func NewAnteHandler(options HandlerOptions, logger log.Logger) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.TXCounterStoreKey == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "tx counter key is required for ante builder")
return nil, errors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.GlobalFeeSubspace.Name() == "" {
return nil, errors.Wrap(gaiaerrors.ErrNotFound, "globalfee param store is required for AnteHandler")
if options.TXCounterStoreService == nil {
return nil, errors.Wrap(sdkerrors.ErrLogic, "tx counter store service is required for ante builder")
}
if options.MEVLane == nil {
return nil, errors.Wrap(gaiaerrors.ErrLogic, "mev lane is required for AnteHandler")

if options.FeeMarketKeeper == nil {
return nil, errors.Wrap(sdkerrors.ErrLogic, "feemarket keeper is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand All @@ -69,32 +62,24 @@ func NewAnteHandler(options HandlerOptions, logger log.Logger) (sdk.AnteHandler,
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreService),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
// We are providing nil as a StakingKeeper arg because we do not have staking module
// In this case you should be sure that you
// implemented upgrade to set default `ParamStoreKeyMinGasPrices` global fee param with at least one record
// otherwise you will get panic
globalfeeante.NewFeeDecorator(options.GlobalFeeSubspace, nil),

ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
feemarketante.NewFeeMarketCheckDecorator(
options.FeeMarketKeeper,
NewFeeDecoratorWithSwitch(options),
),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
auctionante.NewAuctionDecorator(
options.AuctionKeeper,
options.TxEncoder,
options.MEVLane,
),
}

// Don't delete it even if IDE tells you so.
Expand All @@ -107,3 +92,29 @@ func NewAnteHandler(options HandlerOptions, logger log.Logger) (sdk.AnteHandler,

return sdk.ChainAnteDecorators(anteDecorators...), nil
}

// FeeDecoratorWithSwitch is a fee ante decorator which switches between globalfee ante handler
// and feemarket's one, depending on the `params.Enabled` field feemarket's module.
// If feemarket is enabled, we don't need to perform checks for min gas prices, since they are handled by feemarket
// so we switch the execution directly to feemarket ante handler
// If feemarket is disabled, we call globalfee + native cosmos fee ante handler where min gas prices will be checked
// via globalfee and then they will be deducted via native cosmos fee ante handler.
type FeeDecoratorWithSwitch struct {
globalfeeDecorator globalfeeante.FeeDecorator
cosmosFeeDecorator ante.DeductFeeDecorator
}

func NewFeeDecoratorWithSwitch(options HandlerOptions) FeeDecoratorWithSwitch {
return FeeDecoratorWithSwitch{
globalfeeDecorator: globalfeeante.NewFeeDecorator(options.GlobalFeeKeeper),
cosmosFeeDecorator: ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
}
}

func (d FeeDecoratorWithSwitch) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// If feemarket is disabled, we call globalfee + native cosmos fee ante handler where min gas prices will be checked
// via globalfee and then they will be deducted via native cosmos fee ante handler.
return d.globalfeeDecorator.AnteHandle(ctx, tx, simulate, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
return d.cosmosFeeDecorator.AnteHandle(ctx, tx, simulate, next)
})
}
Loading

0 comments on commit a2baa8c

Please sign in to comment.