diff options
-rw-r--r-- | accounts/abi/abi.go | 2 | ||||
-rw-r--r-- | accounts/accounts.go | 4 | ||||
-rw-r--r-- | accounts/keystore/wallet.go | 2 | ||||
-rw-r--r-- | cmd/clef/main.go | 7 | ||||
-rw-r--r-- | core/blockchain.go | 2 | ||||
-rw-r--r-- | core/blockchain_test.go | 2 | ||||
-rw-r--r-- | crypto/signature_cgo.go | 2 | ||||
-rw-r--r-- | crypto/signature_nocgo.go | 2 | ||||
-rw-r--r-- | eth/api_tracer.go | 19 | ||||
-rw-r--r-- | eth/config.go | 11 | ||||
-rw-r--r-- | eth/downloader/downloader.go | 2 | ||||
-rw-r--r-- | node/defaults.go | 37 | ||||
-rw-r--r-- | p2p/discover/udp.go | 16 | ||||
-rw-r--r-- | rpc/websocket.go | 7 | ||||
-rw-r--r-- | signer/core/abihelper.go | 12 | ||||
-rw-r--r-- | swarm/swarm.go | 107 | ||||
-rw-r--r-- | trie/database.go | 2 | ||||
-rw-r--r-- | trie/proof.go | 2 | ||||
-rw-r--r-- | trie/sync.go | 4 | ||||
-rw-r--r-- | trie/sync_test.go | 2 |
20 files changed, 155 insertions, 89 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 08d5db979..ba1774c64 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -136,7 +136,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { // returns nil if none found func (abi *ABI) MethodById(sigdata []byte) (*Method, error) { if len(sigdata) < 4 { - return nil, fmt.Errorf("data too short (% bytes) for abi method lookup", len(sigdata)) + return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata)) } for _, method := range abi.Methods { if bytes.Equal(method.Id(), sigdata[:4]) { diff --git a/accounts/accounts.go b/accounts/accounts.go index b57f282b3..a52aa425c 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -104,7 +104,7 @@ type Wallet interface { // a password to decrypt the account, or a PIN code o verify the transaction), // an AuthNeededError instance will be returned, containing infos for the user // about which fields or actions are needed. The user may retry by providing - // the needed details via SignHashWithPassphrase, or by other means (e.g. unlock + // the needed details via SignDataWithPassphrase, or by other means (e.g. unlock // the account in a keystore). SignData(account Account, mimeType string, data []byte) ([]byte, error) @@ -114,7 +114,7 @@ type Wallet interface { // should never echo the mimetype or return the mimetype in the error-response SignDataWithPassphrase(account Account, passphrase, mimeType string, data []byte) ([]byte, error) - // Signtext requests the wallet to sign the hash of a given piece of data, prefixed + // SignText requests the wallet to sign the hash of a given piece of data, prefixed // by the Ethereum prefix scheme // It looks up the account specified either solely via its address contained within, // or optionally with the aid of any location metadata from the embedded URL field. diff --git a/accounts/keystore/wallet.go b/accounts/keystore/wallet.go index 632620ead..1b36b6dff 100644 --- a/accounts/keystore/wallet.go +++ b/accounts/keystore/wallet.go @@ -111,7 +111,7 @@ func (w *keystoreWallet) SignText(account accounts.Account, text []byte) ([]byte return w.signHash(account, accounts.TextHash(text)) } -// SignHashWithPassphrase implements accounts.Wallet, attempting to sign the +// SignTextWithPassphrase implements accounts.Wallet, attempting to sign the // given hash with the given account using passphrase as extra authentication. func (w *keystoreWallet) SignTextWithPassphrase(account accounts.Account, passphrase string, text []byte) ([]byte, error) { // Make sure the requested account is contained within diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 802e118e7..088701eee 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -533,7 +533,12 @@ func DefaultConfigDir() string { if runtime.GOOS == "darwin" { return filepath.Join(home, "Library", "Signer") } else if runtime.GOOS == "windows" { - return filepath.Join(home, "AppData", "Roaming", "Signer") + appdata := os.Getenv("APPDATA") + if appdata != "" { + return filepath.Join(appdata, "Signer") + } else { + return filepath.Join(home, "AppData", "Roaming", "Signer") + } } else { return filepath.Join(home, ".clef") } diff --git a/core/blockchain.go b/core/blockchain.go index feb9fb942..b6605e66c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -456,7 +456,7 @@ func (bc *BlockChain) repair(head **types.Block) error { if block == nil { return fmt.Errorf("missing block %d [%x]", (*head).NumberU64()-1, (*head).ParentHash()) } - (*head) = block + *head = block } } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 0372a9848..a16b3ba8a 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1412,7 +1412,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in } b.StopTimer() if got := chain.CurrentBlock().Transactions().Len(); got != numTxs*numBlocks { - b.Fatalf("Transactions were not included, expected %d, got %d", (numTxs * numBlocks), got) + b.Fatalf("Transactions were not included, expected %d, got %d", numTxs*numBlocks, got) } } diff --git a/crypto/signature_cgo.go b/crypto/signature_cgo.go index 340bfc221..aadf028d2 100644 --- a/crypto/signature_cgo.go +++ b/crypto/signature_cgo.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. -// +build !nacl,!js,!nocgo +// +build !nacl,!js,cgo package crypto diff --git a/crypto/signature_nocgo.go b/crypto/signature_nocgo.go index e8fa18ed4..90d072cda 100644 --- a/crypto/signature_nocgo.go +++ b/crypto/signature_nocgo.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. -// +build nacl js nocgo +// +build nacl js !cgo package crypto diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 7aa48b256..a529ea118 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -526,13 +526,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block, func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) { // If we're tracing a single transaction, make sure it's present if config != nil && config.TxHash != (common.Hash{}) { - var exists bool - for _, tx := range block.Transactions() { - if exists = (tx.Hash() == config.TxHash); exists { - break - } - } - if !exists { + if !containsTx(block, config.TxHash) { return nil, fmt.Errorf("transaction %#x not found in block", config.TxHash) } } @@ -625,6 +619,17 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block return dumps, nil } +// containsTx reports whether the transaction with a certain hash +// is contained within the specified block. +func containsTx(block *types.Block, hash common.Hash) bool { + for _, tx := range block.Transactions() { + if tx.Hash() == hash { + return true + } + } + return false +} + // computeStateDB retrieves the state database associated with a certain block. // If no state is locally available for the given block, a number of blocks are // attempted to be reexecuted to generate the desired state. diff --git a/eth/config.go b/eth/config.go index f71b8dfee..aca9b5e68 100644 --- a/eth/config.go +++ b/eth/config.go @@ -68,8 +68,15 @@ func init() { home = user.HomeDir } } - if runtime.GOOS == "windows" { - DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash") + if runtime.GOOS == "darwin" { + DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") + } else if runtime.GOOS == "windows" { + localappdata := os.Getenv("LOCALAPPDATA") + if localappdata != "" { + DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") + } else { + DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") + } } else { DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash") } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 58d19254c..b8eaa6a5e 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -719,7 +719,7 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) } // Make sure the peer's reply conforms to the request for i, header := range headers { - expectNumber := from + int64(i)*int64((skip+1)) + expectNumber := from + int64(i)*int64(skip+1) if number := header.Number.Int64(); number != expectNumber { p.log.Warn("Head headers broke chain ordering", "index", i, "requested", expectNumber, "received", number) return 0, errInvalidChain diff --git a/node/defaults.go b/node/defaults.go index cea4997cb..73b262429 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -58,11 +58,20 @@ func DefaultDataDir() string { // Try to place the data folder in the user's home dir home := homeDir() if home != "" { - if runtime.GOOS == "darwin" { + switch runtime.GOOS { + case "darwin": return filepath.Join(home, "Library", "Ethereum") - } else if runtime.GOOS == "windows" { - return filepath.Join(home, "AppData", "Roaming", "Ethereum") - } else { + case "windows": + // We used to put everything in %HOME%\AppData\Roaming, but this caused + // problems with non-typical setups. If this fallback location exists and + // is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%. + fallback := filepath.Join(home, "AppData", "Roaming", "Ethereum") + appdata := windowsAppData() + if appdata == "" || isNonEmptyDir(fallback) { + return fallback + } + return filepath.Join(appdata, "Ethereum") + default: return filepath.Join(home, ".ethereum") } } @@ -70,6 +79,26 @@ func DefaultDataDir() string { return "" } +func windowsAppData() string { + if v := os.Getenv("LOCALAPPDATA"); v != "" { + return v // Vista+ + } + if v := os.Getenv("APPDATA"); v != "" { + return filepath.Join(v, "Local") + } + return "" +} + +func isNonEmptyDir(dir string) bool { + f, err := os.Open(dir) + if err != nil { + return false + } + names, _ := f.Readdir(1) + f.Close() + return len(names) > 0 +} + func homeDir() string { if home := os.Getenv("HOME"); home != "" { return home diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index df9a3065f..e386af363 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -54,6 +54,11 @@ const ( ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP ntpWarningCooldown = 10 * time.Minute // Minimum amount of time to pass before repeating NTP warning driftThreshold = 10 * time.Second // Allowed clock drift before warning user + + // Discovery packets are defined to be no larger than 1280 bytes. + // Packets larger than this size will be cut at the end and treated + // as invalid because their hash won't match. + maxPacketSize = 1280 ) // RPC packet types @@ -496,7 +501,7 @@ var ( headSpace = make([]byte, headSize) // Neighbors replies are sent across multiple packets to - // stay below the 1280 byte limit. We compute the maximum number + // stay below the packet size limit. We compute the maximum number // of entries by stuffing a packet until it grows too large. maxNeighbors int ) @@ -511,7 +516,7 @@ func init() { // If this ever happens, it will be caught by the unit tests. panic("cannot encode: " + err.Error()) } - if headSize+size+1 >= 1280 { + if headSize+size+1 >= maxPacketSize { maxNeighbors = n break } @@ -562,10 +567,7 @@ func (t *udp) readLoop(unhandled chan<- ReadPacket) { defer close(unhandled) } - // Discovery packets are defined to be no larger than 1280 bytes. - // Packets larger than this size will be cut at the end and treated - // as invalid because their hash won't match. - buf := make([]byte, 1280) + buf := make([]byte, maxPacketSize) for { nbytes, from, err := t.conn.ReadFromUDP(buf) if netutil.IsTemporaryError(err) { @@ -715,7 +717,7 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID enode.ID, mac []by t.tab.mutex.Unlock() // Send neighbors in chunks with at most maxNeighbors per packet - // to stay below the 1280 byte limit. + // to stay below the packet size limit. p := neighbors{Expiration: uint64(time.Now().Add(expiration).Unix())} var sent bool for _, n := range closest { diff --git a/rpc/websocket.go b/rpc/websocket.go index b8e067a5f..c5383667d 100644 --- a/rpc/websocket.go +++ b/rpc/websocket.go @@ -124,6 +124,13 @@ func wsHandshakeValidator(allowedOrigins []string) func(*websocket.Config, *http log.Debug(fmt.Sprintf("Allowed origin(s) for WS RPC interface %v", origins.ToSlice())) f := func(cfg *websocket.Config, req *http.Request) error { + // Skip origin verification if no Origin header is present. The origin check + // is supposed to protect against browser based attacks. Browsers always set + // Origin. Non-browser software can put anything in origin and checking it doesn't + // provide additional security. + if _, ok := req.Header["Origin"]; !ok { + return nil + } // Verify origin against whitelist. origin := strings.ToLower(req.Header.Get("Origin")) if allowAllOrigins || origins.Contains(origin) { diff --git a/signer/core/abihelper.go b/signer/core/abihelper.go index de6b815a6..88c1da033 100644 --- a/signer/core/abihelper.go +++ b/signer/core/abihelper.go @@ -177,7 +177,9 @@ func NewAbiDBFromFile(path string) (*AbiDb, error) { if err != nil { return nil, err } - json.Unmarshal(raw, &db.db) + if err := json.Unmarshal(raw, &db.db); err != nil { + return nil, err + } return db, nil } @@ -192,14 +194,18 @@ func NewAbiDBFromFiles(standard, custom string) (*AbiDb, error) { if err != nil { return nil, err } - json.Unmarshal(raw, &db.db) + if err := json.Unmarshal(raw, &db.db); err != nil { + return nil, err + } // Custom file may not exist. Will be created during save, if needed if _, err := os.Stat(custom); err == nil { raw, err = ioutil.ReadFile(custom) if err != nil { return nil, err } - json.Unmarshal(raw, &db.customdb) + if err := json.Unmarshal(raw, &db.customdb); err != nil { + return nil, err + } } return db, nil diff --git a/swarm/swarm.go b/swarm/swarm.go index 5b0e5f177..3ab98b3ab 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -344,51 +344,51 @@ Start is called when the stack is started * TODO: start subservices like sword, swear, swarmdns */ // implements the node.Service interface -func (self *Swarm) Start(srv *p2p.Server) error { +func (s *Swarm) Start(srv *p2p.Server) error { startTime := time.Now() - self.tracerClose = tracing.Closer + s.tracerClose = tracing.Closer // update uaddr to correct enode - newaddr := self.bzz.UpdateLocalAddr([]byte(srv.Self().String())) + newaddr := s.bzz.UpdateLocalAddr([]byte(srv.Self().String())) log.Info("Updated bzz local addr", "oaddr", fmt.Sprintf("%x", newaddr.OAddr), "uaddr", fmt.Sprintf("%s", newaddr.UAddr)) // set chequebook //TODO: Currently if swap is enabled and no chequebook (or inexistent) contract is provided, the node would crash. //Once we integrate back the contracts, this check MUST be revisited - if self.config.SwapEnabled && self.config.SwapAPI != "" { + if s.config.SwapEnabled && s.config.SwapAPI != "" { ctx := context.Background() // The initial setup has no deadline. - err := self.SetChequebook(ctx) + err := s.SetChequebook(ctx) if err != nil { return fmt.Errorf("Unable to set chequebook for SWAP: %v", err) } - log.Debug(fmt.Sprintf("-> cheque book for SWAP: %v", self.config.Swap.Chequebook())) + log.Debug(fmt.Sprintf("-> cheque book for SWAP: %v", s.config.Swap.Chequebook())) } else { log.Debug(fmt.Sprintf("SWAP disabled: no cheque book set")) } log.Info("Starting bzz service") - err := self.bzz.Start(srv) + err := s.bzz.Start(srv) if err != nil { log.Error("bzz failed", "err", err) return err } - log.Info("Swarm network started", "bzzaddr", fmt.Sprintf("%x", self.bzz.Hive.BaseAddr())) + log.Info("Swarm network started", "bzzaddr", fmt.Sprintf("%x", s.bzz.Hive.BaseAddr())) - if self.ps != nil { - self.ps.Start(srv) + if s.ps != nil { + s.ps.Start(srv) } // start swarm http proxy server - if self.config.Port != "" { - addr := net.JoinHostPort(self.config.ListenAddr, self.config.Port) - server := httpapi.NewServer(self.api, self.config.Cors) + if s.config.Port != "" { + addr := net.JoinHostPort(s.config.ListenAddr, s.config.Port) + server := httpapi.NewServer(s.api, s.config.Cors) - if self.config.Cors != "" { - log.Debug("Swarm HTTP proxy CORS headers", "allowedOrigins", self.config.Cors) + if s.config.Cors != "" { + log.Debug("Swarm HTTP proxy CORS headers", "allowedOrigins", s.config.Cors) } - log.Debug("Starting Swarm HTTP proxy", "port", self.config.Port) + log.Debug("Starting Swarm HTTP proxy", "port", s.config.Port) go func() { err := server.ListenAndServe(addr) if err != nil { @@ -399,7 +399,7 @@ func (self *Swarm) Start(srv *p2p.Server) error { doneC := make(chan struct{}) - self.cleanupFuncs = append(self.cleanupFuncs, func() error { + s.cleanupFuncs = append(s.cleanupFuncs, func() error { close(doneC) return nil }) @@ -409,7 +409,7 @@ func (self *Swarm) Start(srv *p2p.Server) error { select { case <-time.After(updateGaugesPeriod): uptimeGauge.Update(time.Since(startTime).Nanoseconds()) - requestsCacheGauge.Update(int64(self.netStore.RequestsCacheLen())) + requestsCacheGauge.Update(int64(s.netStore.RequestsCacheLen())) case <-doneC: return } @@ -417,46 +417,46 @@ func (self *Swarm) Start(srv *p2p.Server) error { }(startTime) startCounter.Inc(1) - self.streamer.Start(srv) + s.streamer.Start(srv) return nil } // implements the node.Service interface // stops all component services. -func (self *Swarm) Stop() error { - if self.tracerClose != nil { - err := self.tracerClose.Close() +func (s *Swarm) Stop() error { + if s.tracerClose != nil { + err := s.tracerClose.Close() if err != nil { return err } } - if self.ps != nil { - self.ps.Stop() + if s.ps != nil { + s.ps.Stop() } - if ch := self.config.Swap.Chequebook(); ch != nil { + if ch := s.config.Swap.Chequebook(); ch != nil { ch.Stop() ch.Save() } - if self.swap != nil { - self.swap.Close() + if s.swap != nil { + s.swap.Close() } - if self.accountingMetrics != nil { - self.accountingMetrics.Close() + if s.accountingMetrics != nil { + s.accountingMetrics.Close() } - if self.netStore != nil { - self.netStore.Close() + if s.netStore != nil { + s.netStore.Close() } - self.sfs.Stop() + s.sfs.Stop() stopCounter.Inc(1) - self.streamer.Stop() + s.streamer.Stop() - err := self.bzz.Stop() - if self.stateStore != nil { - self.stateStore.Close() + err := s.bzz.Stop() + if s.stateStore != nil { + s.stateStore.Close() } - for _, cleanF := range self.cleanupFuncs { + for _, cleanF := range s.cleanupFuncs { err = cleanF() if err != nil { log.Error("encountered an error while running cleanup function", "err", err) @@ -482,68 +482,73 @@ func (s *Swarm) Protocols() (protos []p2p.Protocol) { // implements node.Service // APIs returns the RPC API descriptors the Swarm implementation offers -func (self *Swarm) APIs() []rpc.API { +func (s *Swarm) APIs() []rpc.API { apis := []rpc.API{ // public APIs { Namespace: "bzz", Version: "3.0", - Service: &Info{self.config, chequebook.ContractParams}, + Service: &Info{s.config, chequebook.ContractParams}, Public: true, }, // admin APIs { Namespace: "bzz", Version: "3.0", - Service: api.NewInspector(self.api, self.bzz.Hive, self.netStore), + Service: api.NewInspector(s.api, s.bzz.Hive, s.netStore), Public: false, }, { Namespace: "chequebook", Version: chequebook.Version, - Service: chequebook.NewAPI(self.config.Swap.Chequebook), + Service: chequebook.NewAPI(s.config.Swap.Chequebook), Public: false, }, { Namespace: "swarmfs", Version: fuse.Swarmfs_Version, - Service: self.sfs, + Service: s.sfs, Public: false, }, { Namespace: "accounting", Version: protocols.AccountingVersion, - Service: protocols.NewAccountingApi(self.accountingMetrics), + Service: protocols.NewAccountingApi(s.accountingMetrics), Public: false, }, } - apis = append(apis, self.bzz.APIs()...) + apis = append(apis, s.bzz.APIs()...) - if self.ps != nil { - apis = append(apis, self.ps.APIs()...) + if s.ps != nil { + apis = append(apis, s.ps.APIs()...) } return apis } // SetChequebook ensures that the local checquebook is set up on chain. -func (self *Swarm) SetChequebook(ctx context.Context) error { - err := self.config.Swap.SetChequebook(ctx, self.backend, self.config.Path) +func (s *Swarm) SetChequebook(ctx context.Context) error { + err := s.config.Swap.SetChequebook(ctx, s.backend, s.config.Path) if err != nil { return err } - log.Info(fmt.Sprintf("new chequebook set (%v): saving config file, resetting all connections in the hive", self.config.Swap.Contract.Hex())) + log.Info(fmt.Sprintf("new chequebook set (%v): saving config file, resetting all connections in the hive", s.config.Swap.Contract.Hex())) return nil } +// RegisterPssProtocol adds a devp2p protocol to the swarm node's Pss instance +func (s *Swarm) RegisterPssProtocol(topic *pss.Topic, spec *protocols.Spec, targetprotocol *p2p.Protocol, options *pss.ProtocolParams) (*pss.Protocol, error) { + return pss.RegisterProtocol(s.ps, topic, spec, targetprotocol, options) +} + // serialisable info about swarm type Info struct { *api.Config *chequebook.Params } -func (self *Info) Info() *Info { - return self +func (s *Info) Info() *Info { + return s } diff --git a/trie/database.go b/trie/database.go index aba5943f5..958823eb8 100644 --- a/trie/database.go +++ b/trie/database.go @@ -809,7 +809,7 @@ func (db *Database) verifyIntegrity() { db.accumulate(child, reachable) } // Find any unreachable but cached nodes - unreachable := []string{} + var unreachable []string for hash, node := range db.dirties { if _, ok := reachable[hash]; !ok { unreachable = append(unreachable, fmt.Sprintf("%x: {Node: %v, Parents: %d, Prev: %x, Next: %x}", diff --git a/trie/proof.go b/trie/proof.go index f90ecd7d8..1334bde97 100644 --- a/trie/proof.go +++ b/trie/proof.go @@ -37,7 +37,7 @@ import ( func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error { // Collect all nodes on the path to key. key = keybytesToHex(key) - nodes := []node{} + var nodes []node tn := t.root for len(key) > 0 && tn != nil { switch n := tn.(type) { diff --git a/trie/sync.go b/trie/sync.go index 67dff5a8b..44f5087b9 100644 --- a/trie/sync.go +++ b/trie/sync.go @@ -157,7 +157,7 @@ func (s *Sync) AddRawEntry(hash common.Hash, depth int, parent common.Hash) { // Missing retrieves the known missing nodes from the trie for retrieval. func (s *Sync) Missing(max int) []common.Hash { - requests := []common.Hash{} + var requests []common.Hash for !s.queue.Empty() && (max == 0 || len(requests) < max) { requests = append(requests, s.queue.PopItem().(common.Hash)) } @@ -254,7 +254,7 @@ func (s *Sync) children(req *request, object node) ([]*request, error) { node node depth int } - children := []child{} + var children []child switch node := (object).(type) { case *shortNode: diff --git a/trie/sync_test.go b/trie/sync_test.go index c76779e5c..ff15baa52 100644 --- a/trie/sync_test.go +++ b/trie/sync_test.go @@ -313,7 +313,7 @@ func TestIncompleteSync(t *testing.T) { triedb := NewDatabase(diskdb) sched := NewSync(srcTrie.Hash(), diskdb, nil) - added := []common.Hash{} + var added []common.Hash queue := append([]common.Hash{}, sched.Missing(1)...) for len(queue) > 0 { // Fetch a batch of trie nodes |