Skip to content

Commit

Permalink
Use history.averageDelay() to het average time between blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
catena2w committed Jun 3, 2016
1 parent 07a5489 commit db2b41b
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ class NxtLikeConsensusModule(AvgDelay: Duration = 5.seconds)
val height = history.heightOf(prevBlock).get
val prevBaseTarget = consensusBlockData(prevBlock).baseTarget
if (height % 2 == 0) {
val blocktimeAverage = (if (height > AvgBlockTimeDepth) {
(timestamp - history.parent(prevBlock, AvgBlockTimeDepth - 1).get.timestampField.value) / AvgBlockTimeDepth
} else {
timestamp - prevBlock.timestampField.value
}) / 1000
val blocktimeAverage = history.averageDelay(prevBlock, AvgBlockTimeDepth)
.getOrElse(timestamp - prevBlock.timestampField.value) / 1000

val baseTarget = (if (blocktimeAverage > AvgDelayInSeconds) {
(prevBaseTarget * Math.min(blocktimeAverage, MaxBlocktimeLimit)) / AvgDelayInSeconds
Expand Down

0 comments on commit db2b41b

Please sign in to comment.