mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-21 03:03:08 +00:00
Compare commits
1 Commits
v0.9.2-dev
...
miner-dela
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71efac329a |
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user