Merge pull request #2553

9d5eb00 TransactionHistory: guard tx info list against concurrent access (xiphon)
This commit is contained in:
luigi1111 2019-12-05 08:49:14 -06:00
commit fd9e7d00ed
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
2 changed files with 45 additions and 31 deletions

View File

@ -32,10 +32,13 @@
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QReadLocker>
#include <QWriteLocker>
TransactionInfo *TransactionHistory::transaction(int index) TransactionInfo *TransactionHistory::transaction(int index)
{ {
QReadLocker locker(&m_tinfoLock);
if (index < 0 || index >= m_tinfo.size()) { if (index < 0 || index >= m_tinfo.size()) {
qCritical("%s: no transaction info for index %d", __FUNCTION__, index); qCritical("%s: no transaction info for index %d", __FUNCTION__, index);
@ -53,13 +56,18 @@ TransactionInfo *TransactionHistory::transaction(int index)
QList<TransactionInfo *> TransactionHistory::getAll(quint32 accountIndex) const QList<TransactionInfo *> TransactionHistory::getAll(quint32 accountIndex) const
{ {
// XXX this invalidates previously saved history that might be used by model QDateTime firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
QDateTime lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
emit refreshStarted(); emit refreshStarted();
{
QWriteLocker locker(&m_tinfoLock);
// XXX this invalidates previously saved history that might be used by model
qDeleteAll(m_tinfo); qDeleteAll(m_tinfo);
m_tinfo.clear(); m_tinfo.clear();
QDateTime firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
QDateTime lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
quint64 lastTxHeight = 0; quint64 lastTxHeight = 0;
m_locked = false; m_locked = false;
m_minutesToUnlock = 0; m_minutesToUnlock = 0;
@ -88,6 +96,8 @@ QList<TransactionInfo *> TransactionHistory::getAll(quint32 accountIndex) const
} }
} }
}
emit refreshFinished(); emit refreshFinished();
if (m_firstDateTime != firstDateTime) { if (m_firstDateTime != firstDateTime) {
@ -112,6 +122,8 @@ void TransactionHistory::refresh(quint32 accountIndex)
quint64 TransactionHistory::count() const quint64 TransactionHistory::count() const
{ {
QReadLocker locker(&m_tinfoLock);
return m_tinfo.count(); return m_tinfo.count();
} }

View File

@ -31,6 +31,7 @@
#include <QObject> #include <QObject>
#include <QList> #include <QList>
#include <QReadWriteLock>
#include <QDateTime> #include <QDateTime>
namespace Monero { namespace Monero {
@ -76,6 +77,7 @@ private:
friend class Wallet; friend class Wallet;
Monero::TransactionHistory * m_pimpl; Monero::TransactionHistory * m_pimpl;
mutable QList<TransactionInfo*> m_tinfo; mutable QList<TransactionInfo*> m_tinfo;
mutable QReadWriteLock m_tinfoLock;
mutable QDateTime m_firstDateTime; mutable QDateTime m_firstDateTime;
mutable QDateTime m_lastDateTime; mutable QDateTime m_lastDateTime;
mutable int m_minutesToUnlock; mutable int m_minutesToUnlock;