diff --git a/.github/workflows/go-mod-check.yaml b/.github/workflows/go-mod-check.yaml index e7c510158..bc3c21171 100644 --- a/.github/workflows/go-mod-check.yaml +++ b/.github/workflows/go-mod-check.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' cache: false - name: go mod tidy diff --git a/.github/workflows/gosec.yaml b/.github/workflows/gosec.yaml index 77cde9c73..b520cd1b0 100644 --- a/.github/workflows/gosec.yaml +++ b/.github/workflows/gosec.yaml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' cache: false - name: Run Gosec id: gosec-run diff --git a/.github/workflows/lint-go.yaml b/.github/workflows/lint-go.yaml index c8f141d5f..c090dd712 100644 --- a/.github/workflows/lint-go.yaml +++ b/.github/workflows/lint-go.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' cache: false - name: Check `builtins` directory @@ -31,7 +31,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6.4.1 with: - version: v1.64.5 + version: v1.64.8 # use the default if on main branch, otherwise use the pull request config args: --timeout=30m --config=.golangci.yml only-new-issues: false diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index de2380aa7..65ad63e60 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,14 +11,14 @@ jobs: unit_tests: strategy: matrix: - go-version: [1.23.x] + go-version: [1.24.x] os: [ubuntu-latest, macos-latest, windows-latest] include: - go-version: 1.21.x os: ubuntu-latest - go-version: 1.22.x os: ubuntu-latest - - go-version: 1.24.x + - go-version: 1.23.x os: ubuntu-latest runs-on: ${{ matrix.os }} steps: @@ -46,7 +46,7 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: 1.23.x + go-version: 1.24.x - name: Make all run: make all diff --git a/Dockerfile b/Dockerfile index 89ebb06ab..475f549a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build thor in a stock Go builder container -FROM golang:1.23-alpine3.21 AS builder +FROM golang:1.24-alpine3.21 AS builder RUN apk add --no-cache make gcc musl-dev linux-headers git WORKDIR /go/thor diff --git a/Makefile b/Makefile index af31e11f1..3e6a3b909 100644 --- a/Makefile +++ b/Makefile @@ -33,11 +33,11 @@ dep:| go_version_check go_version_check: @if test $(MAJOR) -lt 1; then \ - echo "Go 1.23 or higher required"; \ + echo "Go 1.24 or higher required"; \ exit 1; \ else \ if test $(MAJOR) -eq 1 -a $(MINOR) -lt 22; then \ - echo "Go 1.23 or higher required"; \ + echo "Go 1.24 or higher required"; \ exit 1; \ fi \ fi diff --git a/go.mod b/go.mod index f0aeabbd8..99b371d88 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/vechain/thor/v2 -go 1.23 +go 1.24 require ( github.com/beevik/ntp v0.2.0 diff --git a/log/format_test.go b/log/format_test.go index 7e48f6b99..c66434251 100644 --- a/log/format_test.go +++ b/log/format_test.go @@ -26,7 +26,7 @@ var sink []byte func BenchmarkPrettyInt64Logfmt(b *testing.B) { buf := make([]byte, 100) b.ReportAllocs() - for i := 0; i < b.N; i++ { + for b.Loop() { sink = appendInt64(buf, rand.Int64()) //#nosec G404 } } @@ -34,7 +34,7 @@ func BenchmarkPrettyInt64Logfmt(b *testing.B) { func BenchmarkPrettyUint64Logfmt(b *testing.B) { buf := make([]byte, 100) b.ReportAllocs() - for i := 0; i < b.N; i++ { + for b.Loop() { sink = appendUint64(buf, rand.Uint64(), false) //#nosec G404 } } diff --git a/log/logger_test.go b/log/logger_test.go index 4d82c710e..2d0fcf87c 100644 --- a/log/logger_test.go +++ b/log/logger_test.go @@ -73,8 +73,8 @@ func TestJSONHandler(t *testing.T) { func BenchmarkTraceLogging(b *testing.B) { SetDefault(NewLogger(NewTerminalHandler(os.Stderr, true))) - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for i := 0; b.Loop(); i++ { Trace("a message", "v", i) } } @@ -102,8 +102,8 @@ func benchmarkLogger(b *testing.B, l Logger) { err = errors.New("oh nooes it's crap") ) b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for i := 0; b.Loop(); i++ { l.Info("This is a message", "foo", int16(i), "bytes", bb, @@ -165,18 +165,18 @@ const termTimeFormat = "01-02|15:04:05.000" func BenchmarkAppendFormat(b *testing.B) { var now = time.Now() b.Run("fmt time.Format", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { fmt.Fprintf(io.Discard, "%s", now.Format(termTimeFormat)) } }) b.Run("time.AppendFormat", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { now.AppendFormat(nil, termTimeFormat) } }) var buf = new(bytes.Buffer) b.Run("time.Custom", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { writeTimeTermFormat(buf, now) buf.Reset() } diff --git a/logdb/logdb_bench_test.go b/logdb/logdb_bench_test.go index 7e87c27a5..9a061107e 100644 --- a/logdb/logdb_bench_test.go +++ b/logdb/logdb_bench_test.go @@ -78,7 +78,7 @@ func BenchmarkFakeDB_NewestBlockID(t *testing.B) { t.ResetTimer() for _, tt := range tests { t.Run(tt.name, func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { want, err := tt.prepare() require.NoError(t, err) @@ -139,7 +139,7 @@ func BenchmarkFakeDB_WriteBlocks(t *testing.B) { t.ResetTimer() for _, tt := range tests { t.Run(tt.name, func(b *testing.B) { - for i := 0; i < t.N; i++ { + for t.Loop() { tt.writeFunc(b) } }) @@ -158,8 +158,7 @@ func BenchmarkTestDB_HasBlockID(b *testing.B) { require.NoError(b, err) require.GreaterOrEqual(b, len(events), 500_000, "there should be more than 500k events in the db") - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { for _, event := range events { has, err := db.HasBlockID(event.BlockID) require.NoError(b, err) @@ -203,7 +202,7 @@ func BenchmarkTestDB_FilterEvents(b *testing.B) { for _, tt := range tests { b.Run(tt.name, func(b *testing.B) { b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { _, err = db.FilterEvents(context.Background(), tt.arg) if err != nil { b.Fatal(err) @@ -242,7 +241,7 @@ func BenchmarkTestDB_FilterTransfers(b *testing.B) { for _, tt := range tests { b.Run(tt.name, func(b *testing.B) { b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { _, err = db.FilterTransfers(context.Background(), tt.arg) if err != nil { b.Fatal(err) diff --git a/muxdb/cache_test.go b/muxdb/cache_test.go index 3f0c14bbe..9b1203153 100644 --- a/muxdb/cache_test.go +++ b/muxdb/cache_test.go @@ -66,7 +66,7 @@ func Benchmark_cacheNodeBlob(b *testing.B) { ) rand.Read(blob) - for i := 0; i < b.N; i++ { + for b.Loop() { cache.AddNodeBlob(&keyBuf, name, path, trie.Version{}, blob, true) got := cache.GetNodeBlob(&keyBuf, name, path, trie.Version{}, false) if !bytes.Equal(got, blob) { @@ -86,7 +86,7 @@ func Benchmark_cacheRootNode(b *testing.B) { rn := tr.RootNode() - for i := 0; i < b.N; i++ { + for b.Loop() { cache.AddRootNode(name, rn) got := cache.GetRootNode(name, trie.Version{}) if got != rn { diff --git a/thor/hash_test.go b/thor/hash_test.go index fda605a97..8ec031c9f 100644 --- a/thor/hash_test.go +++ b/thor/hash_test.go @@ -29,7 +29,7 @@ func BenchmarkHash(b *testing.B) { k := sha3.NewLegacyKeccak256().(keccakState) var b32 thor.Bytes32 - for i := 0; i < b.N; i++ { + for b.Loop() { k.Write(data) k.Read(b32[:]) k.Reset() @@ -37,7 +37,7 @@ func BenchmarkHash(b *testing.B) { }) b.Run("blake2b", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { thor.Blake2b(data) } }) @@ -47,13 +47,13 @@ func BenchmarkBlake2b(b *testing.B) { data := make([]byte, 100) rand.New(rand.NewSource(1)).Read(data) //#nosec G404 b.Run("Blake2b", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { thor.Blake2b(data).Bytes() } }) b.Run("BlakeFn", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { thor.Blake2bFn(func(w io.Writer) { w.Write(data) }) diff --git a/tracers/tracers_test.go b/tracers/tracers_test.go index 54118de32..5b900a549 100644 --- a/tracers/tracers_test.go +++ b/tracers/tracers_test.go @@ -99,7 +99,7 @@ type traceTest struct { type callTest struct { traceTest - Calls callFrame `json:"calls,omitempty"` + Calls callFrame `json:"calls"` } type diffState struct { diff --git a/trie/derive_root_test.go b/trie/derive_root_test.go index 5e3a95e90..7a2ab3bc6 100644 --- a/trie/derive_root_test.go +++ b/trie/derive_root_test.go @@ -23,7 +23,7 @@ func BenchmarkDeriveRoot(b *testing.B) { n: 100, content: make([]byte, 32), } - for i := 0; i < b.N; i++ { + for b.Loop() { DeriveRoot(&list) } } diff --git a/trie/encoding_test.go b/trie/encoding_test.go index dd019d44f..2784dfa69 100644 --- a/trie/encoding_test.go +++ b/trie/encoding_test.go @@ -83,7 +83,7 @@ func TestHexKeybytes(t *testing.T) { func BenchmarkHexToCompact(b *testing.B) { testBytes := []byte{0, 15, 1, 12, 11, 8, 16 /*term*/} - for i := 0; i < b.N; i++ { + for b.Loop() { hexToCompact(testBytes) } } @@ -91,28 +91,28 @@ func BenchmarkHexToCompact(b *testing.B) { func BenchmarkAppendHexToCompact(b *testing.B) { testBytes := []byte{0, 15, 1, 12, 11, 8, 16 /*term*/} var buf []byte - for i := 0; i < b.N; i++ { + for b.Loop() { buf = appendHexToCompact(buf[:0], testBytes) } } func BenchmarkCompactToHex(b *testing.B) { testBytes := []byte{0, 15, 1, 12, 11, 8, 16 /*term*/} - for i := 0; i < b.N; i++ { + for b.Loop() { compactToHex(testBytes) } } func BenchmarkKeybytesToHex(b *testing.B) { testBytes := []byte{7, 6, 6, 5, 7, 2, 6, 2, 16} - for i := 0; i < b.N; i++ { + for b.Loop() { keybytesToHex(testBytes) } } func BenchmarkHexToKeybytes(b *testing.B) { testBytes := []byte{7, 6, 6, 5, 7, 2, 6, 2, 16} - for i := 0; i < b.N; i++ { + for b.Loop() { hexToKeybytes(testBytes) } } diff --git a/trie/node_test.go b/trie/node_test.go index 8c795b923..544d6c506 100644 --- a/trie/node_test.go +++ b/trie/node_test.go @@ -33,7 +33,7 @@ func benchmarkEncodeFullNode(b *testing.B, consensus, skipHash bool) { for i := range 16 { f.children[i] = &refNode{hash: datagen.RandomHash().Bytes()} } - for i := 0; i < b.N; i++ { + for b.Loop() { if consensus { buf = f.encodeConsensus(buf[:0]) } else { @@ -50,7 +50,7 @@ func benchmarkEncodeShortNode(b *testing.B, consensus bool) { buf []byte ) - for i := 0; i < b.N; i++ { + for b.Loop() { if consensus { buf = s.encodeConsensus(buf[:0]) } else { @@ -85,7 +85,7 @@ func benchmarkDecodeFullNode(b *testing.B, skipHash bool) { f.children[i] = &refNode{hash: datagen.RandomHash().Bytes()} } enc := f.encode(nil, skipHash) - for i := 0; i < b.N; i++ { + for b.Loop() { mustDecodeNode(nil, enc, 0) } } @@ -105,7 +105,7 @@ func BenchmarkDecodeShortNode(b *testing.B) { } enc := s.encode(nil, false) - for i := 0; i < b.N; i++ { + for b.Loop() { mustDecodeNode(nil, enc, 0) } } diff --git a/trie/trie_test.go b/trie/trie_test.go index 34f165795..b20f0fae0 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -474,8 +474,7 @@ func benchGet(b *testing.B, commit bool) { trie.Commit(db, root.Ver, false) } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { trie.Get(k) } b.StopTimer() @@ -484,7 +483,7 @@ func benchGet(b *testing.B, commit bool) { func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie { trie := new(Trie) k := make([]byte, 32) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { e.PutUint64(k, uint64(i)) trie.Update(k, k, nil) } diff --git a/tx/transaction_test.go b/tx/transaction_test.go index 0d364f2f4..755c55c08 100644 --- a/tx/transaction_test.go +++ b/tx/transaction_test.go @@ -285,7 +285,7 @@ func BenchmarkTxMining(b *testing.B) { signer := thor.BytesToAddress([]byte("acc1")) maxWork := &big.Int{} eval := tx.EvaluateWork(signer) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { work := eval(uint64(i)) if work.Cmp(maxWork) > 0 { maxWork = work diff --git a/vm/analysis_test.go b/vm/analysis_test.go index 3d1d0478a..cefd1d332 100644 --- a/vm/analysis_test.go +++ b/vm/analysis_test.go @@ -65,8 +65,8 @@ func BenchmarkJumpdestAnalysis_1200k(bench *testing.B) { // 1.4 ms code := make([]byte, analysisCodeSize) bench.SetBytes(analysisCodeSize) - bench.ResetTimer() - for i := 0; i < bench.N; i++ { + + for bench.Loop() { codeBitmap(code) } bench.StopTimer() @@ -75,8 +75,8 @@ func BenchmarkJumpdestHashing_1200k(bench *testing.B) { // 4 ms code := make([]byte, analysisCodeSize) bench.SetBytes(analysisCodeSize) - bench.ResetTimer() - for i := 0; i < bench.N; i++ { + + for bench.Loop() { thor.Keccak256(code) } bench.StopTimer() @@ -92,7 +92,7 @@ func BenchmarkJumpdestOpAnalysis(bench *testing.B) { } bits := make(bitvec, len(code)/8+1+4) b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { for j := range bits { bits[j] = 0 } diff --git a/vm/contracts_test.go b/vm/contracts_test.go index 0977165e5..f8441334c 100644 --- a/vm/contracts_test.go +++ b/vm/contracts_test.go @@ -164,7 +164,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { bench.ReportAllocs() start := time.Now() bench.ResetTimer() - for i := 0; i < bench.N; i++ { + for bench.Loop() { copy(data, in) contract := NewContract(AccountRef(common.HexToAddress("1337")), nil, new(big.Int), reqGas) diff --git a/vm/instructions_test.go b/vm/instructions_test.go index 4ce3ec91b..00e18b082 100644 --- a/vm/instructions_test.go +++ b/vm/instructions_test.go @@ -193,8 +193,8 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contr byteArgs[i] = common.Hex2Bytes(arg) } pc := uint64(0) - bench.ResetTimer() - for i := 0; i < bench.N; i++ { + + for bench.Loop() { for _, arg := range byteArgs { a := new(uint256.Int).SetBytes(arg) stack.push(a) diff --git a/vrf/vrf_test.go b/vrf/vrf_test.go index 3dace6795..12270230f 100644 --- a/vrf/vrf_test.go +++ b/vrf/vrf_test.go @@ -198,7 +198,7 @@ func BenchmarkVRF(b *testing.B) { alpha := []byte("Hello VeChain") b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { _, _, err := vrf.Prove(sk, alpha) if err != nil { b.Fatal(err) @@ -211,7 +211,7 @@ func BenchmarkVRF(b *testing.B) { _, pi, _ := vrf.Prove(sk, alpha) b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { _, err := vrf.Verify(&sk.PublicKey, alpha, pi) if err != nil { b.Fatal(err)