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

feat: cosmos-sdk v0.47.x & ibc v7 #20

Merged
merged 18 commits into from
Nov 20, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ on:
- main
- development

env:
GO_VERSION: "1.21.3"

permissions:
contents: read

# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# This workflow makes x86_64 binaries for mac, windows, and linux.

jobs:
Expand All @@ -29,11 +41,11 @@ jobs:
targetos: [ darwin, linux ]
name: streampayd ${{ matrix.arch }} for ${{ matrix.targetos }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: ${{env.GO_VERSION}}
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
Expand All @@ -44,7 +56,7 @@ jobs:
cd cmd/streampayd
go build .

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: streampayd ${{ matrix.targetos }} ${{ matrix.arch }}
path: cmd/streampayd/streampayd
20 changes: 15 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ on:
tags:
- v*
branches:
- master
- main
pull_request:
paths:
- '**.go'

env:
GO_VERSION: '1.21.3'

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
- uses: actions/checkout@v3.1.0
go-version: ${{env.GO_VERSION}}
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
args: --timeout 5m0s
args: --timeout 10m
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
vue/node_modules
vue/dist
release/
.idea
.idea
build
bin
22 changes: 15 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ linters:
- unused

issues:
gofumpt:
# Module path which contains the source code being formatted.
# Default: ""
module-path: github.com/cosmos/interchain-security
# Choose whether to use the extra rules.
# Default: false
extra-rules: true
exclude-rules:
- text: "Use of weak random number generator"
linters:
Expand All @@ -51,14 +44,26 @@ issues:
text: "SA1019:"
linters:
- staticcheck
- path: cli
linters:
- goconst
- text: "leading space"
linters:
- nolintlint
- path: "legacy"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
gosec:
excludes:
- G404
- G101
- G601
gocritic:
disabled-checks:
- appendAssign
Expand All @@ -69,6 +74,9 @@ linters-settings:
rules:
- name: var-naming
disabled: true
govet:
excludes:
- SA1019
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
Expand Down
82 changes: 68 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@ APP_NAME = streampay
DAEMON_NAME = streampayd
LEDGER_ENABLED ?= true

PACKAGES=$(shell go list ./... | grep -v '/simulation')
VERSION := $(shell echo $(shell git describe --tags --always) | sed 's/^v//')
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
COSMOS_SDK := $(shell grep -i cosmos-sdk go.mod | awk '{print $$2}')

build_tags = netgo,
# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --exact-match 2>/dev/null)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

PACKAGES_SIMTEST=$(shell go list ./... | grep -v '/simulation')
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
BFT_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
DOCKER := $(shell which docker)
BUILDDIR ?= $(CURDIR)/build

GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
REQUIRE_GO_VERSION = 1.20

export GO111MODULE = on

# process build tags
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
Expand All @@ -30,39 +49,74 @@ ifeq ($(LEDGER_ENABLED),true)
endif
endif
endif

ifeq (cleveldb,$(findstring cleveldb,$(STREAMPAY_BUILD_OPTIONS)))
build_tags += gcc cleveldb
else ifeq (rocksdb,$(findstring rocksdb,$(STREAMPAY_BUILD_OPTIONS)))
build_tags += gcc rocksdb
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

whitespace :=
whitespace := $(whitespace) $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))

# process linker flags

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=${APP_NAME} \
-X github.com/cosmos/cosmos-sdk/version.AppName=${DAEMON_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),cosmos-sdk $(COSMOS_SDK)"
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(BFT_VERSION)

ifeq (cleveldb,$(findstring cleveldb,$(STREAMPAY_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
else ifeq (rocksdb,$(findstring rocksdb,$(STREAMPAY_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb
endif
ifeq (,$(findstring nostrip,$(STREAMPAY_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

BUILD_FLAGS := -ldflags '$(ldflags)'
ifeq (,$(findstring nostrip,$(STREAMPAY_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

all: go.sum install
all: install
@echo "--> project root: go mod tidy"
@go mod tidy
@echo "--> project root: linting --fix"
@GOGC=1 golangci-lint run --fix --timeout=8m

install: go.sum
go install $(BUILD_FLAGS) ./cmd/streampayd/
go install -mod=readonly $(BUILD_FLAGS) ./cmd/streampayd
build:
go build $(BUILD_FLAGS) -o ${GOPATH}/bin/${DAEMON_NAME} ./cmd/streampayd/
go build $(BUILD_FLAGS) -o ${BUILDDIR}/${DAEMON_NAME} ./cmd/streampayd

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify


lint:
@echo "--> Running linter"
@golangci-lint run
@go mod verify

reset-and-start-test-chain:
rm -rf ~/.streampay/config/*
streampayd unsafe-reset-all
streampayd tendermint unsafe-reset-all
streampayd init sp-node --chain-id "sp-test-1"
streampayd keys add validator --keyring-backend test
streampayd add-genesis-account `streampayd keys show validator -a --keyring-backend test` 100000000stake
streampayd gentx validator 1000000stake --moniker "validator-1" --chain-id "sp-test-1" --keyring-backend test
streampayd collect-gentxs
streampayd validate-genesis
streampayd genesis add-genesis-account `streampayd keys show validator -a --keyring-backend test` 100000000stake
streampayd genesis gentx validator 1000000stake --moniker "validator-1" --chain-id "sp-test-1" --keyring-backend test
streampayd genesis collect-gentxs
streampayd genesis validate-genesis
streampayd start
24 changes: 12 additions & 12 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package app

import (
errorsmod "cosmossdk.io/errors"
"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"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
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"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -17,21 +19,21 @@ type HandlerOptions struct {
ante.HandlerOptions

GovKeeper govkeeper.Keeper
StakingKeeper stakingkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
TxCounterStoreKey sdk.StoreKey
TxCounterStoreKey storetypes.StoreKey
Codec codec.BinaryCodec
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand All @@ -41,21 +43,19 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // Outermost AnteDecorator, SetUpContext must be called first

ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
// 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.NewAnteDecorator(options.IBCKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
Loading
Loading