Show number of InstantSend locks in Debug Console (#2919)

* Implement GetInstantSendLockCount in CInstantSendManager

* Add islockCountChanged signal to client model

* Show number of InstantSend locks in debug console
This commit is contained in:
Alexander Block 2019-05-22 08:35:51 +02:00 committed by UdjinM6
parent a3f0306097
commit 5652ea0237
7 changed files with 66 additions and 0 deletions

View File

@ -185,6 +185,28 @@ bool CInstantSendDb::HasArchivedInstantSendLock(const uint256& islockHash)
return db.Exists(std::make_tuple(std::string("is_a2"), islockHash)); return db.Exists(std::make_tuple(std::string("is_a2"), islockHash));
} }
size_t CInstantSendDb::GetInstantSendLockCount()
{
auto it = std::unique_ptr<CDBIterator>(db.NewIterator());
auto firstKey = std::make_tuple(std::string("is_i"), uint256());
it->Seek(firstKey);
size_t cnt = 0;
while (it->Valid()) {
decltype(firstKey) curKey;
if (!it->GetKey(curKey) || std::get<0>(curKey) != "is_i") {
break;
}
cnt++;
it->Next();
}
return cnt;
}
CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash) CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash)
{ {
CInstantSendLockPtr ret; CInstantSendLockPtr ret;
@ -1410,6 +1432,11 @@ CInstantSendLockPtr CInstantSendManager::GetConflictingLock(const CTransaction&
return nullptr; return nullptr;
} }
size_t CInstantSendManager::GetInstantSendLockCount()
{
return db.GetInstantSendLockCount();
}
void CInstantSendManager::WorkThreadMain() void CInstantSendManager::WorkThreadMain()
{ {
while (!workInterrupt) { while (!workInterrupt) {

View File

@ -62,6 +62,7 @@ public:
std::unordered_map<uint256, CInstantSendLockPtr> RemoveConfirmedInstantSendLocks(int nUntilHeight); std::unordered_map<uint256, CInstantSendLockPtr> RemoveConfirmedInstantSendLocks(int nUntilHeight);
void RemoveArchivedInstantSendLocks(int nUntilHeight); void RemoveArchivedInstantSendLocks(int nUntilHeight);
bool HasArchivedInstantSendLock(const uint256& islockHash); bool HasArchivedInstantSendLock(const uint256& islockHash);
size_t GetInstantSendLockCount();
CInstantSendLockPtr GetInstantSendLockByHash(const uint256& hash); CInstantSendLockPtr GetInstantSendLockByHash(const uint256& hash);
uint256 GetInstantSendLockHashByTxid(const uint256& txid); uint256 GetInstantSendLockHashByTxid(const uint256& txid);
@ -159,6 +160,8 @@ public:
bool AlreadyHave(const CInv& inv); bool AlreadyHave(const CInv& inv);
bool GetInstantSendLockByHash(const uint256& hash, CInstantSendLock& ret); bool GetInstantSendLockByHash(const uint256& hash, CInstantSendLock& ret);
size_t GetInstantSendLockCount();
void WorkThreadMain(); void WorkThreadMain();
}; };

View File

@ -23,6 +23,8 @@
#include "masternode/masternode-sync.h" #include "masternode/masternode-sync.h"
#include "privatesend/privatesend.h" #include "privatesend/privatesend.h"
#include "llmq/quorums_instantsend.h"
#include <stdint.h> #include <stdint.h>
#include <QDebug> #include <QDebug>
@ -161,6 +163,14 @@ size_t ClientModel::getMempoolDynamicUsage() const
return mempool.DynamicMemoryUsage(); return mempool.DynamicMemoryUsage();
} }
size_t ClientModel::getInstantSentLockCount() const
{
if (!llmq::quorumInstantSendManager) {
return 0;
}
return llmq::quorumInstantSendManager->GetInstantSendLockCount();
}
double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
{ {
CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn); CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn);
@ -177,6 +187,7 @@ void ClientModel::updateTimer()
// no locking required at this point // no locking required at this point
// the following calls will acquire the required lock // the following calls will acquire the required lock
Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage()); Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage());
Q_EMIT islockCountChanged(getInstantSentLockCount());
Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent()); Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent());
} }

View File

@ -63,6 +63,8 @@ public:
long getMempoolSize() const; long getMempoolSize() const;
//! Return the dynamic memory usage of the mempool //! Return the dynamic memory usage of the mempool
size_t getMempoolDynamicUsage() const; size_t getMempoolDynamicUsage() const;
//! Return number of ISLOCKs
size_t getInstantSentLockCount() const;
void setMasternodeList(const CDeterministicMNList& mnList); void setMasternodeList(const CDeterministicMNList& mnList);
CDeterministicMNList getMasternodeList() const; CDeterministicMNList getMasternodeList() const;
@ -117,6 +119,7 @@ Q_SIGNALS:
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header); void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
void additionalDataSyncProgressChanged(double nSyncProgress); void additionalDataSyncProgressChanged(double nSyncProgress);
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes); void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
void islockCountChanged(size_t count);
void networkActiveChanged(bool networkActive); void networkActiveChanged(bool networkActive);
void alertsChanged(const QString &warnings); void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);

View File

@ -408,6 +408,20 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="16" column="0">
<widget class="QLabel" name="labelInstantSendLockCount">
<property name="text">
<string>InstantSend locks</string>
</property>
</widget>
</item>
<item row="16" column="1">
<widget class="QLabel" name="instantSendLockCount">
<property name="text">
<string>N/A</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_console"> <widget class="QWidget" name="tab_console">

View File

@ -563,6 +563,7 @@ void RPCConsole::setClientModel(ClientModel *model)
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64))); connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
connect(model, SIGNAL(mempoolSizeChanged(long,size_t)), this, SLOT(setMempoolSize(long,size_t))); connect(model, SIGNAL(mempoolSizeChanged(long,size_t)), this, SLOT(setMempoolSize(long,size_t)));
connect(model, SIGNAL(islockCountChanged(size_t)), this, SLOT(setInstantSendLockCount(size_t)));
// set up peer table // set up peer table
ui->peerWidget->setModel(model->getPeerTableModel()); ui->peerWidget->setModel(model->getPeerTableModel());
@ -906,6 +907,11 @@ void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)
ui->mempoolSize->setText(QString::number(dynUsage/1000000.0, 'f', 2) + " MB"); ui->mempoolSize->setText(QString::number(dynUsage/1000000.0, 'f', 2) + " MB");
} }
void RPCConsole::setInstantSendLockCount(size_t count)
{
ui->instantSendLockCount->setText(QString::number(count));
}
void RPCConsole::on_lineEdit_returnPressed() void RPCConsole::on_lineEdit_returnPressed()
{ {
QString cmd = ui->lineEdit->text(); QString cmd = ui->lineEdit->text();

View File

@ -111,6 +111,8 @@ public Q_SLOTS:
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers); void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
/** Set size (number of transactions and memory usage) of the mempool in the UI */ /** Set size (number of transactions and memory usage) of the mempool in the UI */
void setMempoolSize(long numberOfTxs, size_t dynUsage); void setMempoolSize(long numberOfTxs, size_t dynUsage);
/** Set number of InstantSend locks */
void setInstantSendLockCount(size_t count);
/** Go forward or back in history */ /** Go forward or back in history */
void browseHistory(int offset); void browseHistory(int offset);
/** Scroll console view to end */ /** Scroll console view to end */