Skip to content

Commit

Permalink
Bump go to 1.18 (from 1.17) (#998)
Browse files Browse the repository at this point in the history
* Add changelog line.

* [996]: Bump go in go.mod to 1.18 (from 1.17).

* [996]: Bump the go version in the docker files to 1.18-bullseye (from 1.17-bullseye).

* [996]: Bump go version in the github actions to 1.18 (from 1.17).

* [996]: Define the go version to use in the rosetta github action.

* [996]: Update documentation to reflect minimum go version of 1.18.

* [999]: Bump golangci-lint to version 1.48.0 and fix all new problems.

* [999]: Add the predeclared linter and fix its complaints.

* [999]: Add errorlint to the list of linters and fix all complaints.

* [999]: Alphabetize the linters list.
  • Loading branch information
SpicyLemon authored Aug 8, 2022
1 parent 98349e7 commit 25bb51b
Show file tree
Hide file tree
Showing 56 changed files with 195 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.18
- name: Go mod vendor
run: |
go mod vendor
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
go.sum
- uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.18
- uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.44
version: v1.48
args: --timeout 10m --out-${NO_FUTURE}format colored-line-number
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
2 changes: 1 addition & 1 deletion .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.18
- uses: bufbuild/[email protected]
- uses: bufbuild/buf-lint-action@v1
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
version: ${{ steps.vars.outputs.version }}
is_release: ${{ steps.vars.outputs.is_release }}
prerelease: ${{ steps.vars.outputs.prerelease }}
go_version: "1.17"
go_version: 1.18

build_osx:
runs-on: macos-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/rosetta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
go.mod
go.sum
.github/workflows/rosetta.yml
- uses: actions/setup-go@v3
if: ${{ env.GIT_DIFF }}
with:
go-version: 1.18
- name: Go mod vendor
if: ${{ env.GIT_DIFF }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
echo "::set-output name=db-cache-key-hash::${{ hashFiles('scripts/cleveldb_build_and_install.sh') }}"
echo "::set-output name=go-cache-key-hash::${{ hashFiles('go.sum') }}"
outputs:
go-version: 1.17
go-version: 1.18
should-run: ${{ env.GIT_DIFF }}
file-prefix: ${{ steps.def-vars.outputs.file-prefix }}
db-cache-key-suffix: sims-db3-${{ steps.def-vars.outputs.db-cache-key-hash }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
- name: Define Variables
id: def-vars
run: |
echo "::set-output name=go-version::1.17"
echo "::set-output name=cache-key::${{ runner.os }}-unit-tests-${{ hashFiles('scripts/cleveldb_build_and_install.sh', '.github/workflows/test.yml') }}"
echo "::set-output name=file-prefix::${GITHUB_SHA:0:7}-${GITHUB_RUN_ATTEMPT}"
- name: Create a file with all the pkgs
Expand Down Expand Up @@ -88,7 +87,7 @@ jobs:
run: CLEVELDB_DO_CLEANUP=false make cleveldb
outputs:
should-run: ${{ env.GIT_DIFF }}
go-version: ${{ steps.def-vars.outputs.go-version }}
go-version: 1.18
cache-key: ${{ steps.def-vars.outputs.cache-key }}
file-prefix: ${{ steps.def-vars.outputs.file-prefix }}
# Note: this needs to match the path: entries in the actions/cache step above.
Expand Down
14 changes: 6 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ linters:
- depguard
- dogsled
- errcheck
- errorlint
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign

- misspell
- nakedret
- nolintlint
- prealloc
- exportloopref
- predeclared
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
# - wsl
- unused
- varcheck
- whitespace
- nolintlint

issues:
exclude-rules:
Expand Down Expand Up @@ -88,6 +87,5 @@ linters-settings:
- cancelled
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Bump IBC to 2.3.0 and update third-party protos [PR 868](https://github.com/provenance-io/provenance/pull/868)
* Update docker images from `buster` to b`bullseye` [#963](https://github.com/provenance-io/provenance/issues/963)
* Add documentation for `gRPCurl` to `docs/grpcurl.md` [#953](https://github.com/provenance-io/provenance/issues/953)
* Updated to go 1.18 [#996](https://github.com/provenance-io/provenance/issues/996)

### Features

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ is a useful starting point.

Developers can use a local checkout and the make targets `make run` and `make localnet-start` to run a local development network.

Note: Requires [Go 1.17+](https://golang.org/dl/)
Note: Requires [Go 1.18+](https://golang.org/dl/)

See Also: [Building](docs/Building.md)

Expand Down
3 changes: 2 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func (app *App) ExportAppStateAndValidators(

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favor of export at a block height
//
// in favor of export at a block height
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

Expand Down
4 changes: 2 additions & 2 deletions client/rosetta/rosetta-ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-bullseye as build
FROM golang:1.18-bullseye as build
ARG VERSION

WORKDIR /go/src/github.com/provenance-io/provenance
Expand Down Expand Up @@ -51,4 +51,4 @@ RUN chmod +x faucet.py
RUN chmod -R 0777 ./

ENV PATH=$PATH:/bin
ENV PIO_HOME="/provenance/testrosetta"
ENV PIO_HOME="/provenance/testrosetta"
8 changes: 5 additions & 3 deletions cmd/dbmigrate/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"os"

"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -11,9 +12,10 @@ import (
func main() {
rootCmd := cmd.NewDBMigrateCmd()
if err := cmd.Execute(rootCmd); err != nil {
switch e := err.(type) {
case server.ErrorCode:
os.Exit(e.Code)
var srvErr *server.ErrorCode
switch {
case errors.As(err, &srvErr):
os.Exit(srvErr.Code)
default:
os.Exit(1)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/dbmigrate/utils/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,9 @@ func splitDBPath(elem ...string) (string, string) {
// Returned strings are relative to dataDirPath.
//
// Example return values:
// return param 1: []string{"application.db", "blockstore.db", "evidence.db", "snapshots/metadata.db", "state.db", "tx_index.db"}
// return param 2: []string{"cs.wal", "priv_validator_state.json", "wasm"}
//
// return param 1: []string{"application.db", "blockstore.db", "evidence.db", "snapshots/metadata.db", "state.db", "tx_index.db"}
// return param 2: []string{"cs.wal", "priv_validator_state.json", "wasm"}
func GetDataDirContents(dataDirPath string) ([]string, []string, error) {
contents, err := os.ReadDir(dataDirPath)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions cmd/provenanced/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ Default values are filled in appropriately.
func runConfigGetCmd(cmd *cobra.Command, args []string) error {
_, appFields, acerr := provconfig.ExtractAppConfigAndMap(cmd)
if acerr != nil {
return fmt.Errorf("could not get app config fields: %v", acerr)
return fmt.Errorf("could not get app config fields: %w", acerr)
}
_, tmFields, tmcerr := provconfig.ExtractTmConfigAndMap(cmd)
if tmcerr != nil {
return fmt.Errorf("could not get tendermint config fields: %v", tmcerr)
return fmt.Errorf("could not get tendermint config fields: %w", tmcerr)
}
_, clientFields, ccerr := provconfig.ExtractClientConfigAndMap(cmd)
if ccerr != nil {
return fmt.Errorf("could not get client config fields: %v", ccerr)
return fmt.Errorf("could not get client config fields: %w", ccerr)
}

if len(args) == 0 {
Expand Down Expand Up @@ -333,15 +333,15 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) {

appConfig, appFields, acerr := provconfig.ExtractAppConfigAndMap(cmd)
if acerr != nil {
return false, fmt.Errorf("couldn't get app config: %v", acerr)
return false, fmt.Errorf("couldn't get app config: %w", acerr)
}
tmConfig, tmFields, tmcerr := provconfig.ExtractTmConfigAndMap(cmd)
if tmcerr != nil {
return false, fmt.Errorf("couldn't get tendermint config: %v", tmcerr)
return false, fmt.Errorf("couldn't get tendermint config: %w", tmcerr)
}
clientConfig, clientFields, ccerr := provconfig.ExtractClientConfigAndMap(cmd)
if ccerr != nil {
return false, fmt.Errorf("couldn't get client config: %v", ccerr)
return false, fmt.Errorf("couldn't get client config: %w", ccerr)
}

if len(args) == 0 {
Expand Down Expand Up @@ -450,15 +450,15 @@ func runConfigSetCmd(cmd *cobra.Command, args []string) (bool, error) {
func runConfigChangedCmd(cmd *cobra.Command, args []string) error {
_, appFields, acerr := provconfig.ExtractAppConfigAndMap(cmd)
if acerr != nil {
return fmt.Errorf("couldn't get app config: %v", acerr)
return fmt.Errorf("couldn't get app config: %w", acerr)
}
_, tmFields, tmcerr := provconfig.ExtractTmConfigAndMap(cmd)
if tmcerr != nil {
return fmt.Errorf("couldn't get tendermint config: %v", tmcerr)
return fmt.Errorf("couldn't get tendermint config: %w", tmcerr)
}
_, clientFields, ccerr := provconfig.ExtractClientConfigAndMap(cmd)
if ccerr != nil {
return fmt.Errorf("couldn't get client config: %v", ccerr)
return fmt.Errorf("couldn't get client config: %w", ccerr)
}

if len(args) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/provenanced/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ func ApplyClientConfigToContext(ctx client.Context, config *ClientConfig) (clien

keyring, krerr := client.NewKeyringFromBackend(ctx, config.KeyringBackend)
if krerr != nil {
return ctx, fmt.Errorf("couldn't get key ring backend %s: %v", config.KeyringBackend, krerr)
return ctx, fmt.Errorf("couldn't get key ring backend %s: %w", config.KeyringBackend, krerr)
}

ctx = ctx.WithKeyring(keyring)

// https://github.com/cosmos/cosmos-sdk/issues/8986
clnt, nerr := client.NewClientFromNode(config.Node)
if nerr != nil {
return ctx, fmt.Errorf("couldn't get client from nodeURI: %v", nerr)
return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", nerr)
}

ctx = ctx.WithNodeURI(config.Node).
Expand Down
2 changes: 1 addition & 1 deletion cmd/provenanced/config/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command) error {
// Binds viper flags using the PIO ENV prefix.
func bindFlagsAndEnv(cmd *cobra.Command, v *viper.Viper) (err error) {
defer func() {
recover() // nolint:errcheck
recover() //nolint:errcheck
}()

replacer := strings.NewReplacer(".", "_", "-", "_")
Expand Down
4 changes: 2 additions & 2 deletions cmd/provenanced/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func loadPackedConfig(cmd *cobra.Command) error {
}
}
if rvErr != nil {
return fmt.Errorf("one or more fields in the packed config could not be set\n%s", rvErr)
return fmt.Errorf("one or more fields in the packed config could not be set\n%w", rvErr)
}

// Set the config values as defaults in viper.
Expand Down Expand Up @@ -649,5 +649,5 @@ func appendError(origErr, newErr error) error {
if origErr == nil {
return newErr
}
return fmt.Errorf("%v\n%v", origErr, newErr)
return fmt.Errorf("%v\n%v", origErr, newErr) //nolint:errorlint // Can't wrap two errors at once.
}
24 changes: 14 additions & 10 deletions cmd/provenanced/config/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ type FieldValueMap map[string]reflect.Value
// Each segment of a name comes from getFieldName. I.e. pays attention to mapstruct and is all lowercase.
// Similarly, if mapstruct says to squash the fields, they won't have the parent field name.
// If fillNilsWithZero is true, nil fields in the obj will be filled in using zero values for that field type.
// Fields in structs created this way cannot be set later using the map values.
// But the resulting map will contain information about all possible fields in the object.
// None of the substructures will not have map entries specifically for the parent field containing the substructure.
// E.g. With { Foo: { Bar: "foobar" } }, there won't be an entry for "foo", but there will be one for "foo.bar".
//
// Fields in structs created this way cannot be set later using the map values.
// But the resulting map will contain information about all possible fields in the object.
// None of the substructures will not have map entries specifically for the parent field containing the substructure.
// E.g. With { Foo: { Bar: "foobar" } }, there won't be an entry for "foo", but there will be one for "foo.bar".
//
// If fillNilsWithZero is false, nil fields in the obj will have an entry for the field and a value where .IsNil() is true.
// If the provided obj is a pointer, then the resulting map values can be used to set values in the obj.
// Substructures that are nil will have entries in the resulting map.
// E.g. With { Foo: (*Bar)(nil) }, there will be an entry for "foo".
// Substructures that are not nill will still not have an entry though; they'll have entries for sub-fields still.
// E.g. With { Foo: (*Bar)(nil), Ban: { Ana: "banana" } will have entries for "foo" and "ban.ana", but not "ban" (it isn't nil).
//
// If the provided obj is a pointer, then the resulting map values can be used to set values in the obj.
// Substructures that are nil will have entries in the resulting map.
// E.g. With { Foo: (*Bar)(nil) }, there will be an entry for "foo".
// Substructures that are not nill will still not have an entry though; they'll have entries for sub-fields still.
// E.g. With { Foo: (*Bar)(nil), Ban: { Ana: "banana" } will have entries for "foo" and "ban.ana", but not "ban" (it isn't nil).
func MakeFieldValueMap(obj interface{}, fillNilsWithZero bool) FieldValueMap {
if obj == nil {
return FieldValueMap{}
Expand Down Expand Up @@ -182,7 +185,8 @@ func (m FieldValueMap) GetStringOf(key string) string {
// For strings, it turns into `"a"`.
// For anything else, it just uses fmt %v.
// This wasn't designed with the following kinds in mind:
// Invalid, Chan, Func, Interface, Map, Ptr, Struct, or UnsafePointer.
//
// Invalid, Chan, Func, Interface, Map, Ptr, Struct, or UnsafePointer.
func GetStringFromValue(v reflect.Value) string {
switch v.Kind() {
case reflect.Slice, reflect.Array:
Expand Down
8 changes: 5 additions & 3 deletions cmd/provenanced/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"os"

"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -11,9 +12,10 @@ import (
func main() {
rootCmd, _ := cmd.NewRootCmd()
if err := cmd.Execute(rootCmd); err != nil {
switch e := err.(type) {
case server.ErrorCode:
os.Exit(e.Code)
var srvErr *server.ErrorCode
switch {
case errors.As(err, &srvErr):
os.Exit(srvErr.Code)
default:
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion docker/blockchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-bullseye as build
FROM golang:1.18-bullseye as build
ARG VERSION

WORKDIR /go/src/github.com/provenance-io/provenance
Expand Down
2 changes: 1 addition & 1 deletion docs/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Built executables are placed in the `build/` directory.

### Go

Building `provenanced` requires [Go 1.17+](https://golang.org/dl/) (or higher).
Building `provenanced` requires [Go 1.18+](https://golang.org/dl/) (or higher).

### CLevelDB

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/provenance-io/provenance

go 1.17
go 1.18

require (
github.com/CosmWasm/wasmd v0.26.0
Expand Down
Loading

0 comments on commit 25bb51b

Please sign in to comment.