mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +00:00
Fix the target block rate to create less bursty mining (#1554)
Co-authored-by: Svarog <feanorr@gmail.com>
This commit is contained in:
parent
3f08bf87a8
commit
201646282b
@ -53,6 +53,8 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond
|
|||||||
}
|
}
|
||||||
blockInWindowIndex := 0
|
blockInWindowIndex := 0
|
||||||
|
|
||||||
|
sleepTime := 0 * time.Second
|
||||||
|
|
||||||
for {
|
for {
|
||||||
foundBlockChan <- mineNextBlock(mineWhenNotSynced)
|
foundBlockChan <- mineNextBlock(mineWhenNotSynced)
|
||||||
|
|
||||||
@ -61,15 +63,16 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond
|
|||||||
if blockInWindowIndex == windowSize-1 {
|
if blockInWindowIndex == windowSize-1 {
|
||||||
deviation := windowExpectedEndTime.Sub(time.Now())
|
deviation := windowExpectedEndTime.Sub(time.Now())
|
||||||
if deviation > 0 {
|
if deviation > 0 {
|
||||||
log.Infof("Finished to mine %d blocks %s earlier than expected. Sleeping %s to compensate",
|
sleepTime = deviation / windowSize
|
||||||
windowSize, deviation, deviation)
|
log.Infof("Finished to mine %d blocks %s earlier than expected. Setting the miner "+
|
||||||
time.Sleep(deviation)
|
"to sleep %s between blocks to compensate",
|
||||||
|
windowSize, deviation, sleepTime)
|
||||||
}
|
}
|
||||||
blockInWindowIndex = 0
|
blockInWindowIndex = 0
|
||||||
windowExpectedEndTime = time.Now().Add(expectedDurationForWindow)
|
windowExpectedEndTime = time.Now().Add(expectedDurationForWindow)
|
||||||
}
|
}
|
||||||
|
time.Sleep(sleepTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user