Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ethstorage/miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type worker struct {
miningStates map[uint64]*MiningState
submissionStates map[uint64]*SubmissionState

running int32
running atomic.Int32
wg sync.WaitGroup
lg log.Logger
}
Expand Down Expand Up @@ -185,16 +185,16 @@ func newWorker(

func (w *worker) start() {
w.lg.Info("Worker is being started...")
atomic.StoreInt32(&w.running, 1)
w.running.Store(1)
}

func (w *worker) stop() {
w.lg.Warn("Worker is being stopped...")
atomic.StoreInt32(&w.running, 0)
w.running.Store(0)
}

func (w *worker) isRunning() bool {
return atomic.LoadInt32(&w.running) == 1
return w.running.Load() == 1
}

func (w *worker) close() {
Expand Down
12 changes: 6 additions & 6 deletions ethstorage/pora/ethash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
rows := int(size) / hashBytes

// Start a monitoring goroutine to report progress on low end devices
var progress uint32
var progress atomic.Uint32

done := make(chan struct{})
defer close(done)
Expand All @@ -185,7 +185,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
case <-done:
return
case <-time.After(3 * time.Second):
lg.Info("Generating ethash verification cache", "percentage", atomic.LoadUint32(&progress)*100/uint32(rows)/(cacheRounds+1), "elapsed", common.PrettyDuration(time.Since(start)))
lg.Info("Generating ethash verification cache", "percentage", progress.Load()*100/uint32(rows)/(cacheRounds+1), "elapsed", common.PrettyDuration(time.Since(start)))
}
}
}()
Expand All @@ -196,7 +196,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
keccak512(cache, seed)
for offset := uint64(hashBytes); offset < size; offset += hashBytes {
keccak512(cache[offset:], cache[offset-hashBytes:offset])
atomic.AddUint32(&progress, 1)
progress.Add(1)
}
// Use a low-round version of randmemohash
temp := make([]byte, hashBytes)
Expand All @@ -211,7 +211,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
bitutil.XORBytes(temp, cache[srcOff:srcOff+hashBytes], cache[xorOff:xorOff+hashBytes])
keccak512(cache[dstOff:], temp)

atomic.AddUint32(&progress, 1)
progress.Add(1)
}
}
// Swap the byte order on big endian systems and return
Expand Down Expand Up @@ -310,7 +310,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
var pend sync.WaitGroup
pend.Add(threads)

var progress uint64
var progress atomic.Uint64
for i := 0; i < threads; i++ {
go func(id int) {
defer pend.Done()
Expand All @@ -331,7 +331,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
}
copy(dataset[index*hashBytes:], item)

if status := atomic.AddUint64(&progress, 1); status%percent == 0 {
if status := progress.Add(1); status%percent == 0 {
lg.Info("Generating DAG in progress", "percentage", (status*100)/(size/hashBytes), "elapsed", common.PrettyDuration(time.Since(start)))
}
}
Expand Down