diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 435033445a..b7df616b36 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,10 +17,10 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.18.10 - uses: actions/checkout@v3 - 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 \ No newline at end of file + version: v1.53.3 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3075a6d47..bcad15a21a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/setup-go@v2.1.3 with: - go-version: 1.18 + go-version: 1.18.10 - name: Display go version run: go version - name: install tparse @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.18 + go-version: 1.18.10 - uses: technote-space/get-diff-action@v4 id: git_diff with: @@ -52,7 +52,7 @@ jobs: # - uses: actions/checkout@v2 # - uses: actions/setup-go@v2.1.3 # with: - # go-version: 1.18 + # go-version: 1.18.10 # - name: Display go version # run: go version # - uses: technote-space/get-diff-action@v4 @@ -105,7 +105,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.18 + go-version: 1.18.10 - uses: technote-space/get-diff-action@v4 with: PATTERNS: | @@ -183,7 +183,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.3 with: - go-version: 1.18 + go-version: 1.18.10 - uses: technote-space/get-diff-action@v4 with: PATTERNS: | @@ -232,7 +232,7 @@ jobs: # - uses: actions/checkout@v2 # - uses: actions/setup-go@v2.1.3 # with: - # go-version: 1.18 + # go-version: 1.18.10 # - uses: technote-space/get-diff-action@v4 # id: git_diff # with: diff --git a/Makefile b/Makefile index 62cd744cd4..531088c0c3 100644 --- a/Makefile +++ b/Makefile @@ -321,13 +321,17 @@ benchmark: ### Linting ### ############################################################################### +golangCliLintVersion=v1.53.3 + containerMarkdownLintImage=tmknom/markdownlint containerMarkdownLint=cosmos-sdk-markdownlint containerMarkdownLintFix=cosmos-sdk-markdownlint-fix +containerGolangCliLint=golangci/golangci-lint:$(golangCliLintVersion) -golangci_lint_cmd=go run github.com/golangci/golangci-lint/cmd/golangci-lint +#golangci_lint_cmd_shared_cache=$(DOCKER) run --rm -v $(CURDIR):/work -v ./.cache/golangci-lint/$(golangCliLintVersion):/root/.cache -w /work $(containerGolangCliLint) golangci-lint +golangci_lint_cmd=$(DOCKER) run --rm -v $(CURDIR):/work -w /work $(containerGolangCliLint) golangci-lint -lint: lint-go +lint: lint-go-diff @#if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLint}$$"; then docker start -a $(containerMarkdownLint); else docker run --name $(containerMarkdownLint) -i -v "$(CURDIR):/work" $(markdownLintImage); fi docker run -i --rm -v "$(CURDIR):/work" $(containerMarkdownLintImage) . @@ -335,9 +339,26 @@ lint-fix: @#if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLintFix}$$"; then docker start -a $(containerMarkdownLintFix); else docker run --name $(containerMarkdownLintFix) -i -v "$(CURDIR):/work" $(markdownLintImage) . --fix; fi docker run -i --rm -v "$(CURDIR):/work" $(containerMarkdownLintImage) --fix . -lint-go: +lint-go-diff: echo $(GIT_DIFF) - $(golangci_lint_cmd) run --out-format=tab $(GIT_DIFF) + #$(golangci_lint_cmd) run --out-format=tab $(GIT_DIFF) + # + #mkdir -p ./.cache/golangci-lint/$(golangCliLintVersion) + #$(golangci_lint_cmd_shared_cache) run -v --out-format=tab $(GIT_DIFF) + # + $(golangci_lint_cmd) run -v --out-format=tab $(GIT_DIFF) + +lint-go: + #mkdir -p ./.cache/golangci-lint/$(golangCliLintVersion) + #$(golangci_lint_cmd_shared_cache) run -v --out-format=tab + # + $(golangci_lint_cmd) run -v --out-format=tab + +lint-go-fix: + #mkdir -p ./.cache/golangci-lint/$(golangCliLintVersion) + #$(golangci_lint_cmd_shared_cache) run -v --fix --out-format=tab + # + $(golangci_lint_cmd) run -v --fix --out-format=tab .PHONY: lint lint-fix diff --git a/x/mint/abci.go b/x/mint/abci.go index 24754bdfeb..a69aa42966 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -2,12 +2,13 @@ package mint import ( "fmt" + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/mint/cache" "github.com/cosmos/cosmos-sdk/x/mint/keeper" "github.com/cosmos/cosmos-sdk/x/mint/types" - "time" ) // HandleMunicipalInflation iterates through all other native tokens specified in the minter.MunicipalInflation structure, and processes @@ -34,7 +35,6 @@ func HandleMunicipalInflation(ctx sdk.Context, k keeper.Keeper) { coinsToMint := types.CalculateInflationIssuance(cacheItem.PerBlockInflation, totalDenomSupply) err := k.MintCoins(ctx, coinsToMint) - if err != nil { panic(err) } diff --git a/x/mint/cache/municipal_inflation_cahe.go b/x/mint/cache/municipal_inflation_cahe.go index 7952910101..dfc82bd15a 100644 --- a/x/mint/cache/municipal_inflation_cahe.go +++ b/x/mint/cache/municipal_inflation_cahe.go @@ -1,9 +1,10 @@ package cache import ( + "sync" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/mint/types" - "sync" ) type MunicipalInflationCacheItem struct { @@ -18,19 +19,17 @@ type MunicipalInflationCache struct { mu sync.RWMutex } -var ( - // GMunicipalInflationCache Thread safety: - // As the things stand now from design & impl. perspective: - // 1. This global variable is supposed to be initialised(= its value set) - // just *ONCE* here, at this place, - // 2. This global variable is *NOT* used anywhere else in the initialisation - // context of the *global scope* - e.g. as input for initialisation of - // another global variable, etc. ... - // 3. All *exported* methods of `MunicipalInflationCache` type *ARE* thread safe, - // and so can be called from anywhere, *EXCEPT* from the initialisation context - // of the global scope(implication of the point 2 above)! - GMunicipalInflationCache = MunicipalInflationCache{} -) +// GMunicipalInflationCache Thread safety: +// As the things stand now from design & impl. perspective: +// 1. This global variable is supposed to be initialised(= its value set) +// just *ONCE* here, at this place, +// 2. This global variable is *NOT* used anywhere else in the initialisation +// context of the *global scope* - e.g. as input for initialisation of +// another global variable, etc. ... +// 3. All *exported* methods of `MunicipalInflationCache` type *ARE* thread safe, +// and so can be called from anywhere, *EXCEPT* from the initialisation context +// of the global scope(implication of the point 2 above)! +var GMunicipalInflationCache = MunicipalInflationCache{} func (cache *MunicipalInflationCache) Refresh(inflations *[]*types.MunicipalInflationPair, blocksPerYear uint64) { cache.mu.Lock() @@ -78,7 +77,6 @@ func (cache *MunicipalInflationCache) refresh(inflations *[]*types.MunicipalInfl for _, pair := range *inflations { inflationPerBlock, err := types.CalculateInflationPerBlock(pair.Inflation.Value, blocksPerYear) - if err != nil { panic(err) } diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index 66ed07dbb6..91e4d3965d 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/mint/types" diff --git a/x/mint/client/testutil/suite.go b/x/mint/client/testutil/suite.go index fbc31112fa..0859f83ffe 100644 --- a/x/mint/client/testutil/suite.go +++ b/x/mint/client/testutil/suite.go @@ -38,10 +38,10 @@ func (s *IntegrationTestSuite) SetupSuite() { mintData.Minter.Inflation = inflation mintData.Minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{ - {"denom1", minttypes.NewMunicipalInflation("cosmos12kdu2sy0zcmz84qymyj6zcfvwss3a703xgpczm", sdk.NewDecWithPrec(234, 4))}, - {"denom0", minttypes.NewMunicipalInflation("cosmos1d9pzg5542spe4anjgu2zmk7wxhgh04ysn2phpq", sdk.NewDecWithPrec(123, 2))}, - {"denom3", minttypes.NewMunicipalInflation("cosmos1ck73rpk6eqxtla4rv7rspsq7apl3740rgjfte4", sdk.NewDecWithPrec(456, 3))}, - {"denom2", minttypes.NewMunicipalInflation("cosmos1ury8qn5w7m3xkl9pdd9ehazd2c9urx7qht2jly", sdk.NewDecWithPrec(345, 3))}, + {Denom: "denom1", Inflation: minttypes.NewMunicipalInflation("cosmos12kdu2sy0zcmz84qymyj6zcfvwss3a703xgpczm", sdk.NewDecWithPrec(234, 4))}, + {Denom: "denom0", Inflation: minttypes.NewMunicipalInflation("cosmos1d9pzg5542spe4anjgu2zmk7wxhgh04ysn2phpq", sdk.NewDecWithPrec(123, 2))}, + {Denom: "denom3", Inflation: minttypes.NewMunicipalInflation("cosmos1ck73rpk6eqxtla4rv7rspsq7apl3740rgjfte4", sdk.NewDecWithPrec(456, 3))}, + {Denom: "denom2", Inflation: minttypes.NewMunicipalInflation("cosmos1ury8qn5w7m3xkl9pdd9ehazd2c9urx7qht2jly", sdk.NewDecWithPrec(345, 3))}, } mintDataBz, err := s.cfg.Codec.MarshalJSON(&mintData) diff --git a/x/mint/keeper/grpc_query.go b/x/mint/keeper/grpc_query.go index e4a65d8b56..8763214746 100644 --- a/x/mint/keeper/grpc_query.go +++ b/x/mint/keeper/grpc_query.go @@ -3,6 +3,7 @@ package keeper import ( "context" "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/mint/cache" "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -28,22 +29,18 @@ func (k Keeper) Inflation(c context.Context, _ *types.QueryInflationRequest) (*t // MunicipalInflation returns minter.MunicipalInflation of the mint module. func (k Keeper) MunicipalInflation(c context.Context, req *types.QueryMunicipalInflationRequest) (*types.QueryMunicipalInflationResponse, error) { - //ctx := sdk.UnwrapSDKContext(c) - //minter := k.GetMinter(ctx) denom := req.GetDenom() if len(denom) == 0 { - return &types.QueryMunicipalInflationResponse{Inflations: *cache.GMunicipalInflationCache.GetOriginal()}, nil } - //for _, infl := minter.MunicipalInflation infl, exists := cache.GMunicipalInflationCache.GetInflation(denom) if !exists { return nil, fmt.Errorf("there is no municipal inflation defined for requested \"%s\" denomination", denom) } - return &types.QueryMunicipalInflationResponse{Inflations: []*types.MunicipalInflationPair{{denom, infl.AnnualInflation}}}, nil + return &types.QueryMunicipalInflationResponse{Inflations: []*types.MunicipalInflationPair{{Denom: denom, Inflation: infl.AnnualInflation}}}, nil } // AnnualProvisions returns minter.AnnualProvisions of the mint module. diff --git a/x/mint/types/inflations.go b/x/mint/types/inflations.go index 4e7b41317a..d0c27fb6a7 100644 --- a/x/mint/types/inflations.go +++ b/x/mint/types/inflations.go @@ -2,6 +2,7 @@ package types import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" )