From d93abad96643133c1a1293203af934e0f43d21a6 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 24 Jul 2023 12:59:05 +0200 Subject: [PATCH] Update to use Go 1.20 (backport #405) (#419) * Update to use Go 1.20 (#405) * Bump minimum Go version to 1.20 in go.mod Signed-off-by: Thane Thomson * Bump minimum Go version in CI/test infra Signed-off-by: Thane Thomson * Bump Go version in docs Signed-off-by: Thane Thomson * Add changelog entry Signed-off-by: Thane Thomson * Ignore lint Signed-off-by: Thane Thomson * Fix math/rand usages in tests Signed-off-by: Thane Thomson * Fix lint: use local random source in test Signed-off-by: Thane Thomson * Rename variable for clarity Signed-off-by: Thane Thomson * ci: Bump version of golangci-lint to latest Signed-off-by: Thane Thomson --------- Signed-off-by: Thane Thomson (cherry picked from commit 200784acb3d9b3b955b237d038411534a5480b17) * Resolve conflicts Signed-off-by: Thane Thomson * Remove use of deprecated global random seed Signed-off-by: Thane Thomson * Attempt to appease linter Signed-off-by: Thane Thomson * Attempt 2 to appease linter Signed-off-by: Thane Thomson --------- Signed-off-by: Thane Thomson Co-authored-by: Thane Thomson --- .github/workflows/check-generated.yml | 2 +- .github/workflows/e2e-manual.yml | 2 +- .github/workflows/e2e.yml | 2 +- .github/workflows/fuzz-nightly.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/pre-release.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/tests.yml | 2 +- DOCKER/Dockerfile | 2 +- README.md | 2 +- abci/client/grpc_client.go | 9 ++++---- abci/example/example_test.go | 10 +++++---- crypto/merkle/proof_key_path_test.go | 3 ++- docs/guides/go-built-in.md | 4 ++-- docs/guides/go.md | 4 ++-- go.mod | 2 +- libs/rand/random_test.go | 11 +++++----- rpc/grpc/client_server.go | 2 +- scripts/proto-gen.sh | 2 +- test/fuzz/p2p/pex/init-corpus/main.go | 10 ++++----- test/fuzz/p2p/secret_connection/read_write.go | 2 +- types/event_bus_test.go | 21 ++++++++++--------- 22 files changed, 52 insertions(+), 48 deletions(-) diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index ba206e4964..6151fd5fde 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -43,7 +43,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: "1.20" - uses: actions/checkout@v3 with: diff --git a/.github/workflows/e2e-manual.yml b/.github/workflows/e2e-manual.yml index bca2861687..91ec9d2967 100644 --- a/.github/workflows/e2e-manual.yml +++ b/.github/workflows/e2e-manual.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: '1.20' - uses: actions/checkout@v3 diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 2cb134aa90..10ff022080 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: '1.20' - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: diff --git a/.github/workflows/fuzz-nightly.yml b/.github/workflows/fuzz-nightly.yml index c2fcda24c7..3a90a681d6 100644 --- a/.github/workflows/fuzz-nightly.yml +++ b/.github/workflows/fuzz-nightly.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: '1.20' - uses: actions/checkout@v3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 33c46137d2..e360108cfc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: '1.20' - uses: technote-space/get-diff-action@v6 with: PATTERNS: | diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 2a9872bb9d..bbd28cbd06 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: '1.20' # Similar check to ./release-version.yml, but enforces this when pushing # tags. The ./release-version.yml check can be bypassed and is mainly diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f3a9dd4e93..73560af9c4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version: '1.20' - name: Generate release notes run: | diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 64bb85e744..d589bf79ee 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,7 +25,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.19" + go-version: "1.20" - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: diff --git a/DOCKER/Dockerfile b/DOCKER/Dockerfile index af6361e690..cf99713757 100644 --- a/DOCKER/Dockerfile +++ b/DOCKER/Dockerfile @@ -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 diff --git a/README.md b/README.md index b2a71d5f7f..fc56ca0c27 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ This repo intends on preserving the minimal possible diff with [cometbft/cometbf - **specific to Celestia**: consider if [celestia-app](https://github.com/celestiaorg/celestia-app) is a better target - **not specific to Celestia**: consider making the contribution upstream in CometBFT -1. [Install Go](https://go.dev/doc/install) 1.19+ +1. [Install Go](https://go.dev/doc/install) 1.20+ 2. Fork this repo 3. Clone your fork 4. Find an issue to work on (see [good first issues](https://github.com/celestiaorg/celestia-core/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)) diff --git a/abci/client/grpc_client.go b/abci/client/grpc_client.go index cbe1b71f2a..58d5969dd0 100644 --- a/abci/client/grpc_client.go +++ b/abci/client/grpc_client.go @@ -88,7 +88,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 { @@ -433,13 +433,15 @@ 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() } @@ -447,7 +449,6 @@ func (cli *grpcClient) ApplySnapshotChunkSync( func (cli *grpcClient) PrepareProposalSync( params types.RequestPrepareProposal, ) (*types.ResponsePrepareProposal, error) { - reqres := cli.PrepareProposalAsync(params) return cli.finishSyncCall(reqres).GetPrepareProposal(), cli.Error() } diff --git a/abci/example/example_test.go b/abci/example/example_test.go index 0bd172eb25..758f81c050 100644 --- a/abci/example/example_test.go +++ b/abci/example/example_test.go @@ -25,8 +25,10 @@ import ( "github.com/tendermint/tendermint/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) { @@ -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) @@ -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) @@ -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()) diff --git a/crypto/merkle/proof_key_path_test.go b/crypto/merkle/proof_key_path_test.go index 22e3e21ca3..25a61af929 100644 --- a/crypto/merkle/proof_key_path_test.go +++ b/crypto/merkle/proof_key_path_test.go @@ -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" @@ -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") } diff --git a/docs/guides/go-built-in.md b/docs/guides/go-built-in.md index 589f4b8733..b09c2b3c8b 100644 --- a/docs/guides/go-built-in.md +++ b/docs/guides/go-built-in.md @@ -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 @@ -96,7 +96,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.34.27 diff --git a/docs/guides/go.md b/docs/guides/go.md index 3bbe48d326..efb40b85c5 100644 --- a/docs/guides/go.md +++ b/docs/guides/go.md @@ -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 @@ -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.34.27 diff --git a/go.mod b/go.mod index 4deab97b04..eed8fcae13 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/tendermint/tendermint -go 1.19 +go 1.20 require ( github.com/BurntSushi/toml v1.2.1 diff --git a/libs/rand/random_test.go b/libs/rand/random_test.go index e669f250fa..10bb601b5e 100644 --- a/libs/rand/random_test.go +++ b/libs/rand/random_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - mrand "math/rand" "sync" "testing" "time" @@ -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 { @@ -53,7 +48,6 @@ func TestDeterminism(t *testing.T) { } func testThemAll() string { - // Such determinism. grand.reset(1) @@ -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) } diff --git a/rpc/grpc/client_server.go b/rpc/grpc/client_server.go index 39c6859c13..c914a4e4bb 100644 --- a/rpc/grpc/client_server.go +++ b/rpc/grpc/client_server.go @@ -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) diff --git a/scripts/proto-gen.sh b/scripts/proto-gen.sh index cb8261fdfd..d07ed32263 100755 --- a/scripts/proto-gen.sh +++ b/scripts/proto-gen.sh @@ -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 diff --git a/test/fuzz/p2p/pex/init-corpus/main.go b/test/fuzz/p2p/pex/init-corpus/main.go index dfa18363ef..d97be5c120 100644 --- a/test/fuzz/p2p/pex/init-corpus/main.go +++ b/test/fuzz/p2p/pex/init-corpus/main.go @@ -31,7 +31,7 @@ func initCorpus(rootDir string) { sizes := []int{0, 1, 2, 17, 5, 31} // Make the PRNG predictable - rand.Seed(10) + rnd := rand.New(rand.NewSource(10)) for _, n := range sizes { var addrs []*p2p.NetAddress @@ -42,10 +42,10 @@ func initCorpus(rootDir string) { addr := fmt.Sprintf( "%s@%v.%v.%v.%v:26656", p2p.PubKeyToID(privKey.PubKey()), - rand.Int()%256, - rand.Int()%256, - rand.Int()%256, - rand.Int()%256, + rnd.Int()%256, + rnd.Int()%256, + rnd.Int()%256, + rnd.Int()%256, ) netAddr, _ := p2p.NewNetAddressString(addr) addrs = append(addrs, netAddr) diff --git a/test/fuzz/p2p/secret_connection/read_write.go b/test/fuzz/p2p/secret_connection/read_write.go index 632790002e..8183316da8 100644 --- a/test/fuzz/p2p/secret_connection/read_write.go +++ b/test/fuzz/p2p/secret_connection/read_write.go @@ -63,7 +63,7 @@ func makeSecretConnPair() (fooSecConn, barSecConn *sc.SecretConnection) { ) // Make connections from both sides in parallel. - var trs, ok = async.Parallel( + trs, ok := async.Parallel( func(_ int) (val interface{}, abort bool, err error) { fooSecConn, err = sc.MakeSecretConnection(fooConn, fooPrvKey) if err != nil { diff --git a/types/event_bus_test.go b/types/event_bus_test.go index d9e71c1cac..2155ca57aa 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -13,7 +13,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" - cmtrand "github.com/tendermint/tendermint/libs/rand" ) func TestEventBusPublishEventTx(t *testing.T) { @@ -455,7 +454,7 @@ func BenchmarkEventBus(b *testing.B) { func benchmarkEventBus(numClients int, randQueries bool, randEvents bool, b *testing.B) { // for random* functions - rand.Seed(time.Now().Unix()) + rnd := rand.New(rand.NewSource(time.Now().Unix())) eventBus := NewEventBusWithBufferCapacity(0) // set buffer capacity to 0 so we are not testing cache err := eventBus.Start() @@ -473,7 +472,7 @@ func benchmarkEventBus(numClients int, randQueries bool, randEvents bool, b *tes for i := 0; i < numClients; i++ { if randQueries { - q = randQuery() + q = randQuery(rnd) } sub, err := eventBus.Subscribe(ctx, fmt.Sprintf("client-%d", i), q) if err != nil { @@ -496,7 +495,7 @@ func benchmarkEventBus(numClients int, randQueries bool, randEvents bool, b *tes b.ResetTimer() for i := 0; i < b.N; i++ { if randEvents { - eventType = randEvent() + eventType = randEvent(rnd) } err := eventBus.Publish(eventType, EventDataString("Gamora")) @@ -518,10 +517,11 @@ var events = []string{ EventLock, EventRelock, EventTimeoutWait, - EventVote} + EventVote, +} -func randEvent() string { - return events[cmtrand.Intn(len(events))] +func randEvent(r *rand.Rand) string { + return events[r.Intn(len(events))] } var queries = []cmtpubsub.Query{ @@ -536,8 +536,9 @@ var queries = []cmtpubsub.Query{ EventQueryLock, EventQueryRelock, EventQueryTimeoutWait, - EventQueryVote} + EventQueryVote, +} -func randQuery() cmtpubsub.Query { - return queries[cmtrand.Intn(len(queries))] +func randQuery(r *rand.Rand) cmtpubsub.Query { + return queries[r.Intn(len(queries))] }