Skip to content

Commit

Permalink
Update to use Go 1.20 (backport #405) (#419)
Browse files Browse the repository at this point in the history
* Update to use Go 1.20 (#405)

* Bump minimum Go version to 1.20 in go.mod

Signed-off-by: Thane Thomson <[email protected]>

* Bump minimum Go version in CI/test infra

Signed-off-by: Thane Thomson <[email protected]>

* Bump Go version in docs

Signed-off-by: Thane Thomson <[email protected]>

* Add changelog entry

Signed-off-by: Thane Thomson <[email protected]>

* Ignore lint

Signed-off-by: Thane Thomson <[email protected]>

* Fix math/rand usages in tests

Signed-off-by: Thane Thomson <[email protected]>

* Fix lint: use local random source in test

Signed-off-by: Thane Thomson <[email protected]>

* Rename variable for clarity

Signed-off-by: Thane Thomson <[email protected]>

* ci: Bump version of golangci-lint to latest

Signed-off-by: Thane Thomson <[email protected]>

---------

Signed-off-by: Thane Thomson <[email protected]>
(cherry picked from commit 200784acb3d9b3b955b237d038411534a5480b17)

# Conflicts:
#	.github/workflows/e2e-nightly-37x.yml
#	README.md
#	libs/rand/random.go
#	test/fuzz/README.md
#	test/fuzz/p2p/secret_connection/read_write.go
#	test/fuzz/tests/mempool_test.go
#	test/fuzz/tests/rpc_jsonrpc_server_test.go

* Resolve conflicts

Signed-off-by: Thane Thomson <[email protected]>

* Remove use of deprecated global random seed

Signed-off-by: Thane Thomson <[email protected]>

* Attempt to appease linter

Signed-off-by: Thane Thomson <[email protected]>

* Attempt 2 to appease linter

Signed-off-by: Thane Thomson <[email protected]>

---------

Signed-off-by: Thane Thomson <[email protected]>
Co-authored-by: Thane Thomson <[email protected]>
  • Loading branch information
mergify[bot] and thanethomson authored Feb 28, 2023
1 parent d136c53 commit f2bf249
Show file tree
Hide file tree
Showing 29 changed files with 70 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Bump minimum Go version to 1.20
([\#385](https://github.com/cometbft/cometbft/issues/385))
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand All @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand All @@ -65,7 +65,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"

- uses: actions/checkout@v3

Expand All @@ -42,7 +42,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"

- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-manual-multiversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'

- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'

- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-nightly-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'

- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fuzz-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'

- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand All @@ -32,7 +32,7 @@ jobs:
go.sum
- uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.51
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'

- name: Generate release notes
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.20'

- name: Generate release notes
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion DOCKER/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use a build arg to ensure that both stages use the same,
# hopefully current, go version.
ARG GOLANG_BASE_IMAGE=golang:1.19-alpine
ARG GOLANG_BASE_IMAGE=golang:1.20-alpine

# stage 1 Generate CometBFT Binary
FROM --platform=$BUILDPLATFORM $GOLANG_BASE_IMAGE as builder
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ looking for, see [our security policy](SECURITY.md).

| CometBFT version | Requirement | Notes |
|------------------|-------------|-------------------|
| v0.34.x | Go version | Go 1.18 or higher |
| v0.37.x | Go version | Go 1.19 or higher |
| v0.34.x | Go version | Go 1.19 or higher |
| v0.37.x | Go version | Go 1.20 or higher |
| main | Go version | Go 1.20 or higher |

### Install

Expand Down Expand Up @@ -166,7 +167,7 @@ maintains [cometbft.com](https://cometbft.com).
[version-url]: https://github.com/cometbft/cometbft/releases/latest
[api-badge]: https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f6c616e672f6764646f3f7374617475732e737667
[api-url]: https://pkg.go.dev/github.com/cometbft/cometbft
[go-badge]: https://img.shields.io/badge/go-1.19-blue.svg
[go-badge]: https://img.shields.io/badge/go-1.20-blue.svg
[go-url]: https://github.com/moovweb/gvm
[discord-badge]: https://img.shields.io/discord/669268347736686612.svg
[discord-url]: https://discord.gg/cosmosnetwork
Expand Down
11 changes: 7 additions & 4 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (cli *grpcClient) OnStart() error {

RETRY_LOOP:
for {
//nolint:staticcheck // SA1019 Existing use of deprecated but supported dial option.
//nolint:staticcheck,nolintlint // SA1019 Existing use of deprecated but supported dial option.
conn, err := grpc.Dial(cli.addr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
if err != nil {
if cli.mustConnect {
Expand Down Expand Up @@ -412,19 +412,22 @@ func (cli *grpcClient) OfferSnapshotSync(params types.RequestOfferSnapshot) (*ty
}

func (cli *grpcClient) LoadSnapshotChunkSync(
params types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
params types.RequestLoadSnapshotChunk,
) (*types.ResponseLoadSnapshotChunk, error) {
reqres := cli.LoadSnapshotChunkAsync(params)
return cli.finishSyncCall(reqres).GetLoadSnapshotChunk(), cli.Error()
}

func (cli *grpcClient) ApplySnapshotChunkSync(
params types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
params types.RequestApplySnapshotChunk,
) (*types.ResponseApplySnapshotChunk, error) {
reqres := cli.ApplySnapshotChunkAsync(params)
return cli.finishSyncCall(reqres).GetApplySnapshotChunk(), cli.Error()
}

func (cli *grpcClient) PrepareProposalSync(
params types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
params types.RequestPrepareProposal,
) (*types.ResponsePrepareProposal, error) {
reqres := cli.PrepareProposalAsync(params)
return cli.finishSyncCall(reqres).GetPrepareProposal(), cli.Error()
}
Expand Down
10 changes: 6 additions & 4 deletions abci/example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import (
"github.com/cometbft/cometbft/abci/types"
)

var grand *rand.Rand

func init() {
rand.Seed(time.Now().UnixNano())
grand = rand.New(rand.NewSource(time.Now().UnixNano()))
}

func TestKVStore(t *testing.T) {
Expand All @@ -46,7 +48,7 @@ func TestGRPC(t *testing.T) {

func testStream(t *testing.T, app types.Application) {
numDeliverTxs := 20000
socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30))
socketFile := fmt.Sprintf("test-%08x.sock", grand.Int31n(1<<30))
defer os.Remove(socketFile)
socket := fmt.Sprintf("unix://%v", socketFile)

Expand Down Expand Up @@ -130,7 +132,7 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {

func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
numDeliverTxs := 2000
socketFile := fmt.Sprintf("/tmp/test-%08x.sock", rand.Int31n(1<<30))
socketFile := fmt.Sprintf("/tmp/test-%08x.sock", grand.Int31n(1<<30))
defer os.Remove(socketFile)
socket := fmt.Sprintf("unix://%v", socketFile)

Expand All @@ -148,7 +150,7 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
})

// Connect to the socket
//nolint:staticcheck // SA1019 Existing use of deprecated but supported dial option.
//nolint:staticcheck,nolintlint // SA1019 Existing use of deprecated but supported dial option.
conn, err := grpc.Dial(socket, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
if err != nil {
t.Fatalf("Error dialing GRPC server: %v", err.Error())
Expand Down
3 changes: 2 additions & 1 deletion crypto/merkle/proof_key_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package merkle
import (
// it is ok to use math/rand here: we do not need a cryptographically secure random
// number generator here and we can run the tests a bit faster
crand "crypto/rand"
"math/rand"
"testing"

Expand All @@ -26,7 +27,7 @@ func TestKeyPath(t *testing.T) {
keys[i][j] = alphanum[rand.Intn(len(alphanum))]
}
case KeyEncodingHex:
rand.Read(keys[i])
_, _ = crand.Read(keys[i])
default:
panic("Unexpected encoding")
}
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/go-built-in.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Verify that you have the latest version of Go installed (refer to the [official

```bash
$ go version
go version go1.19.2 darwin/amd64
go version go1.20.1 darwin/amd64
```

## 1.2 Creating a new Go project
Expand Down Expand Up @@ -95,7 +95,7 @@ The go.mod file should look similar to:
```go
module github.com/me/example

go 1.19
go 1.20

require (
github.com/cometbft/cometbft v0.37.0
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Verify that you have the latest version of Go installed (refer to the [official

```bash
$ go version
go version go1.19.2 darwin/amd64
go version go1.20.1 darwin/amd64
```

## 1.2 Creating a new Go project
Expand Down Expand Up @@ -94,7 +94,7 @@ The go.mod file should look similar to:
```go
module github.com/me/example

go 1.19
go 1.20

require (
github.com/cometbft/cometbft v0.37.0
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/cometbft/cometbft

go 1.19
go 1.20

require (
github.com/BurntSushi/toml v1.2.1
Expand Down
11 changes: 5 additions & 6 deletions libs/rand/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
mrand "math/rand"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -37,10 +36,6 @@ func TestRandIntn(t *testing.T) {
func TestDeterminism(t *testing.T) {
var firstOutput string

// Set math/rand's seed for the sake of debugging this test.
// (It isn't strictly necessary).
mrand.Seed(1)

for i := 0; i < 100; i++ {
output := testThemAll()
if i == 0 {
Expand All @@ -53,7 +48,6 @@ func TestDeterminism(t *testing.T) {
}

func testThemAll() string {

// Such determinism.
grand.reset(1)

Expand Down Expand Up @@ -92,18 +86,23 @@ func TestRngConcurrencySafety(t *testing.T) {
func BenchmarkRandBytes10B(b *testing.B) {
benchmarkRandBytes(b, 10)
}

func BenchmarkRandBytes100B(b *testing.B) {
benchmarkRandBytes(b, 100)
}

func BenchmarkRandBytes1KiB(b *testing.B) {
benchmarkRandBytes(b, 1024)
}

func BenchmarkRandBytes10KiB(b *testing.B) {
benchmarkRandBytes(b, 10*1024)
}

func BenchmarkRandBytes100KiB(b *testing.B) {
benchmarkRandBytes(b, 100*1024)
}

func BenchmarkRandBytes1MiB(b *testing.B) {
benchmarkRandBytes(b, 1024*1024)
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/grpc/client_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func StartGRPCServer(ln net.Listener) error {
// StartGRPCClient dials the gRPC server using protoAddr and returns a new
// BroadcastAPIClient.
func StartGRPCClient(protoAddr string) BroadcastAPIClient {
//nolint:staticcheck // SA1019 Existing use of deprecated but supported dial option.
//nolint:staticcheck,nolintlint // SA1019 Existing use of deprecated but supported dial option.
conn, err := grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion scripts/proto-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd "$(git rev-parse --show-toplevel)"

# Run inside Docker to install the correct versions of the required tools
# without polluting the local system.
docker run --rm -i -v "$PWD":/w --workdir=/w golang:1.19-alpine sh <<"EOF"
docker run --rm -i -v "$PWD":/w --workdir=/w golang:1.20-alpine sh <<"EOF"
apk add git make
go install github.com/bufbuild/buf/cmd/buf
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# We need to build in a Linux environment to support C libraries, e.g. RocksDB.
# We use Debian instead of Alpine, so that we can use binary database packages
# instead of spending time compiling them.
FROM golang:1.19
FROM golang:1.20

RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
RUN apt-get -qq install -y libleveldb-dev librocksdb-dev >/dev/null
Expand Down
3 changes: 2 additions & 1 deletion test/fuzz/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# fuzz

Fuzzing for various packages in CometBFT using [go-fuzz](https://github.com/dvyukov/go-fuzz) library.
Fuzzing for various packages in CometBFT using
[go-fuzz](https://github.com/dvyukov/go-fuzz) library.

Inputs:

Expand Down
Loading

0 comments on commit f2bf249

Please sign in to comment.