Example #1
0
func (self *CpuAgent) mine(block *types.Block) {
	glog.V(logger.Debug).Infof("(re)started agent[%d]. mining...\n", self.index)

	// Reset the channel
	self.chMu.Lock()
	self.quitCurrentOp = make(chan struct{}, 1)
	self.chMu.Unlock()

	// Mine
	nonce, mixDigest := self.pow.Search(block, self.quitCurrentOp)
	if nonce != 0 {
		block.SetNonce(nonce)
		block.Header().MixDigest = common.BytesToHash(mixDigest)
		self.returnCh <- block
	} else {
		self.returnCh <- nil
	}
}