good morning!!!!

Skip to content
Snippets Groups Projects
Commit c39484bc authored by Jeffrey Wilcke's avatar Jeffrey Wilcke
Browse files

Added thread safe each

parent eff6a434
No related branches found
No related tags found
No related merge requests found
......@@ -88,3 +88,14 @@ func (bc *BlockCache) Has(hash common.Hash) bool {
_, ok := bc.blocks[hash]
return ok
}
func (bc *BlockCache) Each(cb func(int, *types.Block)) {
bc.mu.Lock()
defer bc.mu.Unlock()
i := 0
for _, block := range bc.blocks {
cb(i, block)
i++
}
}
......@@ -438,9 +438,9 @@ type queueEvent struct {
func (self *ChainManager) procFutureBlocks() {
blocks := make([]*types.Block, len(self.futureBlocks.blocks))
for i, hash := range self.futureBlocks.hashes {
blocks[i] = self.futureBlocks.Get(hash)
}
self.futureBlocks.Each(func(i int, block *types.Block) {
blocks[i] = block
})
types.BlockBy(types.Number).Sort(blocks)
self.InsertChain(blocks)
......@@ -536,7 +536,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
if len(chain) > 0 && glog.V(logger.Info) {
start, end := chain[0], chain[len(chain)-1]
glog.Infof("imported %d blocks #%v [%x / %x]\n", len(chain), end.Number(), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4])
glog.Infof("imported %d block(s) #%v [%x / %x]\n", len(chain), end.Number(), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4])
}
go self.eventMux.Post(queueEvent)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment