worker: capture errors

parent a13aafcd
Pipeline #17902104 failed with stages
in 6 minutes and 44 seconds
......@@ -4,6 +4,8 @@ import (
"fmt"
"time"
"github.com/getsentry/raven-go"
metrics "github.com/armon/go-metrics"
"gitlab.com/blockforge/blockforge/algo/cryptonight"
"gitlab.com/blockforge/blockforge/log"
......@@ -72,7 +74,9 @@ func (worker *Cryptonight) gpuThread(key []string, cl *cryptonightCL, workChan c
var ok bool
work := <-workChan
cl.SetJob(work.Input, work.Target)
if err := cl.Update(work.Input, work.Target); err != nil {
workerError(err)
}
for {
select {
......@@ -80,14 +84,14 @@ func (worker *Cryptonight) gpuThread(key []string, cl *cryptonightCL, workChan c
start := time.Now()
results := make([]uint32, 0x100)
if err := cl.RunJob(results, work.NextNonce(cl.Intensity)); err != nil {
log.Errorw("cl error", "error", err)
return
if err := cl.Run(results, work.NextNonce(cl.Intensity)); err != nil {
workerError(err)
}
// number of results is stored in last item of results array
// number of results is stored in last item of results slice
for i := uint32(0); i < results[0xFF]; i++ {
if !work.VerifySend(worker.Algo.Lite, results[i], worker.Shares) {
raven.CaptureMessage("invalid result from CL worker", nil)
log.Errorw("invalid result from CL worker")
}
}
......@@ -97,7 +101,9 @@ func (worker *Cryptonight) gpuThread(key []string, cl *cryptonightCL, workChan c
if !ok {
return
}
cl.SetJob(work.Input, work.Target)
if err := cl.Update(work.Input, work.Target); err != nil {
workerError(err)
}
}
}
......
......@@ -156,7 +156,7 @@ func newCryptonightCL(config CLDeviceConfig, lite bool) (*cryptonightCL, error)
return &w, nil
}
func (w *cryptonightCL) SetJob(input []byte, target uint64) error {
func (w *cryptonightCL) Update(input []byte, target uint64) error {
uintensity := uint64(w.Intensity)
......@@ -268,7 +268,7 @@ func (w *cryptonightCL) SetJob(input []byte, target uint64) error {
return nil
}
func (w *cryptonightCL) RunJob(results []uint32, nonce uint32) error {
func (w *cryptonightCL) Run(results []uint32, nonce uint32) error {
// round up to next multiple of worksize
threads := ((w.Intensity + w.worksize - 1) / w.worksize) * w.worksize
......
......@@ -126,7 +126,7 @@ func (worker *Ethash) thread(key []string, workChan chan *ethash.Work) {
start := time.Now()
worker.lock.RLock()
if err := work.VerifyRange(worker.hash, uint64(worker.rand.Uint32()), 10*1024, worker.Shares); err != nil {
log.Error(err)
workerError(err)
}
worker.lock.RUnlock()
worker.metrics.IncrCounter(key, float32(10*1024/time.Since(start).Seconds()))
......@@ -138,9 +138,11 @@ func (worker *Ethash) clThread(key []string, cl *ethashCL, workChan chan *ethash
defer cl.Release()
work := <-workChan
cl.Update(work.Header, work.Target)
var ok bool
if err := cl.Update(work.Header, work.Target); err != nil {
workerError(err)
}
var ok bool
var results [2]uint32
for {
......@@ -149,13 +151,17 @@ func (worker *Ethash) clThread(key []string, cl *ethashCL, workChan chan *ethash
if !ok {
return
}
cl.Update(work.Header, work.Target)
if err := cl.Update(work.Header, work.Target); err != nil {
workerError(err)
}
default:
start := time.Now()
worker.lock.RLock()
startNonce := uint64(worker.rand.Uint32())
cl.Run(work.ExtraNonce+startNonce, results)
if err := cl.Run(work.ExtraNonce+startNonce, results); err != nil {
workerError(err)
}
if results[0] > 0 {
worker.Shares <- ethash.Share{
JobId: work.JobId,
......
package worker
import (
"time"
metrics "github.com/armon/go-metrics"
raven "github.com/getsentry/raven-go"
"gitlab.com/blockforge/blockforge/hardware/opencl"
"gitlab.com/blockforge/blockforge/hardware/processor"
"gitlab.com/blockforge/blockforge/log"
)
type Worker interface {
......@@ -35,3 +39,10 @@ type CLDeviceConfig struct {
Worksize int
Device *opencl.Device
}
// workerError reports an error and sleeps
func workerError(err error) {
raven.CaptureError(err, nil)
log.Error(err)
time.Sleep(time.Minute * 1)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment