MCPcopy Create free account
hub / github.com/CPChain/chain / prove

Method prove

admission/work.go:112–147  ·  view source on GitHub ↗

prove implements ProveBackend, generate the campaign information. starts cpu pow work.

(abort <-chan interface{}, wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

110// prove implements ProveBackend, generate the campaign information.
111// starts cpu pow work.
112func (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
118search:
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}

Callers

nothing calls this directly

Calls 8

validateFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
NowMethod · 0.65
StopMethod · 0.65
BytesMethod · 0.65
HashMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected