Changeset View
Changeset View
Standalone View
Standalone View
src/qt/clientmodel.cpp
Show First 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | static void BannedListChanged(ClientModel *clientmodel) { | ||||
qDebug() << QString("%1: Requesting update for peer banlist").arg(__func__); | qDebug() << QString("%1: Requesting update for peer banlist").arg(__func__); | ||||
bool invoked = QMetaObject::invokeMethod(clientmodel, "updateBanlist", | bool invoked = QMetaObject::invokeMethod(clientmodel, "updateBanlist", | ||||
Qt::QueuedConnection); | Qt::QueuedConnection); | ||||
assert(invoked); | assert(invoked); | ||||
} | } | ||||
static void BlockTipChanged(ClientModel *clientmodel, | static void BlockTipChanged(ClientModel *clientmodel, | ||||
SynchronizationState sync_state, | SynchronizationState sync_state, | ||||
const BlockHash block_hash, int height, | interfaces::BlockTip tip, | ||||
int64_t blockTime, double verificationProgress, | double verificationProgress, bool fHeader) { | ||||
bool fHeader) { | |||||
if (fHeader) { | if (fHeader) { | ||||
// cache best headers time and height to reduce future cs_main locks | // cache best headers time and height to reduce future cs_main locks | ||||
clientmodel->cachedBestHeaderHeight = height; | clientmodel->cachedBestHeaderHeight = tip.block_height; | ||||
clientmodel->cachedBestHeaderTime = blockTime; | clientmodel->cachedBestHeaderTime = tip.block_time; | ||||
} else { | } else { | ||||
clientmodel->m_cached_num_blocks = height; | clientmodel->m_cached_num_blocks = tip.block_height; | ||||
WITH_LOCK(clientmodel->m_cached_tip_mutex, | WITH_LOCK(clientmodel->m_cached_tip_mutex, | ||||
clientmodel->m_cached_tip_blocks = block_hash;); | clientmodel->m_cached_tip_blocks = tip.block_hash;); | ||||
} | } | ||||
// Throttle GUI notifications about (a) blocks during initial sync, and (b) | // Throttle GUI notifications about (a) blocks during initial sync, and (b) | ||||
// both blocks and headers during reindex. | // both blocks and headers during reindex. | ||||
const bool throttle = | const bool throttle = | ||||
(sync_state != SynchronizationState::POST_INIT && !fHeader) || | (sync_state != SynchronizationState::POST_INIT && !fHeader) || | ||||
sync_state == SynchronizationState::INIT_REINDEX; | sync_state == SynchronizationState::INIT_REINDEX; | ||||
const int64_t now = throttle ? GetTimeMillis() : 0; | const int64_t now = throttle ? GetTimeMillis() : 0; | ||||
int64_t &nLastUpdateNotification = fHeader | int64_t &nLastUpdateNotification = fHeader | ||||
? nLastHeaderTipUpdateNotification | ? nLastHeaderTipUpdateNotification | ||||
: nLastBlockTipUpdateNotification; | : nLastBlockTipUpdateNotification; | ||||
if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) { | if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) { | ||||
return; | return; | ||||
} | } | ||||
bool invoked = QMetaObject::invokeMethod( | bool invoked = QMetaObject::invokeMethod( | ||||
clientmodel, "numBlocksChanged", Qt::QueuedConnection, | clientmodel, "numBlocksChanged", Qt::QueuedConnection, | ||||
Q_ARG(int, height), Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)), | Q_ARG(int, tip.block_height), | ||||
Q_ARG(QDateTime, QDateTime::fromTime_t(tip.block_time)), | |||||
Q_ARG(double, verificationProgress), Q_ARG(bool, fHeader), | Q_ARG(double, verificationProgress), Q_ARG(bool, fHeader), | ||||
Q_ARG(SynchronizationState, sync_state)); | Q_ARG(SynchronizationState, sync_state)); | ||||
assert(invoked); | assert(invoked); | ||||
nLastUpdateNotification = now; | nLastUpdateNotification = now; | ||||
} | } | ||||
void ClientModel::subscribeToCoreSignals() { | void ClientModel::subscribeToCoreSignals() { | ||||
// Connect signals to client | // Connect signals to client | ||||
m_handler_show_progress = m_node.handleShowProgress(std::bind( | m_handler_show_progress = m_node.handleShowProgress(std::bind( | ||||
ShowProgress, this, std::placeholders::_1, std::placeholders::_2)); | ShowProgress, this, std::placeholders::_1, std::placeholders::_2)); | ||||
m_handler_notify_num_connections_changed = | m_handler_notify_num_connections_changed = | ||||
m_node.handleNotifyNumConnectionsChanged(std::bind( | m_node.handleNotifyNumConnectionsChanged(std::bind( | ||||
NotifyNumConnectionsChanged, this, std::placeholders::_1)); | NotifyNumConnectionsChanged, this, std::placeholders::_1)); | ||||
m_handler_notify_network_active_changed = | m_handler_notify_network_active_changed = | ||||
m_node.handleNotifyNetworkActiveChanged( | m_node.handleNotifyNetworkActiveChanged( | ||||
std::bind(NotifyNetworkActiveChanged, this, std::placeholders::_1)); | std::bind(NotifyNetworkActiveChanged, this, std::placeholders::_1)); | ||||
m_handler_notify_alert_changed = | m_handler_notify_alert_changed = | ||||
m_node.handleNotifyAlertChanged(std::bind(NotifyAlertChanged, this)); | m_node.handleNotifyAlertChanged(std::bind(NotifyAlertChanged, this)); | ||||
m_handler_banned_list_changed = | m_handler_banned_list_changed = | ||||
m_node.handleBannedListChanged(std::bind(BannedListChanged, this)); | m_node.handleBannedListChanged(std::bind(BannedListChanged, this)); | ||||
m_handler_notify_block_tip = m_node.handleNotifyBlockTip( | m_handler_notify_block_tip = m_node.handleNotifyBlockTip( | ||||
std::bind(BlockTipChanged, this, std::placeholders::_1, | std::bind(BlockTipChanged, this, std::placeholders::_1, | ||||
std::placeholders::_2, std::placeholders::_3, | std::placeholders::_2, std::placeholders::_3, false)); | ||||
std::placeholders::_4, std::placeholders::_5, false)); | |||||
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( | m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( | ||||
std::bind(BlockTipChanged, this, std::placeholders::_1, | std::bind(BlockTipChanged, this, std::placeholders::_1, | ||||
std::placeholders::_2, std::placeholders::_3, | std::placeholders::_2, std::placeholders::_3, true)); | ||||
std::placeholders::_4, std::placeholders::_5, true)); | |||||
} | } | ||||
void ClientModel::unsubscribeFromCoreSignals() { | void ClientModel::unsubscribeFromCoreSignals() { | ||||
// Disconnect signals from client | // Disconnect signals from client | ||||
m_handler_show_progress->disconnect(); | m_handler_show_progress->disconnect(); | ||||
m_handler_notify_num_connections_changed->disconnect(); | m_handler_notify_num_connections_changed->disconnect(); | ||||
m_handler_notify_network_active_changed->disconnect(); | m_handler_notify_network_active_changed->disconnect(); | ||||
m_handler_notify_alert_changed->disconnect(); | m_handler_notify_alert_changed->disconnect(); | ||||
Show All 14 Lines |