Block pool is thread safe

This commit is contained in:
obscuren
2014-09-28 14:52:58 +02:00
parent 44d50bc8d2
commit ea0357bf02
3 changed files with 88 additions and 72 deletions

11
peer.go
View File

@ -503,16 +503,15 @@ func (p *Peer) HandleInbound() {
it := msg.Data.NewIterator()
for it.Next() {
hash := it.Value().Bytes()
p.lastReceivedHash = hash
p.LastHashReceived = time.Now()
if blockPool.HasCommonHash(hash) {
foundCommonHash = true
break
}
p.lastReceivedHash = hash
p.LastHashReceived = time.Now()
blockPool.AddHash(hash, p)
}
@ -530,7 +529,7 @@ func (p *Peer) HandleInbound() {
block := ethchain.NewBlockFromRlpValue(it.Value())
//fmt.Printf("%v %x - %x\n", block.Number, block.Hash()[0:4], block.PrevHash[0:4])
blockPool.SetBlock(block, p)
blockPool.Add(block, p)
p.lastBlockReceived = time.Now()
}
@ -561,7 +560,7 @@ func (self *Peer) FetchHashes() {
}
func (self *Peer) FetchingHashes() bool {
return time.Since(self.LastHashReceived) < 5*time.Second
return time.Since(self.LastHashReceived) < 200*time.Millisecond
}
// General update method