Skip to content

Commit

Permalink
fix: [Cosmetic] Go linting (#164)
Browse files Browse the repository at this point in the history
* fix: [Cosmetic] Go linting
* CI test run - setting golang v1.18.10
  • Loading branch information
pbukva authored Aug 8, 2023
1 parent eb0a568 commit 5b3dc7d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
version: v1.53.3
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
go-version: 1.18
go-version: 1.18.10
- name: Display go version
run: go version
- name: install tparse
Expand All @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.18
go-version: 1.18.10
- uses: technote-space/get-diff-action@v4
id: git_diff
with:
Expand All @@ -52,7 +52,7 @@ jobs:
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.18
# go-version: 1.18.10
# - name: Display go version
# run: go version
# - uses: technote-space/get-diff-action@v4
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.18
go-version: 1.18.10
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.18
go-version: 1.18.10
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand Down Expand Up @@ -232,7 +232,7 @@ jobs:
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.18
# go-version: 1.18.10
# - uses: technote-space/get-diff-action@v4
# id: git_diff
# with:
Expand Down
29 changes: 25 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,44 @@ 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) .

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

Expand Down
4 changes: 2 additions & 2 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
28 changes: 13 additions & 15 deletions x/mint/cache/municipal_inflation_cahe.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions x/mint/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions x/mint/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions x/mint/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions x/mint/types/inflations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down

0 comments on commit 5b3dc7d

Please sign in to comment.