diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-05-30 05:34:23 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-08 18:23:58 +0800 |
commit | 0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d (patch) | |
tree | a1d727ed04498d78952489f792f5379b197b7524 | |
parent | abdfcda4dd223f2a2a932628da1e9388d2670856 (diff) | |
download | dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.tar dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.tar.gz dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.tar.bz2 dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.tar.lz dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.tar.xz dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.tar.zst dexon-0275fcb3d3979d14e01b4e0b9980be6d0cafbc8d.zip |
eth/downloader: clean up and simplify the code a bit
-rw-r--r-- | eth/downloader/downloader.go | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index af9b6b2b1..159a06bd4 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -3,20 +3,18 @@ package downloader import ( "bytes" "errors" - "fmt" "math/rand" "sync" "sync/atomic" "time" - "gopkg.in/fatih/set.v0" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "gopkg.in/fatih/set.v0" ) const ( @@ -301,7 +299,6 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error { d.queue.Insert(hashPack.hashes[:index+1]) if err := d.banBlocks(active.id, hash); err != nil { - fmt.Println("ban err", err) glog.V(logger.Debug).Infof("Failed to ban batch of blocks: %v", err) } return ErrInvalidChain @@ -596,15 +593,8 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error { if len(blocks) == 0 { return errors.New("no blocks returned to ban") } - // Got the batch of invalid blocks, reconstruct their chain order - for i := 0; i < len(blocks); i++ { - for j := i + 1; j < len(blocks); j++ { - if blocks[i].NumberU64() > blocks[j].NumberU64() { - blocks[i], blocks[j] = blocks[j], blocks[i] - } - } - } - // Ensure we're really banning the correct blocks + // Reconstruct the original chain order and ensure we're banning the correct blocks + types.BlockBy(types.Number).Sort(blocks) if bytes.Compare(blocks[0].Hash().Bytes(), head.Bytes()) != 0 { return errors.New("head block not the banned one") } |