diff --git a/les/api.go b/les/api.go index d4f36a8251..a933cbd068 100644 --- a/les/api.go +++ b/les/api.go @@ -83,7 +83,7 @@ type ( // send sends a changed total capacity event to the subscribers func (s tcSubs) send(tc uint64, underrun bool) { - for sub, _ := range s { + for sub := range s { select { case <-sub.rpcSub.Err(): delete(s, sub) diff --git a/les/api_test.go b/les/api_test.go index 7328ff46c6..cec9459625 100644 --- a/les/api_test.go +++ b/les/api_test.go @@ -183,7 +183,7 @@ func testCapacityAPI(t *testing.T, clientCount int) { processedSince := func(start []uint64) []uint64 { res := make([]uint64, len(reqCount)) - for i, _ := range reqCount { + for i := range reqCount { res[i] = atomic.LoadUint64(&reqCount[i]) if start != nil { res[i] -= start[i] @@ -197,7 +197,7 @@ func testCapacityAPI(t *testing.T, clientCount int) { setCapacity(ctx, t, serverRpcClient, clients[freeIdx].ID(), freeCap) freeIdx = rand.Intn(len(clients)) var sum float64 - for i, _ := range clients { + for i := range clients { if i == freeIdx { weights[i] = 0 } else { @@ -220,14 +220,14 @@ func testCapacityAPI(t *testing.T, clientCount int) { } } weights[freeIdx] = float64(freeCap) - for i, _ := range clients { + for i := range clients { weights[i] /= float64(testCap) } time.Sleep(flowcontrol.DecParamDelay) fmt.Println("Starting measurement") fmt.Printf("Relative weights:") - for i, _ := range clients { + for i := range clients { fmt.Printf(" %f", weights[i]) } fmt.Println() @@ -459,7 +459,7 @@ func testSim(t *testing.T, serverCount, clientCount int, serverDir, clientDir [] servers := make([]*simulations.Node, serverCount) clients := make([]*simulations.Node, clientCount) - for i, _ := range clients { + for i := range clients { clientconf := adapters.RandomNodeConfig() clientconf.Services = []string{"lesclient"} if len(clientDir) == clientCount { @@ -472,7 +472,7 @@ func testSim(t *testing.T, serverCount, clientCount int, serverDir, clientDir [] clients[i] = client } - for i, _ := range servers { + for i := range servers { serverconf := adapters.RandomNodeConfig() serverconf.Services = []string{"lesserver"} if len(serverDir) == serverCount { diff --git a/les/benchmark.go b/les/benchmark.go index abf3f13a85..cb302c6ea5 100644 --- a/les/benchmark.go +++ b/les/benchmark.go @@ -64,7 +64,7 @@ func (b *benchmarkBlockHeaders) init(pm *ProtocolManager, count int) error { } if b.byHash { b.hashes = make([]common.Hash, count) - for i, _ := range b.hashes { + for i := range b.hashes { b.hashes[i] = rawdb.ReadCanonicalHash(pm.chainDb, uint64(b.offset+rand.Int63n(b.randMax))) } } @@ -88,7 +88,7 @@ type benchmarkBodiesOrReceipts struct { func (b *benchmarkBodiesOrReceipts) init(pm *ProtocolManager, count int) error { randMax := pm.blockchain.CurrentHeader().Number.Int64() + 1 b.hashes = make([]common.Hash, count) - for i, _ := range b.hashes { + for i := range b.hashes { b.hashes[i] = rawdb.ReadCanonicalHash(pm.chainDb, uint64(rand.Int63n(randMax))) } return nil @@ -117,9 +117,9 @@ func (b *benchmarkProofsOrCode) request(peer *peer, index int) error { key := make([]byte, 32) rand.Read(key) if b.code { - return peer.RequestCode(0, 0, []CodeReq{CodeReq{BHash: b.headHash, AccKey: key}}) + return peer.RequestCode(0, 0, []CodeReq{{BHash: b.headHash, AccKey: key}}) } else { - return peer.RequestProofs(0, 0, []ProofReq{ProofReq{BHash: b.headHash, Key: key}}) + return peer.RequestProofs(0, 0, []ProofReq{{BHash: b.headHash, Key: key}}) } } @@ -149,14 +149,14 @@ func (b *benchmarkHelperTrie) request(peer *peer, index int) error { if b.bloom { bitIdx := uint16(rand.Intn(2048)) - for i, _ := range reqs { + for i := range reqs { key := make([]byte, 10) binary.BigEndian.PutUint16(key[:2], bitIdx) binary.BigEndian.PutUint64(key[2:], uint64(rand.Int63n(int64(b.sectionCount)))) reqs[i] = HelperTrieReq{Type: htBloomBits, TrieIdx: b.sectionCount - 1, Key: key} } } else { - for i, _ := range reqs { + for i := range reqs { key := make([]byte, 8) binary.BigEndian.PutUint64(key[:], uint64(rand.Int63n(int64(b.headNum)))) reqs[i] = HelperTrieReq{Type: htCanonical, TrieIdx: b.sectionCount - 1, Key: key, AuxReq: auxHeader} @@ -177,7 +177,7 @@ func (b *benchmarkTxSend) init(pm *ProtocolManager, count int) error { signer := types.NewEIP155Signer(big.NewInt(18)) b.txs = make(types.Transactions, count) - for i, _ := range b.txs { + for i := range b.txs { data := make([]byte, txSizeCostLimit) rand.Read(data) tx, err := types.SignTx(types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), data), signer, key) @@ -288,7 +288,7 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error { serverPeer.announceType = announceTypeNone serverPeer.fcCosts = make(requestCostTable) c := &requestCosts{} - for code, _ := range requests { + for code := range requests { serverPeer.fcCosts[code] = c } serverPeer.fcParams = flowcontrol.ServerParams{BufLimit: 1, MinRecharge: 1} diff --git a/les/costtracker.go b/les/costtracker.go index 970cfd822c..1893b1c2ba 100644 --- a/les/costtracker.go +++ b/les/costtracker.go @@ -89,7 +89,7 @@ const ( ) // costTracker is responsible for calculating costs and cost estimates on the -// server side. It continously updates the global cost factor which is defined +// server side. It continuously updates the global cost factor which is defined // as the number of cost units per nanosecond of serving time in a single thread. // It is based on statistics collected during serving requests in high-load periods // and practically acts as a one-dimension request price scaling factor over the @@ -127,7 +127,7 @@ func newCostTracker(db ethdb.Database, config *eth.Config) *costTracker { } if makeCostStats { ct.stats = make(map[uint64][]uint64) - for code, _ := range reqAvgTimeCost { + for code := range reqAvgTimeCost { ct.stats[code] = make([]uint64, 10) } } @@ -370,7 +370,7 @@ func (list RequestCostList) decode() requestCostTable { func testCostList() RequestCostList { cl := make(RequestCostList, len(reqAvgTimeCost)) var max uint64 - for code, _ := range reqAvgTimeCost { + for code := range reqAvgTimeCost { if code > max { max = code } diff --git a/les/flowcontrol/manager.go b/les/flowcontrol/manager.go index 8d7d577ab9..532e6a4050 100644 --- a/les/flowcontrol/manager.go +++ b/les/flowcontrol/manager.go @@ -131,7 +131,7 @@ func (cm *ClientManager) SetRechargeCurve(curve PieceWiseLinear) { } // connect should be called when a client is connected, before passing it to any -// other ClientManager funtion +// other ClientManager function func (cm *ClientManager) connect(node *ClientNode) { cm.lock.Lock() defer cm.lock.Unlock() diff --git a/les/flowcontrol/manager_test.go b/les/flowcontrol/manager_test.go index 5a57689eca..4e7746d400 100644 --- a/les/flowcontrol/manager_test.go +++ b/les/flowcontrol/manager_test.go @@ -57,7 +57,7 @@ func testConstantTotalCapacity(t *testing.T, nodeCount, maxCapacityNodes, random clock := &mclock.Simulated{} nodes := make([]*testNode, nodeCount) var totalCapacity uint64 - for i, _ := range nodes { + for i := range nodes { nodes[i] = &testNode{capacity: uint64(50000 + rand.Intn(100000))} totalCapacity += nodes[i].capacity } @@ -67,7 +67,7 @@ func testConstantTotalCapacity(t *testing.T, nodeCount, maxCapacityNodes, random n.node = NewClientNode(m, ServerParams{BufLimit: n.bufLimit, MinRecharge: n.capacity}) } maxNodes := make([]int, maxCapacityNodes) - for i, _ := range maxNodes { + for i := range maxNodes { // we don't care if some indexes are selected multiple times // in that case we have fewer max nodes maxNodes[i] = rand.Intn(nodeCount)