From 71efac329a02847bbe38636df43c2974a421d4eb Mon Sep 17 00:00:00 2001 From: Mike Zak Date: Mon, 12 Apr 2021 17:21:20 +0300 Subject: [PATCH] Add delay parameter to kaspaminer --- cmd/kaspaminer/config.go | 1 + cmd/kaspaminer/main.go | 2 +- cmd/kaspaminer/mineloop.go | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/kaspaminer/config.go b/cmd/kaspaminer/config.go index ee3f2645b..54dd35f2b 100644 --- a/cmd/kaspaminer/config.go +++ b/cmd/kaspaminer/config.go @@ -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."` 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)"` + Delay int `long:"delay" hidden:"true"` config.NetworkFlags } diff --git a/cmd/kaspaminer/main.go b/cmd/kaspaminer/main.go index c7fb0cf9f..363c360fc 100644 --- a/cmd/kaspaminer/main.go +++ b/cmd/kaspaminer/main.go @@ -49,7 +49,7 @@ func main() { doneChan := make(chan struct{}) 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 { panic(errors.Wrap(err, "error in mine loop")) } diff --git a/cmd/kaspaminer/mineloop.go b/cmd/kaspaminer/mineloop.go index 653c19688..1507527b7 100644 --- a/cmd/kaspaminer/mineloop.go +++ b/cmd/kaspaminer/mineloop.go @@ -26,7 +26,7 @@ var hashesTried uint64 const logHashRateInterval = 10 * time.Second 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. errChan := make(chan error) @@ -79,6 +79,9 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond spawn("handleFoundBlock", func() { for i := uint64(0); numberOfBlocks == 0 || i < numberOfBlocks; i++ { block := <-foundBlockChan + if delay > 0 { + <-time.After(time.Duration(delay) * time.Second) + } err := handleFoundBlock(client, block) if err != nil { errChan <- err