Skip to content

Commit

Permalink
Merge pull request #183 from nspcc-dev/go-1.22
Browse files Browse the repository at this point in the history
Go 1.22
  • Loading branch information
AnnaShaleva authored Aug 22, 2024
2 parents 47712fb + 7fe42f2 commit 9224595
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .docker/build/Dockerfile.bench
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder layer
FROM golang:1.22-alpine as builder
FROM golang:1.23-alpine as builder

WORKDIR /bench

Expand Down
2 changes: 1 addition & 1 deletion .docker/build/Dockerfile.golang
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder layer
FROM golang:1.22-alpine as builder
FROM golang:1.23-alpine as builder

WORKDIR /neo-go

Expand Down
6 changes: 2 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: tab
formats:
- format: tab

# all available settings of specific linters
linters-settings:
Expand All @@ -21,9 +22,6 @@ linters-settings:
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: true
govet:
# report about shadowed variables
check-shadowing: false

linters:
enable:
Expand Down
2 changes: 1 addition & 1 deletion cmd/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func main() {
log.Println("Waiting for an empty block to be processed")
startBlockIndex := blk.Index
// 10*msPerBlock attempts (need some more time for mixed consensus)
for attempt := 0; attempt < 40; attempt++ {
for range 40 {
blk, err = client.GetLastBlock(ctx)
if err != nil {
log.Fatalf("could not fetch last block: %v", err)
Expand Down
21 changes: 16 additions & 5 deletions cmd/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"strings"
"time"

"github.com/k14s/ytt/pkg/cmd/template"
"carvel.dev/ytt/pkg/cmd/template"
"carvel.dev/ytt/pkg/cmd/ui"
"carvel.dev/ytt/pkg/files"
"github.com/nspcc-dev/neo-go/pkg/config"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -90,13 +92,22 @@ func main() {
func convertTemplateToPlain(templatePath string, tempDir string, nodeCount int) error {
filePath := configPath + templatePath
dataPath := configPath + templateDataFile
cmd := template.NewCmd(template.NewOptions())
cmd.SetArgs([]string{"-f", filePath, "-f", dataPath, "--output-files", tempDir,
"--data-value-yaml", "validators_count=" + strconv.FormatInt(int64(nodeCount), 10)})
err := cmd.Execute()
opts := template.NewOptions()
opts.DataValuesFlags.KVsFromYAML = []string{"validators_count=" + strconv.FormatInt(int64(nodeCount), 10)}
inFiles, err := files.NewSortedFilesFromPaths([]string{filePath, dataPath}, files.SymlinkAllowOpts{})
if err != nil {
return err
}
out := opts.RunWithFiles(template.Input{Files: inFiles}, ui.NewTTY(false))
if out.Err != nil {
return out.Err
}
for _, f := range out.Files {
err = f.Create(tempDir)
if err != nil {
return err
}
}
return nil
}

Expand Down
10 changes: 3 additions & 7 deletions cmd/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/nspcc-dev/neo-bench

go 1.21
go 1.22

require (
carvel.dev/ytt v0.49.1
github.com/Workiva/go-datastructures v1.1.5
github.com/docker/docker v26.1.5+incompatible
github.com/fatih/color v1.17.0
github.com/k14s/ytt v0.30.0
github.com/moby/moby v26.1.5+incompatible
github.com/nspcc-dev/neo-go v0.106.3
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240820093251-dfd4566a04a9
Expand Down Expand Up @@ -38,11 +38,10 @@ require (
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -73,7 +72,6 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
github.com/twmb/murmur3 v1.1.8 // indirect
Expand All @@ -98,5 +96,3 @@ require (
gotest.tools/v3 v3.0.3 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/pkg/errors v0.8.1 => github.com/pkg/errors v0.9.1 // see https://github.com/containerd/containerd/issues/4703#issuecomment-736542317
147 changes: 11 additions & 136 deletions cmd/go.sum

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions cmd/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"fmt"
"log"
"math/rand"
"math/rand/v2"
"strings"
"sync/atomic"
"time"
Expand Down Expand Up @@ -58,15 +58,14 @@ func NewRPCClient(v *viper.Viper, maxConnsPerHost int) *RPCClient {
addresses = append(addresses, "http://"+addr)
}

buf := make([]byte, 8)
buf := make([]byte, 16)
if _, err := crand.Read(buf); err != nil {
log.Fatal("could not initialize randomizer for round robin")
}

src := binary.BigEndian.Uint64(buf)
rand.NewSource(int64(src))
pcg := rand.New(rand.NewPCG(binary.BigEndian.Uint64(buf[:8]), binary.BigEndian.Uint64(buf[8:])))

rand.Shuffle(len(addresses), func(i, j int) {
pcg.Shuffle(len(addresses), func(i, j int) {
addresses[i], addresses[j] = addresses[j], addresses[i]
})

Expand Down Expand Up @@ -97,7 +96,7 @@ func NewRPCClient(v *viper.Viper, maxConnsPerHost int) *RPCClient {

timeout: timeout,
}
c.inc.Store(rand.Int31())
c.inc.Store(pcg.Int32())
return c
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func Generate(ctx context.Context, opts BenchOptions, callback ...GenerateCallba

var wg sync.WaitGroup
wg.Add(genWorkerCount)
for i := 0; i < genWorkerCount; i++ {
for i := range genWorkerCount {
go func(i int) {
defer wg.Done()
genTxWorker(i, txCh[i], result[i])
Expand Down Expand Up @@ -152,7 +152,7 @@ func Generate(ctx context.Context, opts BenchOptions, callback ...GenerateCallba

finishCh := make(chan struct{})
go func() {
for i := 0; i < count; i++ {
for i := range count {
if ctx.Err() != nil {
log.Fatal(ctx.Err())
}
Expand All @@ -165,7 +165,7 @@ func Generate(ctx context.Context, opts BenchOptions, callback ...GenerateCallba
close(finishCh)
}()

for i := 0; i < count; i++ {
for i := range count {
r := <-result[i%len(result)]

err := dump.TransactionsQueue.Put(r.blob)
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func fillChain(ctx context.Context, c *rpcclient.Client, proto result.Protocol,
neoC := neo.NewReader(inv)
gasC := gas.NewReader(inv)
fs := make([]func() (bool, error), 0, len(opts.Senders)*2)
for i := 0; i < len(opts.Senders); i++ {
for i := range opts.Senders {
addr := opts.Senders[i].GetScriptHash()
fs = append(fs,
func() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ReadDump(from string) *Dump {

start := time.Now()
log.Printf("Read %d txs from %s", count, in.Name())
for i := uint64(0); i < count; i++ {
for i := range count {
_ = rd.ReadString() // hash
blob := rd.ReadString() // blob

Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (d *doer) Sender(ctx context.Context) {

start := time.Now()

for i := 0; i < d.wrkCount; i++ {
for range d.wrkCount {
go d.worker(ctx, idx, start)
}

Expand Down

0 comments on commit 9224595

Please sign in to comment.