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 <connect@thanethomson.com>

* Bump minimum Go version in CI/test infra

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Bump Go version in docs

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add changelog entry

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Ignore lint

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix math/rand usages in tests

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix lint: use local random source in test

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Rename variable for clarity

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Bump version of golangci-lint to latest

Signed-off-by: Thane Thomson <connect@thanethomson.com>

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
(cherry picked from commit 200784a)

* Resolve conflicts

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove use of deprecated global random seed

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Attempt to appease linter

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Attempt 2 to appease linter

Signed-off-by: Thane Thomson <connect@thanethomson.com>

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
cmwaters and thanethomson committed Jul 24, 2023
1 parent 5c94117 commit d93abad
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
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 @@ -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:
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 @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.20'

- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
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@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
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@v4
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 @@ -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:
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 5 additions & 4 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -433,21 +433,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) {

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/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) {
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/guides/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 @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/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.34.27
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/tendermint/tendermint

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
10 changes: 5 additions & 5 deletions test/fuzz/p2p/pex/init-corpus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/fuzz/p2p/secret_connection/read_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 11 additions & 10 deletions types/event_bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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"))
Expand All @@ -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{
Expand All @@ -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))]
}

0 comments on commit d93abad

Please sign in to comment.