Changeset View
Changeset View
Standalone View
Standalone View
src/qt/clientmodel.cpp
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | |||||
int ClientModel::getNumBlocks() const { | int ClientModel::getNumBlocks() const { | ||||
if (m_cached_num_blocks == -1) { | if (m_cached_num_blocks == -1) { | ||||
m_cached_num_blocks = m_node.getNumBlocks(); | m_cached_num_blocks = m_node.getNumBlocks(); | ||||
} | } | ||||
return m_cached_num_blocks; | return m_cached_num_blocks; | ||||
} | } | ||||
BlockHash ClientModel::getBestBlockHash() { | |||||
BlockHash tip{WITH_LOCK(m_cached_tip_mutex, return m_cached_tip_blocks)}; | |||||
if (!tip.IsNull()) { | |||||
return tip; | |||||
} | |||||
// Lock order must be: first `cs_main`, then `m_cached_tip_mutex`. | |||||
// The following will lock `cs_main` (and release it), so we must not | |||||
// own `m_cached_tip_mutex` here. | |||||
tip = m_node.getBestBlockHash(); | |||||
LOCK(m_cached_tip_mutex); | |||||
// We checked that `m_cached_tip_blocks` is not null above, but then we | |||||
// released the mutex `m_cached_tip_mutex`, so it could have changed in the | |||||
// meantime. Thus, check again. | |||||
if (m_cached_tip_blocks.IsNull()) { | |||||
m_cached_tip_blocks = tip; | |||||
} | |||||
return m_cached_tip_blocks; | |||||
} | |||||
void ClientModel::updateNumConnections(int numConnections) { | void ClientModel::updateNumConnections(int numConnections) { | ||||
Q_EMIT numConnectionsChanged(numConnections); | Q_EMIT numConnectionsChanged(numConnections); | ||||
} | } | ||||
void ClientModel::updateNetworkActive(bool networkActive) { | void ClientModel::updateNetworkActive(bool networkActive) { | ||||
Q_EMIT networkActiveChanged(networkActive); | Q_EMIT networkActiveChanged(networkActive); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | |||||
static void BannedListChanged(ClientModel *clientmodel) { | 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, int height, | SynchronizationState sync_state, | ||||
const BlockHash block_hash, int height, | |||||
int64_t blockTime, double verificationProgress, | int64_t blockTime, 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 = height; | ||||
clientmodel->cachedBestHeaderTime = blockTime; | clientmodel->cachedBestHeaderTime = blockTime; | ||||
} else { | } else { | ||||
clientmodel->m_cached_num_blocks = height; | clientmodel->m_cached_num_blocks = height; | ||||
WITH_LOCK(clientmodel->m_cached_tip_mutex, | |||||
clientmodel->m_cached_tip_blocks = 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; | ||||
Show All 22 Lines | m_handler_notify_num_connections_changed = | ||||
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(std::bind( | m_handler_notify_block_tip = m_node.handleNotifyBlockTip( | ||||
BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, | std::bind(BlockTipChanged, this, std::placeholders::_1, | ||||
std::placeholders::_3, std::placeholders::_4, false)); | std::placeholders::_2, std::placeholders::_3, | ||||
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(std::bind( | std::placeholders::_4, std::placeholders::_5, false)); | ||||
BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, | m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( | ||||
std::placeholders::_3, std::placeholders::_4, true)); | std::bind(BlockTipChanged, this, std::placeholders::_1, | ||||
std::placeholders::_2, std::placeholders::_3, | |||||
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 |