prove implements ProveBackend, generate the campaign information. starts cpu pow work.
(abort <-chan interface{}, wg *sync.WaitGroup)
| 110 | // prove implements ProveBackend, generate the campaign information. |
| 111 | // starts cpu pow work. |
| 112 | func (w *work) prove(abort <-chan interface{}, wg *sync.WaitGroup) { |
| 113 | defer wg.Done() |
| 114 | start := time.Now() |
| 115 | ticker := time.NewTicker(time.Duration(w.timeout)) |
| 116 | defer ticker.Stop() |
| 117 | |
| 118 | search: |
| 119 | for { |
| 120 | select { |
| 121 | case <-abort: |
| 122 | w.mutex.Lock() |
| 123 | w.err = ErrPowAbort |
| 124 | w.mutex.Unlock() |
| 125 | break search |
| 126 | case <-ticker.C: |
| 127 | w.mutex.Lock() |
| 128 | w.err = ErrPowTimeout |
| 129 | w.mutex.Unlock() |
| 130 | break search |
| 131 | default: |
| 132 | w.mutex.RLock() |
| 133 | nonce := w.nonce |
| 134 | w.mutex.RUnlock() |
| 135 | |
| 136 | if nonce < maxNonce && validate(w.difficulty, w.header.Hash().Bytes(), w.coinbase, nonce, w.hashfn) { |
| 137 | log.Info("found nonce", "block hash", w.header.Hash().Hex(), "difficulty", w.difficulty, |
| 138 | "sender", w.coinbase.Hex(), "nonce", nonce, "timeCost(s)", time.Since(start).Seconds()) |
| 139 | break search |
| 140 | } |
| 141 | |
| 142 | w.mutex.Lock() |
| 143 | w.nonce++ |
| 144 | w.mutex.Unlock() |
| 145 | } |
| 146 | } |
| 147 | } |