From 9619a610248e9630968ba1d9be8e214b645c9c55 Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Wed, 8 Nov 2017 11:45:52 +0100 Subject: [PATCH] all: gofmt -w -s (#15419) --- accounts/abi/bind/bind_test.go | 2 +- accounts/abi/unpack_test.go | 2 +- cmd/faucet/website.go | 4 ++-- core/bloombits/matcher_test.go | 16 +++++++------- core/bloombits/scheduler_test.go | 2 +- core/genesis.go | 18 +++++++-------- core/tx_pool.go | 4 ++-- core/tx_pool_test.go | 2 +- eth/filters/bench_test.go | 2 +- les/bloombits.go | 2 +- les/distributor.go | 2 +- les/distributor_test.go | 2 +- les/odr.go | 18 +++++++-------- rpc/subscription_test.go | 2 +- swarm/api/client/client_test.go | 38 ++++++++++++++++---------------- swarm/storage/chunker.go | 15 +++++-------- swarm/storage/pyramid.go | 4 ++-- tests/init.go | 18 +++++++-------- tests/state_test_util.go | 2 +- 19 files changed, 76 insertions(+), 79 deletions(-) diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/bind/bind_test.go index 17b221642..43ed53b92 100644 --- a/accounts/abi/bind/bind_test.go +++ b/accounts/abi/bind/bind_test.go @@ -472,7 +472,7 @@ func TestBindings(t *testing.T) { t.Fatalf("failed to create temporary workspace: %v", err) } defer os.RemoveAll(ws) - + pkg := filepath.Join(ws, "bindtest") if err = os.MkdirAll(pkg, 0700); err != nil { t.Fatalf("failed to create package: %v", err) diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index 9c7c339f3..294908378 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -365,7 +365,7 @@ func TestUnmarshal(t *testing.T) { buff.Write(common.Hex2Bytes("0102000000000000000000000000000000000000000000000000000000000000")) err = abi.Unpack(&mixedBytes, "mixedBytes", buff.Bytes()) - if err !=nil { + if err != nil { t.Error(err) } else { if bytes.Compare(p0, p0Exp) != 0 { diff --git a/cmd/faucet/website.go b/cmd/faucet/website.go index eeb8e410e..6a99f8c6f 100644 --- a/cmd/faucet/website.go +++ b/cmd/faucet/website.go @@ -182,8 +182,9 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ - "faucet.html": &bintree{faucetHtml, map[string]*bintree{}}, + "faucet.html": {faucetHtml, map[string]*bintree{}}, }} // RestoreAsset restores an asset under the given directory @@ -232,4 +233,3 @@ func _filePath(dir, name string) string { cannonicalName := strings.Replace(name, "\\", "/", -1) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } - diff --git a/core/bloombits/matcher_test.go b/core/bloombits/matcher_test.go index 0d8544136..4a31854c5 100644 --- a/core/bloombits/matcher_test.go +++ b/core/bloombits/matcher_test.go @@ -31,14 +31,14 @@ const testSectionSize = 4096 // Tests that wildcard filter rules (nil) can be specified and are handled well. func TestMatcherWildcards(t *testing.T) { matcher := NewMatcher(testSectionSize, [][][]byte{ - [][]byte{common.Address{}.Bytes(), common.Address{0x01}.Bytes()}, // Default address is not a wildcard - [][]byte{common.Hash{}.Bytes(), common.Hash{0x01}.Bytes()}, // Default hash is not a wildcard - [][]byte{common.Hash{0x01}.Bytes()}, // Plain rule, sanity check - [][]byte{common.Hash{0x01}.Bytes(), nil}, // Wildcard suffix, drop rule - [][]byte{nil, common.Hash{0x01}.Bytes()}, // Wildcard prefix, drop rule - [][]byte{nil, nil}, // Wildcard combo, drop rule - [][]byte{}, // Inited wildcard rule, drop rule - nil, // Proper wildcard rule, drop rule + {common.Address{}.Bytes(), common.Address{0x01}.Bytes()}, // Default address is not a wildcard + {common.Hash{}.Bytes(), common.Hash{0x01}.Bytes()}, // Default hash is not a wildcard + {common.Hash{0x01}.Bytes()}, // Plain rule, sanity check + {common.Hash{0x01}.Bytes(), nil}, // Wildcard suffix, drop rule + {nil, common.Hash{0x01}.Bytes()}, // Wildcard prefix, drop rule + {nil, nil}, // Wildcard combo, drop rule + {}, // Inited wildcard rule, drop rule + nil, // Proper wildcard rule, drop rule }) if len(matcher.filters) != 3 { t.Fatalf("filter system size mismatch: have %d, want %d", len(matcher.filters), 3) diff --git a/core/bloombits/scheduler_test.go b/core/bloombits/scheduler_test.go index 8a159c237..70772e4ab 100644 --- a/core/bloombits/scheduler_test.go +++ b/core/bloombits/scheduler_test.go @@ -60,7 +60,7 @@ func testScheduler(t *testing.T, clients int, fetchers int, requests int) { req.section, // Requested data req.section, // Duplicated data (ensure it doesn't double close anything) }, [][]byte{ - []byte{}, + {}, new(big.Int).SetUint64(req.section).Bytes(), new(big.Int).SetUint64(req.section).Bytes(), }) diff --git a/core/genesis.go b/core/genesis.go index 26b1c9f63..df491ce0f 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -356,15 +356,15 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { GasLimit: 6283185, Difficulty: big.NewInt(1), Alloc: map[common.Address]GenesisAccount{ - common.BytesToAddress([]byte{1}): GenesisAccount{Balance: big.NewInt(1)}, // ECRecover - common.BytesToAddress([]byte{2}): GenesisAccount{Balance: big.NewInt(1)}, // SHA256 - common.BytesToAddress([]byte{3}): GenesisAccount{Balance: big.NewInt(1)}, // RIPEMD - common.BytesToAddress([]byte{4}): GenesisAccount{Balance: big.NewInt(1)}, // Identity - common.BytesToAddress([]byte{5}): GenesisAccount{Balance: big.NewInt(1)}, // ModExp - common.BytesToAddress([]byte{6}): GenesisAccount{Balance: big.NewInt(1)}, // ECAdd - common.BytesToAddress([]byte{7}): GenesisAccount{Balance: big.NewInt(1)}, // ECScalarMul - common.BytesToAddress([]byte{8}): GenesisAccount{Balance: big.NewInt(1)}, // ECPairing - faucet: GenesisAccount{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, + common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover + common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256 + common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD + common.BytesToAddress([]byte{4}): {Balance: big.NewInt(1)}, // Identity + common.BytesToAddress([]byte{5}): {Balance: big.NewInt(1)}, // ModExp + common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd + common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul + common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing + faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, }, } } diff --git a/core/tx_pool.go b/core/tx_pool.go index 0f008ddc0..c3915575b 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -820,7 +820,7 @@ func (pool *TxPool) addTxsLocked(txs []*types.Transaction, local bool) []error { // Only reprocess the internal state if something was actually added if len(dirty) > 0 { addrs := make([]common.Address, 0, len(dirty)) - for addr, _ := range dirty { + for addr := range dirty { addrs = append(addrs, addr) } pool.promoteExecutables(addrs) @@ -907,7 +907,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) { // Gather all the accounts potentially needing updates if accounts == nil { accounts = make([]common.Address, 0, len(pool.queue)) - for addr, _ := range pool.queue { + for addr := range pool.queue { accounts = append(accounts, addr) } } diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 737ea4cd3..e9ecbb933 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -105,7 +105,7 @@ func validateTxPoolInternals(pool *TxPool) error { for addr, txs := range pool.pending { // Find the last transaction var last uint64 - for nonce, _ := range txs.txs.items { + for nonce := range txs.txs.items { if last < nonce { last = nonce } diff --git a/eth/filters/bench_test.go b/eth/filters/bench_test.go index abbf4593e..0a0929bc1 100644 --- a/eth/filters/bench_test.go +++ b/eth/filters/bench_test.go @@ -192,7 +192,7 @@ func BenchmarkNoBloomBits(b *testing.B) { start := time.Now() mux := new(event.TypeMux) backend := &testBackend{mux, db, 0, new(event.Feed), new(event.Feed), new(event.Feed), new(event.Feed)} - filter := New(backend, 0, int64(headNum), []common.Address{common.Address{}}, nil) + filter := New(backend, 0, int64(headNum), []common.Address{{}}, nil) filter.Logs(context.Background()) d := time.Since(start) fmt.Println("Finished running filter benchmarks") diff --git a/les/bloombits.go b/les/bloombits.go index dff83d349..de233d751 100644 --- a/les/bloombits.go +++ b/les/bloombits.go @@ -56,7 +56,7 @@ func (eth *LightEthereum) startBloomHandlers() { task.Bitsets = make([][]byte, len(task.Sections)) compVectors, err := light.GetBloomBits(task.Context, eth.odr, task.Bit, task.Sections) if err == nil { - for i, _ := range task.Sections { + for i := range task.Sections { if blob, err := bitutil.DecompressBytes(compVectors[i], int(light.BloomTrieFrequency/8)); err == nil { task.Bitsets[i] = blob } else { diff --git a/les/distributor.go b/les/distributor.go index e8ef5b02e..159fa4c73 100644 --- a/les/distributor.go +++ b/les/distributor.go @@ -191,7 +191,7 @@ func (d *requestDistributor) nextRequest() (distPeer, *distReq, time.Duration) { for (len(d.peers) > 0 || elem == d.reqQueue.Front()) && elem != nil { req := elem.Value.(*distReq) canSend := false - for peer, _ := range d.peers { + for peer := range d.peers { if _, ok := checkedPeers[peer]; !ok && peer.canQueue() && req.canSend(peer) { canSend = true cost := req.getCost(peer) diff --git a/les/distributor_test.go b/les/distributor_test.go index 4e7f8bd29..55defb69b 100644 --- a/les/distributor_test.go +++ b/les/distributor_test.go @@ -124,7 +124,7 @@ func testRequestDistributor(t *testing.T, resend bool) { dist := newRequestDistributor(nil, stop) var peers [testDistPeerCount]*testDistPeer - for i, _ := range peers { + for i := range peers { peers[i] = &testDistPeer{} go peers[i].worker(t, !resend, stop) dist.registerTestPeer(peers[i]) diff --git a/les/odr.go b/les/odr.go index 986630dbf..f8412aaad 100644 --- a/les/odr.go +++ b/les/odr.go @@ -27,20 +27,20 @@ import ( // LesOdr implements light.OdrBackend type LesOdr struct { - db ethdb.Database + db ethdb.Database chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer - retriever *retrieveManager - stop chan struct{} + retriever *retrieveManager + stop chan struct{} } func NewLesOdr(db ethdb.Database, chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer, retriever *retrieveManager) *LesOdr { return &LesOdr{ - db: db, - chtIndexer: chtIndexer, - bloomTrieIndexer: bloomTrieIndexer, - bloomIndexer: bloomIndexer, - retriever: retriever, - stop: make(chan struct{}), + db: db, + chtIndexer: chtIndexer, + bloomTrieIndexer: bloomTrieIndexer, + bloomIndexer: bloomIndexer, + retriever: retriever, + stop: make(chan struct{}), } } diff --git a/rpc/subscription_test.go b/rpc/subscription_test.go index 39f759692..0ba177e63 100644 --- a/rpc/subscription_test.go +++ b/rpc/subscription_test.go @@ -290,7 +290,7 @@ func TestSubscriptionMultipleNamespaces(t *testing.T) { for { done := true - for id, _ := range count { + for id := range count { if count, found := count[id]; !found || count < (2*n) { done = false } diff --git a/swarm/api/client/client_test.go b/swarm/api/client/client_test.go index edf385dd0..c1d144e37 100644 --- a/swarm/api/client/client_test.go +++ b/swarm/api/client/client_test.go @@ -244,25 +244,25 @@ func TestClientFileList(t *testing.T) { } tests := map[string][]string{ - "": []string{"dir1/", "dir2/", "file1.txt", "file2.txt"}, - "file": []string{"file1.txt", "file2.txt"}, - "file1": []string{"file1.txt"}, - "file2.txt": []string{"file2.txt"}, - "file12": []string{}, - "dir": []string{"dir1/", "dir2/"}, - "dir1": []string{"dir1/"}, - "dir1/": []string{"dir1/file3.txt", "dir1/file4.txt"}, - "dir1/file": []string{"dir1/file3.txt", "dir1/file4.txt"}, - "dir1/file3.txt": []string{"dir1/file3.txt"}, - "dir1/file34": []string{}, - "dir2/": []string{"dir2/dir3/", "dir2/dir4/", "dir2/file5.txt"}, - "dir2/file": []string{"dir2/file5.txt"}, - "dir2/dir": []string{"dir2/dir3/", "dir2/dir4/"}, - "dir2/dir3/": []string{"dir2/dir3/file6.txt"}, - "dir2/dir4/": []string{"dir2/dir4/file7.txt", "dir2/dir4/file8.txt"}, - "dir2/dir4/file": []string{"dir2/dir4/file7.txt", "dir2/dir4/file8.txt"}, - "dir2/dir4/file7.txt": []string{"dir2/dir4/file7.txt"}, - "dir2/dir4/file78": []string{}, + "": {"dir1/", "dir2/", "file1.txt", "file2.txt"}, + "file": {"file1.txt", "file2.txt"}, + "file1": {"file1.txt"}, + "file2.txt": {"file2.txt"}, + "file12": {}, + "dir": {"dir1/", "dir2/"}, + "dir1": {"dir1/"}, + "dir1/": {"dir1/file3.txt", "dir1/file4.txt"}, + "dir1/file": {"dir1/file3.txt", "dir1/file4.txt"}, + "dir1/file3.txt": {"dir1/file3.txt"}, + "dir1/file34": {}, + "dir2/": {"dir2/dir3/", "dir2/dir4/", "dir2/file5.txt"}, + "dir2/file": {"dir2/file5.txt"}, + "dir2/dir": {"dir2/dir3/", "dir2/dir4/"}, + "dir2/dir3/": {"dir2/dir3/file6.txt"}, + "dir2/dir4/": {"dir2/dir4/file7.txt", "dir2/dir4/file8.txt"}, + "dir2/dir4/file": {"dir2/dir4/file7.txt", "dir2/dir4/file8.txt"}, + "dir2/dir4/file7.txt": {"dir2/dir4/file7.txt"}, + "dir2/dir4/file78": {}, } for prefix, expected := range tests { actual := ls(prefix) diff --git a/swarm/storage/chunker.go b/swarm/storage/chunker.go index 0454828b9..8c0d62cbe 100644 --- a/swarm/storage/chunker.go +++ b/swarm/storage/chunker.go @@ -50,7 +50,6 @@ data_{i} := size(subtree_{i}) || key_{j} || key_{j+1} .... || key_{j+n-1} The underlying hash function is configurable */ - /* Tree chunker is a concrete implementation of data chunking. This chunker works in a simple way, it builds a tree out of the document so that each node either represents a chunk of real data or a chunk of data representing an branching non-leaf node of the tree. In particular each such non-leaf chunk will represent is a concatenation of the hash of its respective children. This scheme simultaneously guarantees data integrity as well as self addressing. Abstract nodes are transparent since their represented size component is strictly greater than their maximum data size, since they encode a subtree. @@ -61,17 +60,17 @@ The hashing itself does use extra copies and allocation though, since it does ne var ( errAppendOppNotSuported = errors.New("Append operation not supported") - errOperationTimedOut = errors.New("operation timed out") + errOperationTimedOut = errors.New("operation timed out") ) type TreeChunker struct { branches int64 hashFunc SwarmHasher // calculated - hashSize int64 // self.hashFunc.New().Size() - chunkSize int64 // hashSize* branches - workerCount int64 // the number of worker routines used - workerLock sync.RWMutex // lock for the worker count + hashSize int64 // self.hashFunc.New().Size() + chunkSize int64 // hashSize* branches + workerCount int64 // the number of worker routines used + workerLock sync.RWMutex // lock for the worker count } func NewTreeChunker(params *ChunkerParams) (self *TreeChunker) { @@ -124,7 +123,6 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s panic("chunker must be initialised") } - jobC := make(chan *hashJob, 2*ChunkProcessors) wg := &sync.WaitGroup{} errC := make(chan error) @@ -164,7 +162,6 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s close(errC) }() - defer close(quitC) select { case err := <-errC: @@ -172,7 +169,7 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s return nil, err } case <-time.NewTimer(splitTimeout).C: - return nil,errOperationTimedOut + return nil, errOperationTimedOut } return key, nil diff --git a/swarm/storage/pyramid.go b/swarm/storage/pyramid.go index 631ab52b8..42b83583d 100644 --- a/swarm/storage/pyramid.go +++ b/swarm/storage/pyramid.go @@ -123,7 +123,7 @@ type PyramidChunker struct { hashSize int64 branches int64 workerCount int64 - workerLock sync.RWMutex + workerLock sync.RWMutex } func NewPyramidChunker(params *ChunkerParams) (self *PyramidChunker) { @@ -634,4 +634,4 @@ func (self *PyramidChunker) enqueueDataChunk(chunkData []byte, size uint64, pare return pkey -} \ No newline at end of file +} diff --git a/tests/init.go b/tests/init.go index a2c633ad6..9e884efe3 100644 --- a/tests/init.go +++ b/tests/init.go @@ -25,26 +25,26 @@ import ( // This table defines supported forks and their chain config. var Forks = map[string]*params.ChainConfig{ - "Frontier": ¶ms.ChainConfig{ + "Frontier": { ChainId: big.NewInt(1), }, - "Homestead": ¶ms.ChainConfig{ + "Homestead": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), }, - "EIP150": ¶ms.ChainConfig{ + "EIP150": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), }, - "EIP158": ¶ms.ChainConfig{ + "EIP158": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), }, - "Byzantium": ¶ms.ChainConfig{ + "Byzantium": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), @@ -53,22 +53,22 @@ var Forks = map[string]*params.ChainConfig{ DAOForkBlock: big.NewInt(0), ByzantiumBlock: big.NewInt(0), }, - "FrontierToHomesteadAt5": ¶ms.ChainConfig{ + "FrontierToHomesteadAt5": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(5), }, - "HomesteadToEIP150At5": ¶ms.ChainConfig{ + "HomesteadToEIP150At5": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(5), }, - "HomesteadToDaoAt5": ¶ms.ChainConfig{ + "HomesteadToDaoAt5": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: big.NewInt(5), DAOForkSupport: true, }, - "EIP158ToByzantiumAt5": ¶ms.ChainConfig{ + "EIP158ToByzantiumAt5": { ChainId: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 64bf09cb4..352f840d9 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -112,7 +112,7 @@ type stTransactionMarshaling struct { func (t *StateTest) Subtests() []StateSubtest { var sub []StateSubtest for fork, pss := range t.json.Post { - for i, _ := range pss { + for i := range pss { sub = append(sub, StateSubtest{fork, i}) } }