Skip to content

Commit

Permalink
Update Go version to 1.22 (#1731)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan authored Mar 26, 2024
1 parent 8b790ec commit ece0bd6
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/juno-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.54.2
version: v1.56.2
2 changes: 1 addition & 1 deletion .github/workflows/juno-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: [ '1.21' ]
go: [ '1.22' ]
os: [ ubuntu-latest, macos-latest, self-hosted-linux-arm64]
runs-on: ${{ matrix.os }}
env:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build golang dependencies and binaries
FROM ubuntu:23.10 AS build
FROM ubuntu:24.04 AS build

ARG VM_DEBUG

Expand All @@ -19,7 +19,7 @@ RUN VM_DEBUG=${VM_DEBUG} make juno
RUN upx-ucl /app/build/juno

# Stage 2: Build Docker image
FROM ubuntu:23.10 AS runtime
FROM ubuntu:24.04 AS runtime

RUN apt-get update && apt-get install -y ca-certificates curl gawk grep libjemalloc-dev libjemalloc2

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ install-mockgen:
go install go.uber.org/mock/mockgen@latest

install-golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2

lint:
@which golangci-lint || make install-golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

### Prerequisites

- Golang 1.20 or higher is required to build and run the project. You can find the installer on
- Golang 1.22 or higher is required to build and run the project. You can find the installer on
the official Golang [download](https://go.dev/doc/install) page.
- [Rust](https://www.rust-lang.org/tools/install).
- A C compiler: `gcc` or `clang`.
Expand Down
2 changes: 1 addition & 1 deletion blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestEvents(t *testing.T) {
client := feeder.NewTestClient(t, &utils.Goerli2)
gw := adaptfeeder.New(client)

for i := 0; i < 7; i++ {
for i := range 7 {
b, err := gw.BlockByNumber(context.Background(), uint64(i))
require.NoError(t, err)
s, err := gw.StateUpdate(context.Background(), uint64(i))
Expand Down
3 changes: 2 additions & 1 deletion core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"runtime"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -67,7 +68,7 @@ func (rb ResourceBounds) Bytes(resource Resource) []byte {
maxAmountBytes := make([]byte, eight)
binary.BigEndian.PutUint64(maxAmountBytes, rb.MaxAmount)
maxPriceBytes := rb.MaxPricePerUnit.Bytes()
return utils.Flatten(
return slices.Concat(
[]byte{0},
[]byte(resource.String()),
maxAmountBytes,
Expand Down
4 changes: 2 additions & 2 deletions core/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestPutZero(t *testing.T) {
var keys []*felt.Felt

// put random 64 keys and record roots
for i := 0; i < 64; i++ {
for range 64 {
key, value := new(felt.Felt), new(felt.Felt)

_, err = key.SetRandom()
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestPutZero(t *testing.T) {
t.Run("remove keys one by one, check roots", func(t *testing.T) {
var gotRoot *felt.Felt
// put zero in reverse order and check roots still match
for i := 0; i < 64; i++ {
for i := range 64 {
root := roots[len(roots)-1-i]

gotRoot, err = tempTrie.Root()
Expand Down
4 changes: 2 additions & 2 deletions db/buckets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package db

import "bytes"
import "slices"

type Bucket byte

Expand Down Expand Up @@ -36,5 +36,5 @@ const (

// Key flattens a prefix and series of byte arrays into a single []byte.
func (b Bucket) Key(key ...[]byte) []byte {
return append([]byte{byte(b)}, bytes.Join(key, []byte{})...)
return append([]byte{byte(b)}, slices.Concat(key...)...)
}
8 changes: 4 additions & 4 deletions db/pebble/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ func TestConcurrentUpdate(t *testing.T) {
require.NoError(t, testDB.Update(func(txn db.Transaction) error {
return txn.Set(key, []byte{0})
}))
for i := 0; i < 10; i++ {
for range 10 {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 10; i++ {
for range 10 {
assert.NoError(t, testDB.Update(func(txn db.Transaction) error {
var next byte
err := txn.Get(key, func(bytes []byte) error {
Expand All @@ -219,11 +219,11 @@ func TestConcurrentUpdate(t *testing.T) {
}()
}

for i := 0; i < 10; i++ {
for range 10 {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 10; i++ {
for range 10 {
txn, err := testDB.NewTransaction(true)
require.NoError(t, err)
var next byte
Expand Down
2 changes: 1 addition & 1 deletion db/pebble/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (t *Transaction) Get(key []byte, cb func([]byte) error) error {
return ErrDiscardedTransaction
}

defer t.listener.OnIO(false, time.Since(start))
defer t.listener.OnIO(false, time.Since(start)) //nolint:govet
if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return db.ErrKeyNotFound
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/NethermindEth/juno

go 1.21
// if version specified as "1.22" (without bugfix) it breaks CodeQL github build
go 1.22.0

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/bits-and-blooms/bitset v1.13.0
github.com/bits-and-blooms/bloom/v3 v3.6.0
github.com/cockroachdb/pebble v1.0.0
github.com/consensys/gnark-crypto v0.12.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/ethereum/go-ethereum v1.13.10
github.com/fxamacker/cbor/v2 v2.5.0
github.com/go-playground/validator/v10 v10.17.0
Expand Down Expand Up @@ -50,6 +50,7 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions grpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"fmt"
"slices"

"github.com/Masterminds/semver/v3"
"github.com/NethermindEth/juno/db"
Expand Down Expand Up @@ -93,13 +94,13 @@ func (h Handler) handleTxCursor(

switch cur.Op {
case gen.Op_SEEK:
key := utils.Flatten(cur.BucketName, cur.K)
key := slices.Concat(cur.BucketName, cur.K)
if it.Seek(key) {
responsePair.K = it.Key()
responsePair.V, err = it.Value()
}
case gen.Op_SEEK_EXACT:
key := utils.Flatten(cur.BucketName, cur.K)
key := slices.Concat(cur.BucketName, cur.K)
if it.Seek(key) && bytes.Equal(it.Key(), key) {
responsePair.K = it.Key()
responsePair.V, err = it.Value()
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func TestWriteToClosedConnInHandler(t *testing.T) {
w, ok := jsonrpc.ConnFromContext(ctx)
require.True(t, ok)
wg.Go(func() {
for i := 0; i < 3; i++ {
for range 3 {
_, err := w.Write([]byte("test"))
require.ErrorIs(t, err, io.ErrClosedPipe)
require.ErrorContains(t, err, "there was an error while writing the initial response")
Expand Down
2 changes: 1 addition & 1 deletion l1/eth_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *EthSubscriber) FinalisedHeight(ctx context.Context) (uint64, error) {
return 0, fmt.Errorf("get finalised Ethereum block: %w", err)
}

number, ok := finalisedBlock["number"] //nolint:gosec
number, ok := finalisedBlock["number"]
if !ok {
return 0, fmt.Errorf("number field not present in Ethereum block")
}
Expand Down
4 changes: 2 additions & 2 deletions migration/migration_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestChangeTrieNodeEncoding(t *testing.T) {
require.NoError(t, txn.Set(db.ContractStorage.Key(make([]byte, felt.Bytes)), []byte{1, 2, 3}))

for _, bucket := range buckets {
for i := 0; i < 5; i++ {
for i := range 5 {
n.Value = new(felt.Felt).SetUint64(uint64(i))

encodedNode, err := encoder.Marshal(n)
Expand All @@ -149,7 +149,7 @@ func TestChangeTrieNodeEncoding(t *testing.T) {

require.NoError(t, testdb.Update(func(txn db.Transaction) error {
for _, bucket := range buckets {
for i := 0; i < 5; i++ {
for i := range 5 {
var coreNode trie.Node
err := txn.Get(bucket.Key([]byte{byte(i)}), coreNode.UnmarshalBinary)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion p2p/starknet/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestStream(t *testing.T) {
stream := starknet.StaticStream[int](0, 1, 2, 3)
for i := 0; i < 4; i++ {
for i := range 4 {
next, valid := stream()
require.True(t, valid)
require.Equal(t, i, next)
Expand Down
2 changes: 1 addition & 1 deletion rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ func TestEvents(t *testing.T) {
client := feeder.NewTestClient(t, &utils.Goerli2)
gw := adaptfeeder.New(client)

for i := 0; i < 7; i++ {
for i := range 7 {
b, err := gw.BlockByNumber(context.Background(), uint64(i))
require.NoError(t, err)
s, err := gw.StateUpdate(context.Background(), uint64(i))
Expand Down
1 change: 0 additions & 1 deletion sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ func (s *Synchronizer) verifierTask(ctx context.Context, block *core.Block, stat
}
storeTimer := time.Now()
err = s.blockchain.Store(block, commitments, stateUpdate, newClasses)

if err != nil {
if errors.Is(err, blockchain.ErrParentDoesNotMatchHead) {
// revert the head and restart the sync process, hoping that the reorg is not deep
Expand Down
2 changes: 1 addition & 1 deletion utils/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var levelStrings = map[utils.LogLevel]string{

func TestLogLevelString(t *testing.T) {
for level, str := range levelStrings {
t.Run("level "+str, func(t *testing.T) {
t.Run("level "+str, func(t *testing.T) { //nolint:goconst
assert.Equal(t, str, level.String())
})
}
Expand Down
2 changes: 1 addition & 1 deletion utils/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestNetwork(t *testing.T) {
//nolint:dupl // see comment in utils/log_test.go
func TestNetworkSet(t *testing.T) {
for network, str := range networkStrings {
t.Run("network "+str, func(t *testing.T) {
t.Run("network "+str, func(t *testing.T) { //nolint:goconst
n := new(utils.Network)
require.NoError(t, n.Set(str))
assert.Equal(t, network, *n)
Expand Down
9 changes: 0 additions & 9 deletions utils/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ package utils

import "slices"

func Flatten[T any](sl ...[]T) []T {
var result []T
for _, slice := range sl {
result = append(result, slice...)
}

return result
}

func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2 {
if slice == nil {
return nil
Expand Down
7 changes: 0 additions & 7 deletions utils/slices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestFlatten(t *testing.T) {
expected := []int{1, 2, 3, 4, 5, 6}
halfLen := len(expected) / 2
actual := Flatten(expected[:halfLen], expected[halfLen:])
assert.Equal(t, expected, actual)
}

func TestMap(t *testing.T) {
t.Run("nil slice", func(t *testing.T) {
var input []int
Expand Down
2 changes: 1 addition & 1 deletion vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid
C.free(unsafe.Pointer(chainID))
C.free(unsafe.Pointer(cBlockInfo.version))

if len(context.err) > 0 {
if context.err != "" {
if context.errTxnIndex >= 0 {
return nil, nil, nil, TransactionExecutionError{
Index: uint64(context.errTxnIndex),
Expand Down

0 comments on commit ece0bd6

Please sign in to comment.