Skip to content

Commit

Permalink
Review commits applied
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Nov 3, 2024
1 parent 7ec3281 commit 3ae2e27
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ClientModel::ClientModel(OptionsModel *_optionsModel, QObject *parent) :
{
cachedBestHeaderHeight = -1;
cachedBestHeaderTime = -1;
cachedNumBlocks = 0;
cachedLastBlockDate = QDateTime();
peerTableModel = new PeerTableModel(this);
banTableModel = new BanTableModel(this);
pollTimer = new QTimer(this);
Expand Down Expand Up @@ -102,10 +104,10 @@ void ClientModel::refreshMasternodeList()
int ClientModel::getNumBlocks() const
{
TRY_LOCK(cs_main,lock);
if (!lock) {
return -1;
if (lock) {
cachedNumBlocks = chainActive.Height();
}
return chainActive.Height();
return cachedNumBlocks;
}

int ClientModel::getHeaderTipHeight() const
Expand Down Expand Up @@ -158,8 +160,13 @@ QDateTime ClientModel::getLastBlockDate() const
{
TRY_LOCK(cs_main,lock);

if (chainActive.Tip())
return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
if (!lock)
cachedLastBlockDate;

if (chainActive.Tip()) {
cachedLastBlockDate = QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
return cachedLastBlockDate;
}

return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network
}
Expand All @@ -180,6 +187,8 @@ double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
if (!tip)
{
TRY_LOCK(cs_main,lock);
if (!lock)
return 0;
tip = chainActive.Tip();
}
return GuessVerificationProgress(Params().TxData(), tip);
Expand Down
4 changes: 4 additions & 0 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class ClientModel : public QObject
mutable std::atomic<int> cachedBestHeaderHeight;
mutable std::atomic<int64_t> cachedBestHeaderTime;

mutable std::atomic<int> cachedNumBlocks;
mutable QDateTime cachedLastBlockDate;


private:
OptionsModel *optionsModel;
PeerTableModel *peerTableModel;
Expand Down
5 changes: 3 additions & 2 deletions src/qt/sparkmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ CAmount SparkModel::getMintableSparkAmount()
{
TRY_LOCK(cs_main,lock_main);
if (!lock_main)
return 0;
return cachedMintableSparkAmount;
TRY_LOCK(wallet->cs_wallet,lock_wallet);
if (!lock_wallet)
return 0;
return cachedMintableSparkAmount;
pwalletMain->AvailableCoinsForLMint(valueAndUTXO, nullptr);
}

Expand All @@ -51,6 +51,7 @@ CAmount SparkModel::getMintableSparkAmount()
s += val.first;
}

cachedMintableSparkAmount = s;
return s;
}

Expand Down
2 changes: 2 additions & 0 deletions src/qt/sparkmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class SparkModel : public QObject
public:
mutable CCriticalSection cs;

mutable std::atomic<CAmount> cachedMintableSparkAmount;

Q_SIGNALS:
void askMintSparkAll(AutoMintSparkMode);
void ackMintSparkAll(AutoMintSparkAck ack, CAmount minted, QString error);
Expand Down
25 changes: 20 additions & 5 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "core_io.h"
#include "validation.h"
#include "sync.h"
#include "uint256.h"
#include "util.h"
#include "wallet/wallet.h"

Expand Down Expand Up @@ -74,6 +73,7 @@ class TransactionTablePriv
* this is sorted by sha256.
*/
QList<TransactionRecord> cachedWallet;
std::vector<std::pair<uint256, std::pair<int, bool>>> cachedUpdatedTx;

/* Query entire wallet anew from core.
*/
Expand Down Expand Up @@ -137,11 +137,15 @@ class TransactionTablePriv
if(showTransaction)
{
TRY_LOCK(cs_main,lock_main);
if (!lock_main)
if (!lock_main) {
cachedUpdatedTx.push_back(std::make_pair(hash, std::make_pair(status, showTransaction)));
return;
}
TRY_LOCK(wallet->cs_wallet,lock_wallet);
if (!lock_wallet)
if (!lock_wallet) {
cachedUpdatedTx.push_back(std::make_pair(hash, std::make_pair(status, showTransaction)));
return;
}
// Find transaction in wallet
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(hash);
if(mi == wallet->mapWallet.end())
Expand Down Expand Up @@ -289,8 +293,19 @@ void TransactionTableModel::updateTransaction(const QString &hash, int status, b
{
uint256 updated;
updated.SetHex(hash.toStdString());

priv->updateWallet(updated, status, showTransaction);
priv->cachedUpdatedTx.push_back(std::make_pair(updated, std::make_pair(status, showTransaction)));
size_t currentSize = priv->cachedUpdatedTx.size();
for (auto itr = priv->cachedUpdatedTx.rbegin(); itr!= priv->cachedUpdatedTx.rend();)
{
std::pair<uint256, std::pair<int, bool>> current = *itr;
priv->cachedUpdatedTx.erase(--priv->cachedUpdatedTx.end());
itr++;
priv->updateWallet(current.first, current.second.first, current.second.second);
// this thread was not able to perform the update, stop and do it next time
if (currentSize == priv->cachedUpdatedTx.size())
break;
currentSize = priv->cachedUpdatedTx.size();
}
}

void TransactionTableModel::updateConfirmations()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define BITCOIN_QT_TRANSACTIONTABLEMODEL_H

#include "bitcoinunits.h"

#include "uint256.h"
#include <QAbstractTableModel>
#include <QStringList>

Expand Down

0 comments on commit 3ae2e27

Please sign in to comment.