diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-30 23:51:47 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-30 23:51:47 +0800 |
commit | 8595198c1b56364bb9589a912d2a9797b93a3357 (patch) | |
tree | 2c83d707dde62dc2af98a10d35376f23c06a237a /eth | |
parent | 15873fafc02e444c38de722277ab2461cb9b82c5 (diff) | |
download | go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.tar go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.tar.gz go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.tar.bz2 go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.tar.lz go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.tar.xz go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.tar.zst go-tangerine-8595198c1b56364bb9589a912d2a9797b93a3357.zip |
eth/downloader: delete blocks from queue
Diffstat (limited to 'eth')
-rw-r--r-- | eth/downloader/downloader.go | 16 | ||||
-rw-r--r-- | eth/handler.go | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index a48b60716..016f290fc 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -354,6 +354,11 @@ func (d *Downloader) AddHashes(id string, hashes []common.Hash) error { return fmt.Errorf("received hashes from %s while active peer is %s", id, d.activePeer) } + if glog.V(logger.Detail) && len(hashes) != 0 { + from, to := hashes[0], hashes[len(hashes)-1] + glog.Infof("adding %d (T=%d) hashes [ %x / %x ] from: %s\n", len(hashes), d.queue.hashPool.Size(), from[:4], to[:4], id) + } + d.hashCh <- hashes return nil @@ -448,10 +453,17 @@ func (d *Downloader) process(peer *peer) error { return ErrBadPeer } - blocks = blocks[max:] + + // delete the blocks from the slice and let them be garbage collected + // without this slice trick the blocks would stay in memory until nil + // would be assigned to d.queue.blocks + copy(blocks, blocks[max:]) + for k, n := len(blocks)-max, len(blocks); k < n; k++ { + blocks[k] = nil + } + blocks = blocks[:len(blocks)-max] } - // This will allow the GC to remove the in memory blocks if len(blocks) == 0 { d.queue.blocks = nil } else { diff --git a/eth/handler.go b/eth/handler.go index 6c1a92c77..2b432f95d 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -455,7 +455,7 @@ func (pm *ProtocolManager) BroadcastBlock(hash common.Hash, block *types.Block) for _, peer := range peers { peer.sendNewBlock(block) } - glog.V(logger.Detail).Infoln("broadcast block to", len(peers), "peers. Total propagation time:", time.Since(block.ReceivedAt)) + glog.V(logger.Detail).Infoln("broadcast block to", len(peers), "peers. Total processing time:", time.Since(block.ReceivedAt)) } // BroadcastTx will propagate the block to its connected peers. It will sort |