2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
2019-01-29 15:53:14 +01:00
|
|
|
// Copyright (c) 2014-2019 The Dash Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2011-05-22 17:19:43 +02:00
|
|
|
#include "clientmodel.h"
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2015-06-20 20:27:03 +02:00
|
|
|
#include "bantablemodel.h"
|
2011-05-28 20:32:19 +02:00
|
|
|
#include "guiconstants.h"
|
2016-11-07 14:16:54 +01:00
|
|
|
#include "guiutil.h"
|
2014-05-23 19:09:59 +02:00
|
|
|
#include "peertablemodel.h"
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2017-04-20 23:06:56 +02:00
|
|
|
#include "chain.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "chainparams.h"
|
2013-02-10 19:46:42 +01:00
|
|
|
#include "checkpoints.h"
|
2014-10-29 02:33:23 +01:00
|
|
|
#include "clientversion.h"
|
2017-08-09 02:19:06 +02:00
|
|
|
#include "validation.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "net.h"
|
2015-11-09 11:45:07 +01:00
|
|
|
#include "txmempool.h"
|
2012-05-05 16:07:14 +02:00
|
|
|
#include "ui_interface.h"
|
2016-12-20 14:27:59 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
2019-05-21 15:26:15 +02:00
|
|
|
#include "masternode/masternode-sync.h"
|
|
|
|
#include "privatesend/privatesend.h"
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2019-05-22 08:35:51 +02:00
|
|
|
#include "llmq/quorums_instantsend.h"
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-09-04 11:52:45 +02:00
|
|
|
#include <QDebug>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QTimer>
|
2012-05-05 16:07:14 +02:00
|
|
|
|
2015-11-27 13:20:46 +01:00
|
|
|
class CBlockIndex;
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
static const int64_t nClientStartupTime = GetTime();
|
2017-07-10 16:41:14 +02:00
|
|
|
static int64_t nLastHeaderTipUpdateNotification = 0;
|
2015-11-26 16:39:40 +01:00
|
|
|
static int64_t nLastBlockTipUpdateNotification = 0;
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
ClientModel::ClientModel(OptionsModel *_optionsModel, QObject *parent) :
|
2014-06-03 14:42:20 +02:00
|
|
|
QObject(parent),
|
2016-09-23 12:44:09 +02:00
|
|
|
optionsModel(_optionsModel),
|
2014-06-03 14:42:20 +02:00
|
|
|
peerTableModel(0),
|
2015-06-20 20:27:03 +02:00
|
|
|
banTableModel(0),
|
2015-02-09 11:25:23 +01:00
|
|
|
pollTimer(0)
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2017-10-31 21:14:19 +01:00
|
|
|
cachedBestHeaderHeight = -1;
|
|
|
|
cachedBestHeaderTime = -1;
|
2014-05-23 19:09:59 +02:00
|
|
|
peerTableModel = new PeerTableModel(this);
|
2015-06-20 20:27:03 +02:00
|
|
|
banTableModel = new BanTableModel(this);
|
2012-07-05 17:43:28 +02:00
|
|
|
pollTimer = new QTimer(this);
|
2012-05-05 16:07:14 +02:00
|
|
|
connect(pollTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
|
2013-09-28 19:29:44 +02:00
|
|
|
pollTimer->start(MODEL_UPDATE_DELAY);
|
2012-05-06 19:40:58 +02:00
|
|
|
|
|
|
|
subscribeToCoreSignals();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientModel::~ClientModel()
|
|
|
|
{
|
|
|
|
unsubscribeFromCoreSignals();
|
2011-05-22 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2014-02-16 19:48:27 +01:00
|
|
|
int ClientModel::getNumConnections(unsigned int flags) const
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
CConnman::NumConnections connections = CConnman::CONNECTIONS_NONE;
|
|
|
|
|
|
|
|
if(flags == CONNECTIONS_IN)
|
|
|
|
connections = CConnman::CONNECTIONS_IN;
|
|
|
|
else if (flags == CONNECTIONS_OUT)
|
|
|
|
connections = CConnman::CONNECTIONS_OUT;
|
|
|
|
else if (flags == CONNECTIONS_ALL)
|
|
|
|
connections = CConnman::CONNECTIONS_ALL;
|
|
|
|
|
|
|
|
if(g_connman)
|
|
|
|
return g_connman->GetNodeCount(connections);
|
|
|
|
return 0;
|
2011-05-22 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:51:03 +01:00
|
|
|
void ClientModel::setMasternodeList(const CDeterministicMNList& mnList)
|
|
|
|
{
|
|
|
|
LOCK(cs_mnlinst);
|
|
|
|
if (mnListCached.GetBlockHash() == mnList.GetBlockHash()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mnListCached = mnList;
|
|
|
|
Q_EMIT masternodeListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
CDeterministicMNList ClientModel::getMasternodeList() const
|
2015-02-24 14:24:42 +01:00
|
|
|
{
|
2019-02-12 20:51:03 +01:00
|
|
|
LOCK(cs_mnlinst);
|
|
|
|
return mnListCached;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientModel::refreshMasternodeList()
|
|
|
|
{
|
|
|
|
LOCK(cs_mnlinst);
|
|
|
|
setMasternodeList(deterministicMNManager->GetListAtChainTip());
|
2015-02-24 14:24:42 +01:00
|
|
|
}
|
|
|
|
|
2011-06-18 13:13:48 +02:00
|
|
|
int ClientModel::getNumBlocks() const
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2014-04-15 17:38:25 +02:00
|
|
|
LOCK(cs_main);
|
2013-10-10 23:07:44 +02:00
|
|
|
return chainActive.Height();
|
2011-05-22 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 09:04:02 +02:00
|
|
|
int ClientModel::getHeaderTipHeight() const
|
|
|
|
{
|
2017-10-31 21:14:19 +01:00
|
|
|
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);
|
|
|
|
if (pindexBestHeader) {
|
|
|
|
cachedBestHeaderHeight = pindexBestHeader->nHeight;
|
|
|
|
cachedBestHeaderTime = pindexBestHeader->GetBlockTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cachedBestHeaderHeight;
|
2017-09-09 09:04:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t ClientModel::getHeaderTipTime() const
|
|
|
|
{
|
2017-10-31 21:14:19 +01:00
|
|
|
if (cachedBestHeaderTime == -1) {
|
|
|
|
LOCK(cs_main);
|
|
|
|
if (pindexBestHeader) {
|
|
|
|
cachedBestHeaderHeight = pindexBestHeader->nHeight;
|
|
|
|
cachedBestHeaderTime = pindexBestHeader->GetBlockTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cachedBestHeaderTime;
|
2017-09-09 09:04:02 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 18:09:32 +02:00
|
|
|
quint64 ClientModel::getTotalBytesRecv() const
|
|
|
|
{
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
if(!g_connman)
|
|
|
|
return 0;
|
|
|
|
return g_connman->GetTotalBytesRecv();
|
2013-08-22 18:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
quint64 ClientModel::getTotalBytesSent() const
|
|
|
|
{
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
if(!g_connman)
|
|
|
|
return 0;
|
|
|
|
return g_connman->GetTotalBytesSent();
|
2013-08-22 18:09:32 +02:00
|
|
|
}
|
|
|
|
|
2011-07-08 18:05:10 +02:00
|
|
|
QDateTime ClientModel::getLastBlockDate() const
|
|
|
|
{
|
2014-04-15 17:38:25 +02:00
|
|
|
LOCK(cs_main);
|
2015-02-09 11:19:01 +01:00
|
|
|
|
2013-10-10 23:07:44 +02:00
|
|
|
if (chainActive.Tip())
|
|
|
|
return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
|
2015-02-09 11:19:01 +01:00
|
|
|
|
|
|
|
return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network
|
2011-07-08 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
2015-11-09 11:45:07 +01:00
|
|
|
long ClientModel::getMempoolSize() const
|
2013-02-10 19:46:42 +01:00
|
|
|
{
|
2015-11-09 11:45:07 +01:00
|
|
|
return mempool.size();
|
2013-02-10 19:46:42 +01:00
|
|
|
}
|
2013-02-10 19:01:30 +01:00
|
|
|
|
2015-11-09 11:45:07 +01:00
|
|
|
size_t ClientModel::getMempoolDynamicUsage() const
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2015-11-09 11:45:07 +01:00
|
|
|
return mempool.DynamicMemoryUsage();
|
|
|
|
}
|
2015-08-11 14:52:28 +02:00
|
|
|
|
2019-05-22 08:35:51 +02:00
|
|
|
size_t ClientModel::getInstantSentLockCount() const
|
|
|
|
{
|
|
|
|
if (!llmq::quorumInstantSendManager) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return llmq::quorumInstantSendManager->GetInstantSendLockCount();
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:22:18 +01:00
|
|
|
double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
|
2013-02-10 19:46:42 +01:00
|
|
|
{
|
2015-11-27 18:22:18 +01:00
|
|
|
CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn);
|
|
|
|
if (!tip)
|
2012-08-01 23:32:32 +02:00
|
|
|
{
|
2015-11-27 18:22:18 +01:00
|
|
|
LOCK(cs_main);
|
|
|
|
tip = chainActive.Tip();
|
2012-08-01 23:32:32 +02:00
|
|
|
}
|
2017-01-12 12:12:56 +01:00
|
|
|
return GuessVerificationProgress(Params().TxData(), tip);
|
2013-02-10 19:46:42 +01:00
|
|
|
}
|
2013-08-22 18:09:32 +02:00
|
|
|
|
2012-05-05 16:07:14 +02:00
|
|
|
void ClientModel::updateTimer()
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2015-11-26 16:39:40 +01:00
|
|
|
// no locking required at this point
|
2017-09-07 17:59:00 +02:00
|
|
|
// the following calls will acquire the required lock
|
2015-11-09 11:45:07 +01:00
|
|
|
Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage());
|
2019-05-22 08:35:51 +02:00
|
|
|
Q_EMIT islockCountChanged(getInstantSentLockCount());
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent());
|
2012-05-05 16:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientModel::updateNumConnections(int numConnections)
|
|
|
|
{
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT numConnectionsChanged(numConnections);
|
2012-05-05 16:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-09-11 15:38:14 +02:00
|
|
|
void ClientModel::updateNetworkActive(bool networkActive)
|
|
|
|
{
|
|
|
|
Q_EMIT networkActiveChanged(networkActive);
|
|
|
|
}
|
|
|
|
|
2016-03-21 12:54:28 +01:00
|
|
|
void ClientModel::updateAlert()
|
2012-05-05 16:07:14 +02:00
|
|
|
{
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT alertsChanged(getStatusBarWarnings());
|
2011-05-30 20:20:12 +02:00
|
|
|
}
|
|
|
|
|
2011-06-18 13:13:48 +02:00
|
|
|
bool ClientModel::inInitialBlockDownload() const
|
|
|
|
{
|
|
|
|
return IsInitialBlockDownload();
|
|
|
|
}
|
|
|
|
|
2012-10-21 21:23:13 +02:00
|
|
|
enum BlockSource ClientModel::getBlockSource() const
|
2012-09-13 14:33:52 +02:00
|
|
|
{
|
2012-10-21 21:23:13 +02:00
|
|
|
if (fReindex)
|
|
|
|
return BLOCK_SOURCE_REINDEX;
|
2013-04-10 15:45:49 +02:00
|
|
|
else if (fImporting)
|
2012-10-21 21:23:13 +02:00
|
|
|
return BLOCK_SOURCE_DISK;
|
2013-04-10 15:45:49 +02:00
|
|
|
else if (getNumConnections() > 0)
|
|
|
|
return BLOCK_SOURCE_NETWORK;
|
|
|
|
|
|
|
|
return BLOCK_SOURCE_NONE;
|
2012-09-13 14:33:52 +02:00
|
|
|
}
|
|
|
|
|
2017-09-11 15:38:14 +02:00
|
|
|
void ClientModel::setNetworkActive(bool active)
|
|
|
|
{
|
|
|
|
if (g_connman) {
|
|
|
|
g_connman->SetNetworkActive(active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientModel::getNetworkActive() const
|
|
|
|
{
|
|
|
|
if (g_connman) {
|
|
|
|
return g_connman->GetNetworkActive();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-13 20:00:21 +01:00
|
|
|
QString ClientModel::getStatusBarWarnings() const
|
|
|
|
{
|
2015-12-01 09:47:13 +01:00
|
|
|
return QString::fromStdString(GetWarnings("gui"));
|
2011-12-13 20:00:21 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 22:24:53 +02:00
|
|
|
OptionsModel *ClientModel::getOptionsModel()
|
|
|
|
{
|
2011-06-03 21:03:20 +02:00
|
|
|
return optionsModel;
|
|
|
|
}
|
|
|
|
|
2014-05-23 19:09:59 +02:00
|
|
|
PeerTableModel *ClientModel::getPeerTableModel()
|
|
|
|
{
|
|
|
|
return peerTableModel;
|
|
|
|
}
|
|
|
|
|
2015-06-20 20:27:03 +02:00
|
|
|
BanTableModel *ClientModel::getBanTableModel()
|
|
|
|
{
|
|
|
|
return banTableModel;
|
|
|
|
}
|
|
|
|
|
2011-07-01 17:06:36 +02:00
|
|
|
QString ClientModel::formatFullVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(FormatFullVersion());
|
|
|
|
}
|
2012-04-07 02:06:53 +02:00
|
|
|
|
2015-08-06 15:40:50 +02:00
|
|
|
QString ClientModel::formatSubVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(strSubVersion);
|
|
|
|
}
|
|
|
|
|
2012-10-24 21:47:07 +02:00
|
|
|
bool ClientModel::isReleaseVersion() const
|
|
|
|
{
|
|
|
|
return CLIENT_VERSION_IS_RELEASE;
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:05:54 +02:00
|
|
|
QString ClientModel::formatClientStartupTime() const
|
2012-05-12 00:28:58 +02:00
|
|
|
{
|
2012-05-21 23:05:54 +02:00
|
|
|
return QDateTime::fromTime_t(nClientStartupTime).toString();
|
2012-05-12 00:28:58 +02:00
|
|
|
}
|
2012-05-06 19:40:58 +02:00
|
|
|
|
2017-09-09 09:04:02 +02:00
|
|
|
QString ClientModel::dataDir() const
|
|
|
|
{
|
2016-11-07 14:16:54 +01:00
|
|
|
return GUIUtil::boostPathToQString(GetDataDir());
|
2017-09-09 09:04:02 +02:00
|
|
|
}
|
|
|
|
|
2015-06-20 20:27:03 +02:00
|
|
|
void ClientModel::updateBanlist()
|
|
|
|
{
|
|
|
|
banTableModel->refresh();
|
|
|
|
}
|
|
|
|
|
2012-05-06 19:40:58 +02:00
|
|
|
// Handlers for core signals
|
2014-05-23 18:04:09 +02:00
|
|
|
static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress)
|
2012-05-06 19:40:58 +02:00
|
|
|
{
|
2014-05-23 18:04:09 +02:00
|
|
|
// emits signal "showProgress"
|
|
|
|
QMetaObject::invokeMethod(clientmodel, "showProgress", Qt::QueuedConnection,
|
|
|
|
Q_ARG(QString, QString::fromStdString(title)),
|
|
|
|
Q_ARG(int, nProgress));
|
2012-05-06 19:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections)
|
|
|
|
{
|
2015-01-08 11:44:25 +01:00
|
|
|
// Too noisy: qDebug() << "NotifyNumConnectionsChanged: " + QString::number(newNumConnections);
|
2012-05-06 19:40:58 +02:00
|
|
|
QMetaObject::invokeMethod(clientmodel, "updateNumConnections", Qt::QueuedConnection,
|
|
|
|
Q_ARG(int, newNumConnections));
|
|
|
|
}
|
|
|
|
|
2017-09-11 15:38:14 +02:00
|
|
|
static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive)
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(clientmodel, "updateNetworkActive", Qt::QueuedConnection,
|
|
|
|
Q_ARG(bool, networkActive));
|
|
|
|
}
|
|
|
|
|
2016-03-21 12:54:28 +01:00
|
|
|
static void NotifyAlertChanged(ClientModel *clientmodel)
|
2012-05-06 19:40:58 +02:00
|
|
|
{
|
2016-03-21 12:54:28 +01:00
|
|
|
qDebug() << "NotifyAlertChanged";
|
|
|
|
QMetaObject::invokeMethod(clientmodel, "updateAlert", Qt::QueuedConnection);
|
2012-05-06 19:40:58 +02:00
|
|
|
}
|
|
|
|
|
2015-06-20 20:27:28 +02:00
|
|
|
static void BannedListChanged(ClientModel *clientmodel)
|
|
|
|
{
|
2015-06-23 21:10:42 +02:00
|
|
|
qDebug() << QString("%1: Requesting update for peer banlist").arg(__func__);
|
2015-06-20 20:27:28 +02:00
|
|
|
QMetaObject::invokeMethod(clientmodel, "updateBanlist", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:41:14 +02:00
|
|
|
static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex, bool fHeader)
|
2015-11-26 16:39:40 +01:00
|
|
|
{
|
|
|
|
// lock free async UI updates in case we have a new block tip
|
|
|
|
// during initial sync, only update the UI if the last update
|
|
|
|
// was > 250ms (MODEL_UPDATE_DELAY) ago
|
|
|
|
int64_t now = 0;
|
|
|
|
if (initialSync)
|
|
|
|
now = GetTimeMillis();
|
|
|
|
|
2017-07-10 16:41:14 +02:00
|
|
|
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
|
|
|
|
|
2017-10-31 21:14:19 +01:00
|
|
|
if (fHeader) {
|
|
|
|
// cache best headers time and height to reduce future cs_main locks
|
|
|
|
clientmodel->cachedBestHeaderHeight = pIndex->nHeight;
|
|
|
|
clientmodel->cachedBestHeaderTime = pIndex->GetBlockTime();
|
|
|
|
}
|
2015-11-26 16:39:40 +01:00
|
|
|
// if we are in-sync, update the UI regardless of last update time
|
2017-07-10 16:41:14 +02:00
|
|
|
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
|
2017-06-22 20:36:16 +02:00
|
|
|
//pass an async signal to the UI thread
|
2015-12-01 11:45:33 +01:00
|
|
|
QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
|
|
|
|
Q_ARG(int, pIndex->nHeight),
|
|
|
|
Q_ARG(QDateTime, QDateTime::fromTime_t(pIndex->GetBlockTime())),
|
2017-07-10 16:41:14 +02:00
|
|
|
Q_ARG(double, clientmodel->getVerificationProgress(pIndex)),
|
|
|
|
Q_ARG(bool, fHeader));
|
|
|
|
nLastUpdateNotification = now;
|
2015-11-26 16:39:40 +01:00
|
|
|
}
|
2019-04-25 17:38:49 +02:00
|
|
|
}
|
2019-02-12 20:51:03 +01:00
|
|
|
|
2019-06-08 13:17:56 +02:00
|
|
|
static void NotifyMasternodeListChanged(ClientModel *clientmodel, const CDeterministicMNList& newList)
|
2019-04-25 17:38:49 +02:00
|
|
|
{
|
2019-06-13 11:01:26 +02:00
|
|
|
clientmodel->setMasternodeList(newList);
|
2015-11-26 16:39:40 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 19:09:54 +01:00
|
|
|
static void NotifyAdditionalDataSyncProgressChanged(ClientModel *clientmodel, double nSyncProgress)
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(clientmodel, "additionalDataSyncProgressChanged", Qt::QueuedConnection,
|
|
|
|
Q_ARG(double, nSyncProgress));
|
|
|
|
}
|
|
|
|
|
2012-05-06 19:40:58 +02:00
|
|
|
void ClientModel::subscribeToCoreSignals()
|
|
|
|
{
|
|
|
|
// Connect signals to client
|
2014-05-23 18:04:09 +02:00
|
|
|
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
|
2012-05-06 19:40:58 +02:00
|
|
|
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
|
2017-09-11 15:38:14 +02:00
|
|
|
uiInterface.NotifyNetworkActiveChanged.connect(boost::bind(NotifyNetworkActiveChanged, this, _1));
|
2016-03-21 12:54:28 +01:00
|
|
|
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this));
|
2015-06-20 20:27:28 +02:00
|
|
|
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
|
2017-07-10 16:41:14 +02:00
|
|
|
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false));
|
|
|
|
uiInterface.NotifyHeaderTip.connect(boost::bind(BlockTipChanged, this, _1, _2, true));
|
2019-06-08 13:17:56 +02:00
|
|
|
uiInterface.NotifyMasternodeListChanged.connect(boost::bind(NotifyMasternodeListChanged, this, _1));
|
2016-02-19 19:09:54 +01:00
|
|
|
uiInterface.NotifyAdditionalDataSyncProgressChanged.connect(boost::bind(NotifyAdditionalDataSyncProgressChanged, this, _1));
|
2012-05-06 19:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientModel::unsubscribeFromCoreSignals()
|
|
|
|
{
|
|
|
|
// Disconnect signals from client
|
2014-05-23 18:04:09 +02:00
|
|
|
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
2012-05-06 19:40:58 +02:00
|
|
|
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
|
2017-09-11 15:38:14 +02:00
|
|
|
uiInterface.NotifyNetworkActiveChanged.disconnect(boost::bind(NotifyNetworkActiveChanged, this, _1));
|
2016-03-21 12:54:28 +01:00
|
|
|
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this));
|
2015-06-20 20:27:28 +02:00
|
|
|
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
|
2017-07-10 16:41:14 +02:00
|
|
|
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false));
|
|
|
|
uiInterface.NotifyHeaderTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, true));
|
2019-06-08 13:17:56 +02:00
|
|
|
uiInterface.NotifyMasternodeListChanged.disconnect(boost::bind(NotifyMasternodeListChanged, this, _1));
|
2016-02-19 19:09:54 +01:00
|
|
|
uiInterface.NotifyAdditionalDataSyncProgressChanged.disconnect(boost::bind(NotifyAdditionalDataSyncProgressChanged, this, _1));
|
2012-05-06 19:40:58 +02:00
|
|
|
}
|