Skip to content

Commit

Permalink
fix blocks per minute estimation
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Nov 30, 2023
1 parent e1e97ed commit f5c9111
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion service/vochain.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func VochainPrintInfo(interval time.Duration, vi *vochaininfo.VochainInfo) {
b.Reset()
a := vi.BlockTimes()
if a[1] > 0 {
fmt.Fprintf(&b, " 10m:%.2f", float32(a[1])/1000)
fmt.Fprintf(&b, "10m:%.2f", float32(a[1])/1000)
}
if a[2] > 0 {
fmt.Fprintf(&b, " 1h:%.2f", float32(a[2])/1000)
Expand Down
18 changes: 11 additions & 7 deletions vochain/vochaininfo/vochaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ func (vi *VochainInfo) Start(sleepSecs uint64) {

var duration time.Duration
var prevHeight, currentHeight uint64
var intervalCount, heightDiffSum, voteMetricsCount uint64
var avgBlocksPerMinute float64
var accumulatedTimeSecs, heightDiffSum, voteMetricsCount uint64
var blocksPerMinute float64
var oldVoteTreeSize uint64
duration = time.Second * time.Duration(sleepSecs)
for {
Expand All @@ -297,18 +297,22 @@ func (vi *VochainInfo) Start(sleepSecs uint64) {
vi.updateCounters()
currentHeight = uint64(vi.vnode.Height())
voteMetricsCount++
intervalCount++
accumulatedTimeSecs += sleepSecs
heightDiffSum += currentHeight - prevHeight
if sleepSecs*intervalCount >= 60 && heightDiffSum > 0 {
avgBlocksPerMinute = float64(heightDiffSum) / float64((intervalCount * sleepSecs))
intervalCount = 0

if accumulatedTimeSecs >= 60 {
if accumulatedTimeSecs > 0 {
blocksPerMinute = float64(heightDiffSum) * 60.0 / float64(accumulatedTimeSecs)
}
accumulatedTimeSecs = 0
heightDiffSum = 0
}

prevHeight = currentHeight

// update values
vi.lock.Lock()
vi.blocksMinute = avgBlocksPerMinute
vi.blocksMinute = blocksPerMinute
vi.updateBlockTimes()
if sleepSecs*voteMetricsCount >= 60 {
vi.votesPerMinute = voteCount.Get() - oldVoteTreeSize
Expand Down

0 comments on commit f5c9111

Please sign in to comment.