diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-29 00:01:40 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-29 00:01:40 +0800 |
commit | f082c1b8959c1c729a4b62d6ff101d7569e8ba0f (patch) | |
tree | d19fdc2e8982a64d93612677dc2722dd41c8dbd3 /eth | |
parent | 70867904a0255bd044851585a9ad2dc34391ced2 (diff) | |
parent | d51d74eb55535db7670ad336d186ea64c6a2ff81 (diff) | |
download | dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.gz dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.bz2 dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.lz dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.xz dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.zst dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.zip |
Merge branch 'release/0.9.26'
Diffstat (limited to 'eth')
-rw-r--r-- | eth/downloader/downloader.go | 16 | ||||
-rw-r--r-- | eth/handler.go | 19 | ||||
-rw-r--r-- | eth/sync.go | 3 |
3 files changed, 30 insertions, 8 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 421c336f2..85531ce15 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -7,7 +7,10 @@ import ( "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" @@ -75,6 +78,7 @@ type Downloader struct { queue *queue // Scheduler for selecting the hashes to download peers *peerSet // Set of active peers from which download can proceed checks map[common.Hash]*crossCheck // Pending cross checks to verify a hash chain + banned *set.SetNonTS // Set of hashes we've received and banned // Callbacks hasBlock hashCheckFn @@ -100,6 +104,7 @@ type Block struct { } func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloader { + // Create the base downloader downloader := &Downloader{ mux: mux, queue: newQueue(), @@ -110,6 +115,11 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa hashCh: make(chan hashPack, 1), blockCh: make(chan blockPack, 1), } + // Inject all the known bad hashes + downloader.banned = set.NewNonTS() + for hash, _ := range core.BadHashes { + downloader.banned.Add(hash) + } return downloader } @@ -280,6 +290,12 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error { glog.V(logger.Debug).Infof("Peer (%s) responded with empty hash set\n", active.id) return errEmptyHashSet } + for _, hash := range hashPack.hashes { + if d.banned.Has(hash) { + glog.V(logger.Debug).Infof("Peer (%s) sent a known invalid chain\n", active.id) + return ErrInvalidChain + } + } // Determine if we're done fetching hashes (queue up all pending), and continue if not done done, index := false, 0 for index, head = range hashPack.hashes { diff --git a/eth/handler.go b/eth/handler.go index 777a9c7c0..aea33452c 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -2,7 +2,6 @@ package eth import ( "fmt" - "math" "math/big" "sync" "time" @@ -93,14 +92,22 @@ func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpo } func (pm *ProtocolManager) removePeer(id string) { - // Unregister the peer from the downloader - pm.downloader.UnregisterPeer(id) + // Short circuit if the peer was already removed + peer := pm.peers.Peer(id) + if peer == nil { + return + } + glog.V(logger.Debug).Infoln("Removing peer", id) - // Remove the peer from the Ethereum peer set too - glog.V(logger.Detail).Infoln("Removing peer", id) + // Unregister the peer from the downloader and Ethereum peer set + pm.downloader.UnregisterPeer(id) if err := pm.peers.Unregister(id); err != nil { glog.V(logger.Error).Infoln("Removal failed:", err) } + // Hard disconnect at the networking layer + if peer != nil { + peer.Peer.Disconnect(p2p.DiscUselessPeer) + } } func (pm *ProtocolManager) Start() { @@ -351,7 +358,7 @@ func (pm *ProtocolManager) verifyTd(peer *peer, request newBlockMsgData) error { func (pm *ProtocolManager) BroadcastBlock(hash common.Hash, block *types.Block) { // Broadcast block to a batch of peers not knowing about it peers := pm.peers.PeersWithoutBlock(hash) - peers = peers[:int(math.Sqrt(float64(len(peers))))] + //peers = peers[:int(math.Sqrt(float64(len(peers))))] for _, peer := range peers { peer.sendNewBlock(block) } diff --git a/eth/sync.go b/eth/sync.go index cf549f852..76e137630 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -70,6 +70,7 @@ func (pm *ProtocolManager) processBlocks() error { // Try to inset the blocks, drop the originating peer if there's an error index, err := pm.chainman.InsertChain(raw) if err != nil { + glog.V(logger.Debug).Infoln("Downloaded block import failed:", err) pm.removePeer(blocks[index].OriginPeer) pm.downloader.Cancel() return err @@ -84,12 +85,10 @@ func (pm *ProtocolManager) processBlocks() error { func (pm *ProtocolManager) synchronise(peer *peer) { // Short circuit if no peers are available if peer == nil { - glog.V(logger.Debug).Infoln("Synchronisation canceled: no peers available") return } // Make sure the peer's TD is higher than our own. If not drop. if peer.td.Cmp(pm.chainman.Td()) <= 0 { - glog.V(logger.Debug).Infoln("Synchronisation canceled: peer's total difficulty is too small") return } // FIXME if we have the hash in our chain and the TD of the peer is |