Add delay parameter to kaspaminer

This commit is contained in:
Mike Zak 2021-04-12 17:21:20 +03:00
parent 54fbfadf84
commit 71efac329a
3 changed files with 6 additions and 2 deletions

View File

@ -38,6 +38,7 @@ type configFlags struct {
MineWhenNotSynced bool `long:"mine-when-not-synced" description:"Mine even if the node is not synced with the rest of the network."` MineWhenNotSynced bool `long:"mine-when-not-synced" description:"Mine even if the node is not synced with the rest of the network."`
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"` Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
TargetBlocksPerSecond *float64 `long:"target-blocks-per-second" description:"Sets a maximum block rate. 0 means no limit (The default one is 2 * target network block rate)"` TargetBlocksPerSecond *float64 `long:"target-blocks-per-second" description:"Sets a maximum block rate. 0 means no limit (The default one is 2 * target network block rate)"`
Delay int `long:"delay" hidden:"true"`
config.NetworkFlags config.NetworkFlags
} }

View File

@ -49,7 +49,7 @@ func main() {
doneChan := make(chan struct{}) doneChan := make(chan struct{})
spawn("mineLoop", func() { spawn("mineLoop", func() {
err = mineLoop(client, cfg.NumberOfBlocks, *cfg.TargetBlocksPerSecond, cfg.MineWhenNotSynced, miningAddr) err = mineLoop(client, cfg.NumberOfBlocks, *cfg.TargetBlocksPerSecond, cfg.MineWhenNotSynced, cfg.Delay, miningAddr)
if err != nil { if err != nil {
panic(errors.Wrap(err, "error in mine loop")) panic(errors.Wrap(err, "error in mine loop"))
} }

View File

@ -26,7 +26,7 @@ var hashesTried uint64
const logHashRateInterval = 10 * time.Second const logHashRateInterval = 10 * time.Second
func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond float64, mineWhenNotSynced bool, func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond float64, mineWhenNotSynced bool,
miningAddr util.Address) error { delay int, miningAddr util.Address) error {
rand.Seed(time.Now().UnixNano()) // Seed the global concurrent-safe random source. rand.Seed(time.Now().UnixNano()) // Seed the global concurrent-safe random source.
errChan := make(chan error) errChan := make(chan error)
@ -79,6 +79,9 @@ 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++ {
block := <-foundBlockChan block := <-foundBlockChan
if delay > 0 {
<-time.After(time.Duration(delay) * time.Second)
}
err := handleFoundBlock(client, block) err := handleFoundBlock(client, block)
if err != nil { if err != nil {
errChan <- err errChan <- err