From 61a7be3fc1003cf79534db3414ea9de90be5f422 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 10 May 2019 17:20:48 +0200 Subject: [PATCH 1/3] Implement GetInstantSendLockCount in CInstantSendManager --- src/llmq/quorums_instantsend.cpp | 27 +++++++++++++++++++++++++++ src/llmq/quorums_instantsend.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index a2c3e7405b39..79ec9e0588ee 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -185,6 +185,28 @@ bool CInstantSendDb::HasArchivedInstantSendLock(const uint256& islockHash) return db.Exists(std::make_tuple(std::string("is_a2"), islockHash)); } +size_t CInstantSendDb::GetInstantSendLockCount() +{ + auto it = std::unique_ptr(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 ret; @@ -1410,6 +1432,11 @@ CInstantSendLockPtr CInstantSendManager::GetConflictingLock(const CTransaction& return nullptr; } +size_t CInstantSendManager::GetInstantSendLockCount() +{ + return db.GetInstantSendLockCount(); +} + void CInstantSendManager::WorkThreadMain() { while (!workInterrupt) { diff --git a/src/llmq/quorums_instantsend.h b/src/llmq/quorums_instantsend.h index 955b1322355d..456ba44bb707 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -62,6 +62,7 @@ class CInstantSendDb std::unordered_map RemoveConfirmedInstantSendLocks(int nUntilHeight); void RemoveArchivedInstantSendLocks(int nUntilHeight); bool HasArchivedInstantSendLock(const uint256& islockHash); + size_t GetInstantSendLockCount(); CInstantSendLockPtr GetInstantSendLockByHash(const uint256& hash); uint256 GetInstantSendLockHashByTxid(const uint256& txid); @@ -159,6 +160,8 @@ class CInstantSendManager : public CRecoveredSigsListener bool AlreadyHave(const CInv& inv); bool GetInstantSendLockByHash(const uint256& hash, CInstantSendLock& ret); + size_t GetInstantSendLockCount(); + void WorkThreadMain(); }; From edd846696b527136687aab2e6614aacaac09b1aa Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 10 May 2019 17:21:11 +0200 Subject: [PATCH 2/3] Add islockCountChanged signal to client model --- src/qt/clientmodel.cpp | 11 +++++++++++ src/qt/clientmodel.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 1ba75e691273..efda8d5352f2 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -23,6 +23,8 @@ #include "masternode-sync.h" #include "privatesend.h" +#include "llmq/quorums_instantsend.h" + #include #include @@ -161,6 +163,14 @@ size_t ClientModel::getMempoolDynamicUsage() const return mempool.DynamicMemoryUsage(); } +size_t ClientModel::getInstantSentLockCount() const +{ + if (!llmq::quorumInstantSendManager) { + return 0; + } + return llmq::quorumInstantSendManager->GetInstantSendLockCount(); +} + double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const { CBlockIndex *tip = const_cast(tipIn); @@ -177,6 +187,7 @@ void ClientModel::updateTimer() // no locking required at this point // the following calls will acquire the required lock Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage()); + Q_EMIT islockCountChanged(getInstantSentLockCount()); Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent()); } diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index d3b429f0b4a0..846a71d46a85 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -63,6 +63,8 @@ class ClientModel : public QObject long getMempoolSize() const; //! Return the dynamic memory usage of the mempool size_t getMempoolDynamicUsage() const; + //! Return number of ISLOCKs + size_t getInstantSentLockCount() const; void setMasternodeList(const CDeterministicMNList& mnList); CDeterministicMNList getMasternodeList() const; @@ -117,6 +119,7 @@ class ClientModel : public QObject void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header); void additionalDataSyncProgressChanged(double nSyncProgress); void mempoolSizeChanged(long count, size_t mempoolSizeInBytes); + void islockCountChanged(size_t count); void networkActiveChanged(bool networkActive); void alertsChanged(const QString &warnings); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); From a80743e52b5c2ca1ac21b394e76ddb6421058ee1 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 10 May 2019 17:22:11 +0200 Subject: [PATCH 3/3] Show number of InstantSend locks in debug console --- src/qt/forms/debugwindow.ui | 14 ++++++++++++++ src/qt/rpcconsole.cpp | 6 ++++++ src/qt/rpcconsole.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index cd60a440aae5..ad14df1bd330 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -408,6 +408,20 @@ + + + + InstantSend locks + + + + + + + N/A + + + diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 01f5c4aeecf0..cb1a80c12940 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -563,6 +563,7 @@ void RPCConsole::setClientModel(ClientModel *model) 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(islockCountChanged(size_t)), this, SLOT(setInstantSendLockCount(size_t))); // set up peer table 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"); } +void RPCConsole::setInstantSendLockCount(size_t count) +{ + ui->instantSendLockCount->setText(QString::number(count)); +} + void RPCConsole::on_lineEdit_returnPressed() { QString cmd = ui->lineEdit->text(); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 8f195cde5a77..c1466cf44fc6 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -111,6 +111,8 @@ public Q_SLOTS: 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 */ void setMempoolSize(long numberOfTxs, size_t dynUsage); + /** Set number of InstantSend locks */ + void setInstantSendLockCount(size_t count); /** Go forward or back in history */ void browseHistory(int offset); /** Scroll console view to end */