Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/bee/cmd/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDBExportImport(t *testing.T) {

chunks := make(map[string]int)
nChunks := 10
for i := 0; i < nChunks; i++ {
for range nChunks {
ch := storagetest.GenerateTestRandomChunk()
err := db1.ReservePutter().Put(ctx, ch)
if err != nil {
Expand Down Expand Up @@ -101,13 +101,13 @@ func TestDBExportImportPinning(t *testing.T) {
pins := make(map[string]any)
nChunks := 10

for i := 0; i < 2; i++ {
for range 2 {
rootAddr := swarm.RandAddress(t)
collection, err := db1.NewCollection(ctx)
if err != nil {
t.Fatal(err)
}
for j := 0; j < nChunks; j++ {
for range nChunks {
ch := storagetest.GenerateTestRandomChunk()
err = collection.Put(ctx, ch)
if err != nil {
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestDBNuke_FLAKY(t *testing.T) {
}, dataDir)

nChunks := 10
for i := 0; i < nChunks; i++ {
for range nChunks {
ch := storagetest.GenerateTestRandomChunk()
err := db.ReservePutter().Put(ctx, ch)
if err != nil {
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestDBInfo(t *testing.T) {
}, dir1)

nChunks := 10
for i := 0; i < nChunks; i++ {
for range nChunks {
ch := storagetest.GenerateTestRandomChunk()
err := db1.ReservePutter().Put(ctx, ch)
if err != nil {
Expand Down
20 changes: 4 additions & 16 deletions pkg/accounting/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ func (a *Accounting) PrepareCredit(ctx context.Context, peer swarm.Address, pric
}
}

timeElapsedInSeconds := (a.timeNow().UnixMilli() - accountingPeer.refreshTimestampMilliseconds) / 1000
if timeElapsedInSeconds > 1 {
timeElapsedInSeconds = 1
}
timeElapsedInSeconds := min((a.timeNow().UnixMilli()-accountingPeer.refreshTimestampMilliseconds)/1000, 1)

refreshDue := new(big.Int).Mul(big.NewInt(timeElapsedInSeconds), a.refreshRate)
overdraftLimit := new(big.Int).Add(accountingPeer.paymentThreshold, refreshDue)
Expand Down Expand Up @@ -745,10 +742,7 @@ func (a *Accounting) PeerAccounting() (map[string]PeerInfo, error) {

t := a.timeNow()

timeElapsedInSeconds := t.Unix() - accountingPeer.refreshReceivedTimestamp
if timeElapsedInSeconds > 1 {
timeElapsedInSeconds = 1
}
timeElapsedInSeconds := min(t.Unix()-accountingPeer.refreshReceivedTimestamp, 1)

// get appropriate refresh rate
refreshRate := new(big.Int).Set(a.refreshRate)
Expand All @@ -759,10 +753,7 @@ func (a *Accounting) PeerAccounting() (map[string]PeerInfo, error) {
refreshDue := new(big.Int).Mul(big.NewInt(timeElapsedInSeconds), refreshRate)
currentThresholdGiven := new(big.Int).Add(accountingPeer.disconnectLimit, refreshDue)

timeElapsedInSeconds = (t.UnixMilli() - accountingPeer.refreshTimestampMilliseconds) / 1000
if timeElapsedInSeconds > 1 {
timeElapsedInSeconds = 1
}
timeElapsedInSeconds = min((t.UnixMilli()-accountingPeer.refreshTimestampMilliseconds)/1000, 1)

// get appropriate refresh rate
refreshDue = new(big.Int).Mul(big.NewInt(timeElapsedInSeconds), a.refreshRate)
Expand Down Expand Up @@ -1352,10 +1343,7 @@ func (d *debitAction) Apply() error {
a.metrics.TotalDebitedAmount.Add(tot)
a.metrics.DebitEventsCount.Inc()

timeElapsedInSeconds := a.timeNow().Unix() - d.accountingPeer.refreshReceivedTimestamp
if timeElapsedInSeconds > 1 {
timeElapsedInSeconds = 1
}
timeElapsedInSeconds := min(a.timeNow().Unix()-d.accountingPeer.refreshReceivedTimestamp, 1)

// get appropriate refresh rate
refreshRate := new(big.Int).Set(a.refreshRate)
Expand Down
10 changes: 5 additions & 5 deletions pkg/accounting/accounting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ func TestAccountingCallPaymentErrorRetries(t *testing.T) {
acc.NotifyPaymentSent(peer1Addr, sentAmount, errors.New("error"))

// try another n requests 1 per second
for i := 0; i < 10; i++ {
for range 10 {
ts++
acc.SetTime(ts)

Expand Down Expand Up @@ -1857,8 +1857,8 @@ func testAccountingSettlementGrowingThresholds(t *testing.T, settleFunc func(t *
checkPaymentThreshold := new(big.Int).Set(testPayThreshold)

// Simulate first 18 threshold upgrades
for j := 0; j < 18; j++ {
for i := 0; i < 100; i++ {
for range 18 {
for range 100 {

// expect no change in threshold while less than 100 seconds worth of refreshment rate was settled
settleFunc(t, acc, peer1Addr, testGrowth-1)
Expand Down Expand Up @@ -1891,7 +1891,7 @@ func testAccountingSettlementGrowingThresholds(t *testing.T, settleFunc func(t *

// Expect no increase for the next 179 seconds of refreshment

for k := 0; k < 1799; k++ {
for range 1799 {

settleFunc(t, acc, peer1Addr, testGrowth)

Expand All @@ -1917,7 +1917,7 @@ func testAccountingSettlementGrowingThresholds(t *testing.T, settleFunc func(t *

// Expect no increase for another 3599 seconds of refreshments

for k := 0; k < 3599; k++ {
for range 3599 {

settleFunc(t, acc, peer1Addr, testGrowth)

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func (s *Service) checkOrigin(r *http.Request) bool {
// validationError is a custom error type for validation errors.
type validationError struct {
Entry string
Value interface{}
Value any
Cause error
}

Expand All @@ -636,7 +636,7 @@ func (e *validationError) Error() string {
// mapStructure maps the input into output struct and validates the output.
// It's a helper method for the handlers, which reduces the chattiness
// of the code.
func (s *Service) mapStructure(input, output interface{}) func(string, log.Logger, http.ResponseWriter) {
func (s *Service) mapStructure(input, output any) func(string, log.Logger, http.ResponseWriter) {
// response unifies the response format for parsing and validation errors.
response := func(err error) func(string, log.Logger, http.ResponseWriter) {
return func(msg string, logger log.Logger, w http.ResponseWriter) {
Expand Down
11 changes: 4 additions & 7 deletions pkg/api/bzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ func TestBzzUploadDownloadWithRedundancy_FLAKY(t *testing.T) {
store.Record()
defer store.Unrecord()
// we intend to forget as many chunks as possible for the given redundancy level
forget := parityCnt
if parityCnt > shardCnt {
forget = shardCnt
}
forget := min(parityCnt, shardCnt)
if levels == 1 {
forget = 2
}
Expand Down Expand Up @@ -141,7 +138,7 @@ func TestBzzUploadDownloadWithRedundancy_FLAKY(t *testing.T) {
if len(got) != len(want) {
t.Fatalf("got %v parts, want %v parts", len(got), len(want))
}
for i := 0; i < len(want); i++ {
for i := range want {
if !bytes.Equal(got[i], want[i]) {
t.Errorf("part %v: got %q, want %q", i, string(got[i]), string(want[i]))
}
Expand Down Expand Up @@ -670,7 +667,7 @@ func TestBzzFilesRangeRequests(t *testing.T) {
if len(got) != len(want) {
t.Fatalf("got %v parts, want %v parts", len(got), len(want))
}
for i := 0; i < len(want); i++ {
for i := range want {
if !bytes.Equal(got[i], want[i]) {
t.Errorf("part %v: got %q, want %q", i, string(got[i]), string(want[i]))
}
Expand All @@ -681,7 +678,7 @@ func TestBzzFilesRangeRequests(t *testing.T) {
}
}

func createRangeHeader(data interface{}, ranges [][2]int) (header string, parts [][]byte) {
func createRangeHeader(data any, ranges [][2]int) (header string, parts [][]byte) {
getLen := func() int {
switch data := data.(type) {
case []byte:
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/chunk_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestChunkUploadStream(t *testing.T) {

t.Run("upload and verify", func(t *testing.T) {
chsToGet := []swarm.Chunk{}
for i := 0; i < 5; i++ {
for range 5 {
ch := testingc.GenerateTestRandomChunk()

err := wsConn.SetWriteDeadline(time.Now().Add(time.Second))
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var ErrHexLength = errHexLength

type HexInvalidByteError = hexInvalidByteError

func MapStructure(input, output interface{}, hooks map[string]func(v string) (string, error)) error {
func MapStructure(input, output any, hooks map[string]func(v string) (string, error)) error {
return mapStructure(input, output, hooks)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func TestGetLoggers(t *testing.T) {
}
api.ReplaceLogRegistryIterateFn(fn)

have := make(map[string]interface{})
want := make(map[string]interface{})
have := make(map[string]any)
want := make(map[string]any)
data := `{"loggers":[{"id":"b25lWzBdW10-PjgyNDYzNDg2MDM2MA==","logger":"one","subsystem":"one[0][]\u003e\u003e824634860360","verbosity":"all"},{"id":"b25lL25hbWVbMF1bXT4-ODI0NjM0ODYwMzYw","logger":"one/name","subsystem":"one/name[0][]\u003e\u003e824634860360","verbosity":"warning"},{"id":"b25lL25hbWVbMF1bXCJ2YWxcIj0xXT4-ODI0NjM0ODYwMzYw","logger":"one/name","subsystem":"one/name[0][\\\"val\\\"=1]\u003e\u003e824634860360","verbosity":"warning"},{"id":"b25lL25hbWVbMV1bXT4-ODI0NjM0ODYwMzYw","logger":"one/name","subsystem":"one/name[1][]\u003e\u003e824634860360","verbosity":"info"},{"id":"b25lL25hbWVbMl1bXT4-ODI0NjM0ODYwMzYw","logger":"one/name","subsystem":"one/name[2][]\u003e\u003e824634860360","verbosity":"info"}],"tree":{"one":{"+":["all|one[0][]\u003e\u003e824634860360"],"/":{"name":{"+":["warning|one/name[0][]\u003e\u003e824634860360","warning|one/name[0][\\\"val\\\"=1]\u003e\u003e824634860360","info|one/name[1][]\u003e\u003e824634860360","info|one/name[2][]\u003e\u003e824634860360"]}}}}}`
if err := json.Unmarshal([]byte(data), &want); err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/postage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func TestPostageAccessHandler(t *testing.T) {
method string
url string
respCode int
resp interface{}
resp any
}

success := []operation{
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

type tagRequest struct {
Address swarm.Address `json:"address,omitempty"`
Address swarm.Address `json:"address"`
}

type tagResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var flattenErrorsFormat = func(es []error) string {
//
// In case of parsing error, a new parseError is returned to the caller.
// The caller can use the Unwrap method to get the original error.
func mapStructure(input, output interface{}, hooks map[string]func(v string) (string, error)) (err error) {
func mapStructure(input, output any, hooks map[string]func(v string) (string, error)) (err error) {
if input == nil || output == nil {
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/api/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func TestMapStructure(t *testing.T) {

tests := []struct {
name string
src interface{}
want interface{}
src any
want any
wantErr error
}{{
name: "bool zero value",
Expand Down Expand Up @@ -520,7 +520,7 @@ func TestMapStructure_InputOutputSanityCheck(t *testing.T) {
t.Run("input is nil", func(t *testing.T) {
t.Parallel()

var input interface{}
var input any
err := api.MapStructure(input, struct{}{}, nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -541,7 +541,7 @@ func TestMapStructure_InputOutputSanityCheck(t *testing.T) {
t.Parallel()

var (
input = map[string]interface{}{"someVal": "123"}
input = map[string]any{"someVal": "123"}
output struct {
SomeVal string `map:"someVal"`
}
Expand All @@ -556,8 +556,8 @@ func TestMapStructure_InputOutputSanityCheck(t *testing.T) {
t.Parallel()

var (
input = map[string]interface{}{"someVal": "123"}
output interface{}
input = map[string]any{"someVal": "123"}
output any
)
err := api.MapStructure(&input, output, nil)
if err != nil {
Expand All @@ -569,7 +569,7 @@ func TestMapStructure_InputOutputSanityCheck(t *testing.T) {
t.Parallel()

var (
input = map[string]interface{}{"someVal": "123"}
input = map[string]any{"someVal": "123"}
output = struct {
SomeVal string `map:"someVal"`
}{}
Expand All @@ -584,7 +584,7 @@ func TestMapStructure_InputOutputSanityCheck(t *testing.T) {
t.Parallel()

var (
input = map[string]interface{}{"someVal": "123"}
input = map[string]any{"someVal": "123"}
output = "foo"
)
err := api.MapStructure(&input, &output, nil)
Expand Down
6 changes: 3 additions & 3 deletions pkg/bitvector/bitvector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestBitvectorGetSet(t *testing.T) {
t.Errorf("error for length %v: %v", length, err)
}

for i := 0; i < length; i++ {
for i := range length {
if bv.Get(i) {
t.Errorf("expected false for element on index %v", i)
}
Expand All @@ -79,9 +79,9 @@ func TestBitvectorGetSet(t *testing.T) {
bv.Get(length + 8)
}()

for i := 0; i < length; i++ {
for i := range length {
bv.Set(i)
for j := 0; j < length; j++ {
for j := range length {
if j == i {
if !bv.Get(j) {
t.Errorf("element on index %v is not set to true", i)
Expand Down
12 changes: 4 additions & 8 deletions pkg/blocker/blocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ func New(blocklister p2p.Blocklister, flagTimeout, blockDuration, wakeUpTime tim
blocklistCallback: callback,
}

b.closeWg.Add(1)
go func() {
defer b.closeWg.Done()
b.closeWg.Go(func() {
for {
select {
case <-b.quit:
Expand All @@ -74,11 +72,9 @@ func New(blocklister p2p.Blocklister, flagTimeout, blockDuration, wakeUpTime tim
}
}
}
}()
})

b.closeWg.Add(1)
go func() {
defer b.closeWg.Done()
b.closeWg.Go(func() {
for {
select {
case <-time.After(wakeUpTime):
Expand All @@ -87,7 +83,7 @@ func New(blocklister p2p.Blocklister, flagTimeout, blockDuration, wakeUpTime tim
return
}
}
}()
})

return b
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/bmt/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func benchmarkBMTBaseline(b *testing.B, _ int) {

for b.Loop() {
eg := new(errgroup.Group)
for j := 0; j < testSegmentCount; j++ {
for range testSegmentCount {
eg.Go(func() error {
_, err := bmt.Sha3hash(testData[:hashSize])
return err
Expand Down Expand Up @@ -113,7 +113,7 @@ func benchmarkPool(b *testing.B, poolsize int) {

for b.Loop() {
eg := new(errgroup.Group)
for j := 0; j < cycles; j++ {
for range cycles {
eg.Go(func() error {
h := pool.Get()
defer pool.Put(h)
Expand Down
Loading
Loading