|
|
@ -36,6 +36,8 @@ ClientModel::ClientModel(OptionsModel *_optionsModel, QObject *parent) : |
|
|
|
banTableModel(0), |
|
|
|
banTableModel(0), |
|
|
|
pollTimer(0) |
|
|
|
pollTimer(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
cachedBestHeaderHeight = -1; |
|
|
|
|
|
|
|
cachedBestHeaderTime = -1; |
|
|
|
peerTableModel = new PeerTableModel(this); |
|
|
|
peerTableModel = new PeerTableModel(this); |
|
|
|
banTableModel = new BanTableModel(this); |
|
|
|
banTableModel = new BanTableModel(this); |
|
|
|
pollTimer = new QTimer(this); |
|
|
|
pollTimer = new QTimer(this); |
|
|
@ -72,20 +74,28 @@ int ClientModel::getNumBlocks() const |
|
|
|
return chainActive.Height(); |
|
|
|
return chainActive.Height(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int ClientModel::getHeaderTipHeight() const |
|
|
|
int ClientModel::getHeaderTipHeight() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (cachedBestHeaderHeight == -1) { |
|
|
|
|
|
|
|
// make sure we initially populate the cache via a cs_main lock
|
|
|
|
|
|
|
|
// otherwise we need to wait for a tip update
|
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
|
if (!pindexBestHeader) |
|
|
|
if (pindexBestHeader) { |
|
|
|
return 0; |
|
|
|
cachedBestHeaderHeight = pindexBestHeader->nHeight; |
|
|
|
return pindexBestHeader->nHeight; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return cachedBestHeaderHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int64_t ClientModel::getHeaderTipTime() const |
|
|
|
int64_t ClientModel::getHeaderTipTime() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (cachedBestHeaderTime == -1) { |
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
|
if (!pindexBestHeader) |
|
|
|
if (pindexBestHeader) { |
|
|
|
return 0; |
|
|
|
cachedBestHeaderTime = pindexBestHeader->GetBlockTime(); |
|
|
|
return pindexBestHeader->GetBlockTime(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return cachedBestHeaderTime; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
quint64 ClientModel::getTotalBytesRecv() const |
|
|
|
quint64 ClientModel::getTotalBytesRecv() const |
|
|
@ -283,6 +293,11 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB |
|
|
|
|
|
|
|
|
|
|
|
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; |
|
|
|
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fHeader) { |
|
|
|
|
|
|
|
// cache best headers time and height to reduce future cs_main locks
|
|
|
|
|
|
|
|
clientmodel->cachedBestHeaderHeight = pIndex->nHeight; |
|
|
|
|
|
|
|
clientmodel->cachedBestHeaderTime = pIndex->GetBlockTime(); |
|
|
|
|
|
|
|
} |
|
|
|
// if we are in-sync, update the UI regardless of last update time
|
|
|
|
// if we are in-sync, update the UI regardless of last update time
|
|
|
|
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) { |
|
|
|
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) { |
|
|
|
//pass a async signal to the UI thread
|
|
|
|
//pass a async signal to the UI thread
|
|
|
|