good morning!!!!

Skip to content
Snippets Groups Projects
Commit 0275fcb3 authored by Péter Szilágyi's avatar Péter Szilágyi
Browse files

eth/downloader: clean up and simplify the code a bit

parent abdfcda4
No related branches found
No related tags found
No related merge requests found
...@@ -3,20 +3,18 @@ package downloader ...@@ -3,20 +3,18 @@ package downloader
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"math/rand" "math/rand"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"gopkg.in/fatih/set.v0"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/logger/glog"
"gopkg.in/fatih/set.v0"
) )
const ( const (
...@@ -301,7 +299,6 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error { ...@@ -301,7 +299,6 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
d.queue.Insert(hashPack.hashes[:index+1]) d.queue.Insert(hashPack.hashes[:index+1])
if err := d.banBlocks(active.id, hash); err != nil { 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) glog.V(logger.Debug).Infof("Failed to ban batch of blocks: %v", err)
} }
return ErrInvalidChain return ErrInvalidChain
...@@ -596,15 +593,8 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error { ...@@ -596,15 +593,8 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error {
if len(blocks) == 0 { if len(blocks) == 0 {
return errors.New("no blocks returned to ban") return errors.New("no blocks returned to ban")
} }
// Got the batch of invalid blocks, reconstruct their chain order // Reconstruct the original chain order and ensure we're banning the correct blocks
for i := 0; i < len(blocks); i++ { types.BlockBy(types.Number).Sort(blocks)
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
if bytes.Compare(blocks[0].Hash().Bytes(), head.Bytes()) != 0 { if bytes.Compare(blocks[0].Hash().Bytes(), head.Bytes()) != 0 {
return errors.New("head block not the banned one") return errors.New("head block not the banned one")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment