diff --git a/core/block_test.go b/core/block_test.go index 81cac95e5b..55a09fd171 100644 --- a/core/block_test.go +++ b/core/block_test.go @@ -171,8 +171,7 @@ func TestBlockHash(t *testing.T) { }, } - for _, testcase := range tests { - tc := testcase + for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() client := feeder.NewTestClient(t, &tc.chain) diff --git a/core/state.go b/core/state.go index 96b5c3548a..1518ca49ce 100644 --- a/core/state.go +++ b/core/state.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "runtime" + "slices" "sort" "github.com/NethermindEth/juno/core/crypto" @@ -400,9 +401,7 @@ func (s *State) updateContractStorages(stateTrie *trie.Trie, diffs map[felt.Felt for key := range diffs { keys = append(keys, key) } - sort.SliceStable(keys, func(i, j int) bool { - return len(diffs[keys[i]]) > len(diffs[keys[j]]) - }) + slices.SortStableFunc(keys, func(a, b felt.Felt) int { return len(diffs[a]) - len(diffs[b]) }) // update per-contract storage Tries concurrently contractUpdaters := pool.NewWithResults[*bufferedTransactionWithAddress]().WithErrors().WithMaxGoroutines(runtime.GOMAXPROCS(0)) diff --git a/core/transaction.go b/core/transaction.go index 194a7b9ae7..5ab0a9cd9b 100644 --- a/core/transaction.go +++ b/core/transaction.go @@ -570,8 +570,7 @@ func l1HandlerTransactionHash(l *L1HandlerTransaction, n *utils.Network) (*felt. } func deployAccountTransactionHash(d *DeployAccountTransaction, n *utils.Network) (*felt.Felt, error) { - callData := []*felt.Felt{d.ClassHash, d.ContractAddressSalt} - callData = append(callData, d.ConstructorCallData...) + callData := append([]*felt.Felt{d.ClassHash, d.ContractAddressSalt}, d.ConstructorCallData...) // There is no version 0 for deploy account switch { case d.Version.Is(1): diff --git a/db/pebble/iterator.go b/db/pebble/iterator.go index e28f83197f..471b186fdb 100644 --- a/db/pebble/iterator.go +++ b/db/pebble/iterator.go @@ -1,6 +1,8 @@ package pebble import ( + "slices" + "github.com/NethermindEth/juno/db" "github.com/cockroachdb/pebble" ) @@ -23,8 +25,7 @@ func (i *iterator) Key() []byte { if key == nil { return nil } - buf := make([]byte, len(key)) - copy(buf, key) + buf := slices.Clone(key) return buf } @@ -34,8 +35,7 @@ func (i *iterator) Value() ([]byte, error) { if err != nil || val == nil { return nil, err } - buf := make([]byte, len(val)) - copy(buf, val) + buf := slices.Clone(val) return buf, nil } diff --git a/l1/l1_pkg_test.go b/l1/l1_pkg_test.go index 4e377cce12..eefa2e3aa1 100644 --- a/l1/l1_pkg_test.go +++ b/l1/l1_pkg_test.go @@ -330,7 +330,6 @@ func TestClient(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.description, func(t *testing.T) { t.Parallel() diff --git a/rpc/block_test.go b/rpc/block_test.go index f778ac7350..d7a02e348b 100644 --- a/rpc/block_test.go +++ b/rpc/block_test.go @@ -52,7 +52,6 @@ func TestBlockId(t *testing.T) { }, } for name, test := range tests { - test := test t.Run(name, func(t *testing.T) { t.Parallel() var blockID rpc.BlockID @@ -81,7 +80,6 @@ func TestBlockId(t *testing.T) { }, } for name, test := range failingTests { - test := test t.Run(name, func(t *testing.T) { t.Parallel() var blockID rpc.BlockID diff --git a/sync/sync.go b/sync/sync.go index 99f3d3dd2b..a2e4ac0bf0 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -298,11 +298,7 @@ func (s *Synchronizer) syncBlocks(syncCtx context.Context) { } func maxWorkers() int { - m, mProcs := 16, runtime.GOMAXPROCS(0) - if mProcs > m { - return m - } - return mProcs + return min(16, runtime.GOMAXPROCS(0)) //nolint:mnd } func (s *Synchronizer) setupWorkers() (*stream.Stream, *stream.Stream) { diff --git a/upgrader/upgrader_test.go b/upgrader/upgrader_test.go index 213eed0b5e..f2893f2781 100644 --- a/upgrader/upgrader_test.go +++ b/upgrader/upgrader_test.go @@ -102,7 +102,6 @@ func TestUpgrader(t *testing.T) { } for description, test := range tests { - test := test t.Run(description, func(t *testing.T) { t.Parallel() srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { diff --git a/vm/vm.go b/vm/vm.go index ba952ee1f7..a55d3e297c 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -344,7 +344,7 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid } func marshalTxnsAndDeclaredClasses(txns []core.Transaction, declaredClasses []core.Class) (json.RawMessage, json.RawMessage, error) { //nolint:lll - txnJSONs := []json.RawMessage{} + txnJSONs := make([]json.RawMessage, 0, len(txns)) for _, txn := range txns { txnJSON, err := marshalTxn(txn) if err != nil { @@ -353,7 +353,7 @@ func marshalTxnsAndDeclaredClasses(txns []core.Transaction, declaredClasses []co txnJSONs = append(txnJSONs, txnJSON) } - classJSONs := []json.RawMessage{} + classJSONs := make([]json.RawMessage, 0, len(declaredClasses)) for _, declaredClass := range declaredClasses { declaredClassJSON, cErr := marshalClassInfo(declaredClass) if cErr != nil {