diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-02 23:35:38 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-02 23:35:38 +0800 |
commit | 677836cbee1105043335c672b41dc4402e98c227 (patch) | |
tree | 365b05bbd446f36078790445dc4154ceaf577b0b /block_pool.go | |
parent | a75c92000fab997a41479c8f92e62f6b0d3f3434 (diff) | |
download | dexon-677836cbee1105043335c672b41dc4402e98c227.tar.gz dexon-677836cbee1105043335c672b41dc4402e98c227.tar.zst dexon-677836cbee1105043335c672b41dc4402e98c227.zip |
Kick off bad peers on bad chains and improved catch up on diverted chain
Diffstat (limited to 'block_pool.go')
-rw-r--r-- | block_pool.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/block_pool.go b/block_pool.go index e31babfd6..a951672c3 100644 --- a/block_pool.go +++ b/block_pool.go @@ -56,6 +56,11 @@ func (self *BlockPool) Len() int { return len(self.hashPool) } +func (self *BlockPool) Reset() { + self.pool = make(map[string]*block) + self.hashPool = nil +} + func (self *BlockPool) HasLatestHash() bool { self.mut.Lock() defer self.mut.Unlock() @@ -77,7 +82,7 @@ func (self *BlockPool) Blocks() (blocks ethchain.Blocks) { return } -func (self *BlockPool) FetchHashes(peer *Peer) { +func (self *BlockPool) FetchHashes(peer *Peer) bool { highestTd := self.eth.HighestTDPeer() if (self.peer == nil && peer.td.Cmp(highestTd) >= 0) || (self.peer != nil && peer.td.Cmp(self.peer.td) >= 0) || self.peer == peer { @@ -95,7 +100,11 @@ func (self *BlockPool) FetchHashes(peer *Peer) { peerlogger.Debugf("Fetching hashes (%d)\n", amount) peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{peer.lastReceivedHash, uint32(amount)})) } + + return true } + + return false } func (self *BlockPool) AddHash(hash []byte, peer *Peer) { @@ -122,7 +131,7 @@ func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) { self.pool[hash] = &block{peer, peer, b, time.Now(), 0} if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes { - poollogger.Infof("Unknown block, requesting parent (%x...)\n", b.PrevHash[0:4]) + poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4]) peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)})) } } else if self.pool[hash] != nil { @@ -308,6 +317,7 @@ out: } if err != nil { + self.Reset() // Remove this bad chain for _, block := range blocks { self.Remove(block.Hash()) |