|
21 | 21 | #include <validation.h>
|
22 | 22 |
|
23 | 23 | #include <stdint.h>
|
24 |
| -#include <functional> |
25 | 24 |
|
26 | 25 | #include <QDebug>
|
27 | 26 | #include <QMetaObject>
|
@@ -216,33 +215,26 @@ QString ClientModel::blocksDir() const
|
216 | 215 | return GUIUtil::PathToQString(gArgs.GetBlocksDirPath());
|
217 | 216 | }
|
218 | 217 |
|
219 |
| -// Handlers for core signals |
220 |
| -static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_state, interfaces::BlockTip tip, double verificationProgress, bool fHeader) |
| 218 | +void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, bool header) |
221 | 219 | {
|
222 |
| - if (fHeader) { |
| 220 | + if (header) { |
223 | 221 | // cache best headers time and height to reduce future cs_main locks
|
224 |
| - clientmodel->cachedBestHeaderHeight = tip.block_height; |
225 |
| - clientmodel->cachedBestHeaderTime = tip.block_time; |
| 222 | + cachedBestHeaderHeight = tip.block_height; |
| 223 | + cachedBestHeaderTime = tip.block_time; |
226 | 224 | } else {
|
227 |
| - clientmodel->m_cached_num_blocks = tip.block_height; |
228 |
| - WITH_LOCK(clientmodel->m_cached_tip_mutex, clientmodel->m_cached_tip_blocks = tip.block_hash;); |
| 225 | + m_cached_num_blocks = tip.block_height; |
| 226 | + WITH_LOCK(m_cached_tip_mutex, m_cached_tip_blocks = tip.block_hash;); |
229 | 227 | }
|
230 | 228 |
|
231 | 229 | // Throttle GUI notifications about (a) blocks during initial sync, and (b) both blocks and headers during reindex.
|
232 |
| - const bool throttle = (sync_state != SynchronizationState::POST_INIT && !fHeader) || sync_state == SynchronizationState::INIT_REINDEX; |
| 230 | + const bool throttle = (sync_state != SynchronizationState::POST_INIT && !header) || sync_state == SynchronizationState::INIT_REINDEX; |
233 | 231 | const int64_t now = throttle ? GetTimeMillis() : 0;
|
234 |
| - int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; |
| 232 | + int64_t& nLastUpdateNotification = header ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; |
235 | 233 | if (throttle && now < nLastUpdateNotification + count_milliseconds(MODEL_UPDATE_DELAY)) {
|
236 | 234 | return;
|
237 | 235 | }
|
238 | 236 |
|
239 |
| - bool invoked = QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection, |
240 |
| - Q_ARG(int, tip.block_height), |
241 |
| - Q_ARG(QDateTime, QDateTime::fromSecsSinceEpoch(tip.block_time)), |
242 |
| - Q_ARG(double, verificationProgress), |
243 |
| - Q_ARG(bool, fHeader), |
244 |
| - Q_ARG(SynchronizationState, sync_state)); |
245 |
| - assert(invoked); |
| 237 | + Q_EMIT numBlocksChanged(tip.block_height, QDateTime::fromSecsSinceEpoch(tip.block_time), verification_progress, header, sync_state); |
246 | 238 | nLastUpdateNotification = now;
|
247 | 239 | }
|
248 | 240 |
|
@@ -271,8 +263,14 @@ void ClientModel::subscribeToCoreSignals()
|
271 | 263 | qDebug() << "ClienModel: Requesting update for peer banlist";
|
272 | 264 | QMetaObject::invokeMethod(banTableModel, [this] { banTableModel->refresh(); });
|
273 | 265 | });
|
274 |
| - m_handler_notify_block_tip = m_node.handleNotifyBlockTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, false)); |
275 |
| - m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, true)); |
| 266 | + m_handler_notify_block_tip = m_node.handleNotifyBlockTip( |
| 267 | + [this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) { |
| 268 | + TipChanged(sync_state, tip, verification_progress, /*header=*/false); |
| 269 | + }); |
| 270 | + m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( |
| 271 | + [this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) { |
| 272 | + TipChanged(sync_state, tip, verification_progress, /*header=*/true); |
| 273 | + }); |
276 | 274 | }
|
277 | 275 |
|
278 | 276 | void ClientModel::unsubscribeFromCoreSignals()
|
|
0 commit comments