Minor improvement catching up

* When catching up check linked up the chain of hashes
This commit is contained in:
obscuren 2014-08-22 14:52:20 +02:00
parent 836ed9d6b7
commit be9bfb5536

@ -1,6 +1,7 @@
package eth package eth
import ( import (
"fmt"
"math" "math"
"math/big" "math/big"
"sync" "sync"
@ -51,6 +52,7 @@ func (self *BlockPool) AddHash(hash []byte) {
func (self *BlockPool) SetBlock(b *ethchain.Block, peer *Peer) { func (self *BlockPool) SetBlock(b *ethchain.Block, peer *Peer) {
hash := string(b.Hash()) hash := string(b.Hash())
fmt.Printf("::SetBlock %x\n", hash)
if self.pool[hash] == nil { if self.pool[hash] == nil {
self.pool[hash] = &block{peer, nil} self.pool[hash] = &block{peer, nil}
@ -88,13 +90,19 @@ func (self *BlockPool) CheckLinkAndProcess(f func(block *ethchain.Block)) bool {
} }
func (self *BlockPool) IsLinked() bool { func (self *BlockPool) IsLinked() bool {
if len(self.hashPool) == 0 || self.pool[string(self.hashPool[0])] == nil { if len(self.hashPool) == 0 {
return false return false
} }
block := self.pool[string(self.hashPool[0])].block for i := 0; i < len(self.hashPool); i++ {
if block != nil { item := self.pool[string(self.hashPool[i])]
return self.eth.BlockChain().HasBlock(block.PrevHash) if item != nil && item.block != nil {
if self.eth.BlockChain().HasBlock(item.block.PrevHash) {
self.hashPool = self.hashPool[i:]
return true
}
}
} }
return false return false