@@ -13,6 +13,16 @@ func (psh *PresenterStatusHandler) GetNonce() uint64 {
1313 return psh .getFromCacheAsUint64 (common .MetricNonce )
1414}
1515
16+ // GetLastExecutedNonce will return current last executed nonce of node
17+ func (psh * PresenterStatusHandler ) GetLastExecutedNonce () uint64 {
18+ return psh .getFromCacheAsUint64 (common .MetricLastExecutedNonce )
19+ }
20+
21+ // GetProposedNonce will return current proposed nonce of node
22+ func (psh * PresenterStatusHandler ) GetProposedNonce () uint64 {
23+ return psh .getFromCacheAsUint64 (common .MetricProposedNonce )
24+ }
25+
1626// GetIsSyncing will return state of the node
1727func (psh * PresenterStatusHandler ) GetIsSyncing () uint64 {
1828 return psh .getFromCacheAsUint64 (common .MetricIsSyncing )
@@ -72,25 +82,14 @@ func (psh *PresenterStatusHandler) CalculateTimeToSynchronize(numMillisecondsRef
7282
7383 currentSynchronizedRound := psh .GetSynchronizedRound ()
7484
75- numSynchronizationSpeedHistory := len (psh .synchronizationSpeedHistory )
76-
77- sum := uint64 (0 )
78- for i := 0 ; i < len (psh .synchronizationSpeedHistory ); i ++ {
79- sum += psh .synchronizationSpeedHistory [i ]
80- }
81-
82- speed := float64 (0 )
83- if numSynchronizationSpeedHistory > 0 {
84- speed = float64 (sum * 1000 ) / float64 (numSynchronizationSpeedHistory * numMillisecondsRefreshTime )
85- }
86-
85+ speed := psh .calculateSpeedFromSpeedHistory (numMillisecondsRefreshTime )
8786 currentRound := psh .GetCurrentRound ()
8887 if currentRound < currentSynchronizedRound || speed == 0 {
89- return ""
88+ return "Estimating... "
9089 }
9190
9291 remainingRoundsToSynchronize := currentRound - currentSynchronizedRound
93- timeEstimationSeconds := float64 (remainingRoundsToSynchronize ) / speed
92+ timeEstimationSeconds := float64 (remainingRoundsToSynchronize ) / float64 ( speed )
9493 remainingTime := core .SecondsToHourMinSec (int (timeEstimationSeconds ))
9594
9695 return remainingTime
@@ -100,47 +99,37 @@ func (psh *PresenterStatusHandler) CalculateTimeToSynchronize(numMillisecondsRef
10099// how many blocks per second are synchronized
101100func (psh * PresenterStatusHandler ) CalculateSynchronizationSpeed (numMillisecondsRefreshTime int ) uint64 {
102101 currentSynchronizedRound := psh .GetSynchronizedRound ()
103- if psh .oldRound == 0 {
104- psh .oldRound = currentSynchronizedRound
105- return 0
106- }
107-
108- roundsPerSecond := int64 (currentSynchronizedRound - psh .oldRound )
109- if roundsPerSecond < 0 {
110- roundsPerSecond = 0
111- }
112102
113103 if len (psh .synchronizationSpeedHistory ) >= maxSpeedHistorySaved {
114- psh .synchronizationSpeedHistory = psh .synchronizationSpeedHistory [1 :len ( psh . synchronizationSpeedHistory ) ]
104+ psh .synchronizationSpeedHistory = psh .synchronizationSpeedHistory [1 :]
115105 }
116- psh .synchronizationSpeedHistory = append (psh .synchronizationSpeedHistory , uint64 ( roundsPerSecond ) )
106+ psh .synchronizationSpeedHistory = append (psh .synchronizationSpeedHistory , currentSynchronizedRound )
117107
118- psh . oldRound = currentSynchronizedRound
108+ speed := psh . calculateSpeedFromSpeedHistory ( numMillisecondsRefreshTime )
119109
120- numSyncedBlocks := uint64 (0 )
121- cumulatedTime := uint64 (0 )
110+ return speed
111+ }
112+
113+ func (psh * PresenterStatusHandler ) calculateSpeedFromSpeedHistory (numMillisecondsRefreshTime int ) uint64 {
122114 lastIndex := len (psh .synchronizationSpeedHistory ) - 1
123- millisecondsInASecond := uint64 (1000 )
124- for {
125- if lastIndex < 0 {
126- break
127- }
128- if cumulatedTime >= millisecondsInASecond {
129- break
130- }
115+ firstIndex := 0
131116
132- numSyncedBlocks += psh .synchronizationSpeedHistory [lastIndex ]
133- lastIndex --
134- cumulatedTime += uint64 (numMillisecondsRefreshTime )
117+ if lastIndex <= firstIndex {
118+ return 0
135119 }
136- if cumulatedTime == 0 || numSyncedBlocks == 0 {
120+
121+ numSyncedBlocks := psh .synchronizationSpeedHistory [lastIndex ] - psh .synchronizationSpeedHistory [firstIndex ]
122+ cumulatedTimeMs := uint64 ((lastIndex - firstIndex ) * numMillisecondsRefreshTime )
123+
124+ if cumulatedTimeMs == 0 || numSyncedBlocks == 0 {
137125 return 0
138126 }
139127
140- timeAdjustment := float64 (millisecondsInASecond ) / float64 (cumulatedTime )
141- syncedBlocksAdjustment := timeAdjustment * float64 (numSyncedBlocks )
128+ numMillisecondsInASecond := 1000.0
129+ speed := (float64 (numSyncedBlocks ) / float64 (cumulatedTimeMs )) * numMillisecondsInASecond
130+
131+ return uint64 (speed )
142132
143- return uint64 (syncedBlocksAdjustment )
144133}
145134
146135// GetNumTxProcessed will return number of processed transactions since node starts
0 commit comments