Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Optimize locks to improve responsiveness #2137

Merged
merged 2 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ GRIDCOIN_CORE_H = \
version.h \
wallet/coincontrol.h \
wallet/db.h \
wallet/generated_type.h \
wallet/walletdb.h \
wallet/wallet.h \
wallet/ismine.h
Expand Down
6 changes: 6 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,12 @@ void BitcoinGUI::updateGlobalStatus()
// This is needed to prevent segfaulting due to early GUI initialization compared to core.
if (miner_first_pass_complete)
{
TRY_LOCK(cs_main, locked_main);

if (!locked_main) {
return;
}

try
{
overviewPage->updateGlobalStatus();
Expand Down
6 changes: 6 additions & 0 deletions src/qt/researcher/researchermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ void ResearcherModel::refresh()
emit researcherChanged();
}

TRY_LOCK(cs_main, lockMain);

if (!lockMain) {
return;
}

updateBeacon();

emit magnitudeChanged();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
{
status.status = TransactionStatus::Confirmed;
}

status.generated_type = wtx.GetGeneratedType(vout);
}
else
{
Expand Down
14 changes: 11 additions & 3 deletions src/qt/transactionrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define TRANSACTIONRECORD_H

#include "uint256.h"
#include "wallet/generated_type.h"
#include "wallet/ismine.h"

#include <QList>
Expand All @@ -14,9 +15,15 @@ class CWalletTx;
class TransactionStatus
{
public:
TransactionStatus():
countsForBalance(false), sortKey(""),
matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
TransactionStatus()
: countsForBalance(false)
, sortKey("")
, matures_in(0)
, status(Offline)
, generated_type(MinedType::UNKNOWN)
, depth(0)
, open_for(0)
, cur_num_blocks(-1)
{ }

enum Status {
Expand Down Expand Up @@ -47,6 +54,7 @@ class TransactionStatus
/** @name Reported status
@{*/
Status status;
MinedType generated_type;
int64_t depth;
int64_t open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
of additional blocks that need to be mined before
Expand Down
8 changes: 2 additions & 6 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,7 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const
return tr("Payment to yourself");
case TransactionRecord::Generated:
{
MinedType gentype = GetGeneratedType(wallet, wtx->hash, wtx->vout);

switch (gentype)
switch (wtx->status.generated_type)
{
case MinedType::POS:
return tr("MINED - POS");
Expand Down Expand Up @@ -445,9 +443,7 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx
{
case TransactionRecord::Generated:
{
MinedType gentype = GetGeneratedType(wallet, wtx->hash, wtx->vout);

switch (gentype)
switch (wtx->status.generated_type)
{
case MinedType::POS:
return QIcon(":/icons/tx_pos");
Expand Down
19 changes: 19 additions & 0 deletions src/wallet/generated_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2014-2021 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

/** (POS/POR) enums for CoinStake Transactions -- We should never get unknown but just in case!*/
enum MinedType
{
UNKNOWN = 0,
POS = 1,
POR = 2,
ORPHANED = 3,
POS_SIDE_STAKE_RCV = 4,
POR_SIDE_STAKE_RCV = 5,
POS_SIDE_STAKE_SEND = 6,
POR_SIDE_STAKE_SEND = 7,
SUPERBLOCK = 8
};
23 changes: 8 additions & 15 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "script.h"
#include "streams.h"
#include "ui_interface.h"
#include "wallet/generated_type.h"
#include "wallet/walletdb.h"
#include "wallet/ismine.h"

Expand All @@ -30,6 +31,8 @@ class CReserveKey;
class COutput;
class CCoinControl;

MinedType GetGeneratedType(const CWallet *wallet, const uint256& tx, unsigned int vout);

/** (client) version numbers for particular wallet features */
enum WalletFeature
{
Expand All @@ -39,20 +42,6 @@ enum WalletFeature
FEATURE_LATEST = 60000
};

/** (POS/POR) enums for CoinStake Transactions -- We should never get unknown but just in case!*/
enum MinedType
{
UNKNOWN = 0,
POS = 1,
POR = 2,
ORPHANED = 3,
POS_SIDE_STAKE_RCV = 4,
POR_SIDE_STAKE_RCV = 5,
POS_SIDE_STAKE_SEND = 6,
POR_SIDE_STAKE_SEND = 7,
SUPERBLOCK = 8
};

/** A key pool entry */
class CKeyPool
{
Expand Down Expand Up @@ -854,6 +843,11 @@ class CWalletTx : public CMerkleTx

void RelayWalletTransaction(CTxDB& txdb);
void RelayWalletTransaction();

MinedType GetGeneratedType(uint32_t vout_offset) const
{
return ::GetGeneratedType(pwallet, GetHash(), vout_offset);
}
};


Expand Down Expand Up @@ -1048,5 +1042,4 @@ class CAccountingEntry
std::vector<char> _ssExtra;
};

MinedType GetGeneratedType(const CWallet *wallet, const uint256& tx, unsigned int vout);
#endif