10
10
#include < cassert>
11
11
#include < chrono>
12
12
13
+ #include < QDateTime>
13
14
#include < QMetaObject>
14
15
#include < QTimerEvent>
15
16
@@ -27,9 +28,46 @@ void NodeModel::setBlockTipHeight(int new_height)
27
28
}
28
29
}
29
30
31
+ void NodeModel::setRemainingSyncTime (double new_progress)
32
+ {
33
+ int currentTime = QDateTime::currentDateTime ().toMSecsSinceEpoch ();
34
+
35
+ // keep a vector of samples of verification progress at height
36
+ m_block_process_time.push_front (qMakePair (currentTime, new_progress));
37
+
38
+ // show progress speed if we have more than one sample
39
+ if (m_block_process_time.size () >= 2 ) {
40
+ double progressDelta = 0 ;
41
+ int timeDelta = 0 ;
42
+ int remainingMSecs = 0 ;
43
+ double remainingProgress = 1.0 - new_progress;
44
+ for (int i = 1 ; i < m_block_process_time.size (); i++) {
45
+ QPair<int , double > sample = m_block_process_time[i];
46
+
47
+ // take first sample after 500 seconds or last available one
48
+ if (sample.first < (currentTime - 500 * 1000 ) || i == m_block_process_time.size () - 1 ) {
49
+ progressDelta = m_block_process_time[0 ].second - sample.second ;
50
+ timeDelta = m_block_process_time[0 ].first - sample.first ;
51
+ remainingMSecs = (progressDelta > 0 ) ? remainingProgress / progressDelta * timeDelta : -1 ;
52
+ break ;
53
+ }
54
+ }
55
+ if (remainingMSecs > 0 && m_block_process_time.count () % 1000 == 0 ) {
56
+ m_remaining_sync_time = remainingMSecs;
57
+
58
+ Q_EMIT remainingSyncTimeChanged ();
59
+ }
60
+ static const int MAX_SAMPLES = 5000 ;
61
+ if (m_block_process_time.count () > MAX_SAMPLES) {
62
+ m_block_process_time.remove (1 , m_block_process_time.count () - 1 );
63
+ }
64
+ }
65
+ }
30
66
void NodeModel::setVerificationProgress (double new_progress)
31
67
{
32
68
if (new_progress != m_verification_progress) {
69
+ setRemainingSyncTime (new_progress);
70
+
33
71
m_verification_progress = new_progress;
34
72
Q_EMIT verificationProgressChanged ();
35
73
}
@@ -54,6 +92,8 @@ void NodeModel::initializeResult([[maybe_unused]] bool success, interfaces::Bloc
54
92
// TODO: Handle the `success` parameter,
55
93
setBlockTipHeight (tip_info.block_height );
56
94
setVerificationProgress (tip_info.verification_progress );
95
+
96
+ Q_EMIT setTimeRatioListInitial ();
57
97
}
58
98
59
99
void NodeModel::startShutdownPolling ()
@@ -84,6 +124,8 @@ void NodeModel::ConnectToBlockTipSignal()
84
124
QMetaObject::invokeMethod (this , [this , tip, verification_progress] {
85
125
setBlockTipHeight (tip.block_height );
86
126
setVerificationProgress (verification_progress);
127
+
128
+ Q_EMIT setTimeRatioList (tip.block_time );
87
129
});
88
130
});
89
131
}
0 commit comments