Parallel miner

This commit is contained in:
Kaspa Profiler 2021-04-13 12:48:22 +03:00 committed by stasatdaglabs
parent bbdf7b246d
commit c46503ea7e

View File

@ -2,7 +2,9 @@ package main
import ( import (
nativeerrors "errors" nativeerrors "errors"
"fmt"
"math/rand" "math/rand"
"runtime"
"sync/atomic" "sync/atomic"
"time" "time"
@ -38,7 +40,9 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond
templatesLoop(client, miningAddr, errChan) templatesLoop(client, miningAddr, errChan)
}) })
spawn("blocksLoop", func() { for c := 0; c < (runtime.NumCPU()/2)+1; c++ {
c := c
spawn(fmt.Sprintf("blocksLoop %d", c), func() {
const windowSize = 10 const windowSize = 10
hasBlockRateTarget := targetBlocksPerSecond != 0 hasBlockRateTarget := targetBlocksPerSecond != 0
var windowTicker, blockTicker *time.Ticker var windowTicker, blockTicker *time.Ticker
@ -69,6 +73,7 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond
} }
} }
}) })
}
spawn("handleFoundBlock", func() { spawn("handleFoundBlock", func() {
for i := uint64(0); numberOfBlocks == 0 || i < numberOfBlocks; i++ { for i := uint64(0); numberOfBlocks == 0 || i < numberOfBlocks; i++ {