Skip to content

Commit

Permalink
adds nLoadedRecordsMaxCount option for the maximum number of transact…
Browse files Browse the repository at this point in the history
…ion records that are loaded into the UI
  • Loading branch information
pedro-at-decenomy committed Oct 2, 2024
1 parent 2ecdfe0 commit f979958
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 35 deletions.
19 changes: 19 additions & 0 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void OptionsModel::setWalletDefaultOptions(QSettings& settings, bool reset)
if (reset) {
setStakeSplitThreshold(CWallet::DEFAULT_STAKE_SPLIT_THRESHOLD);
setAutoCombineThreshold(CWallet::DEFAULT_AUTO_COMBINE_THRESHOLD);
setLoadedRecordsMaxCount(MAX_AMOUNT_LOADED_RECORDS);
setCombineDust(CWallet::DEFAULT_COMBINE_DUST);
setUseCustomFee(false);
refreshDataView();
Expand Down Expand Up @@ -275,6 +276,8 @@ QVariant OptionsModel::data(const QModelIndex& index, int role) const
const CAmount nAutoCombineThreshold = (pwalletMain) ? pwalletMain->nAutoCombineThreshold : CWallet::DEFAULT_AUTO_COMBINE_THRESHOLD;
return QVariant(static_cast<double>(nAutoCombineThreshold / static_cast<double>(COIN)));
}
case LoadedRecordsMaxCount:
return QVariant((pwalletMain) ? pwalletMain->nLoadedRecordsMaxCount : MAX_AMOUNT_LOADED_RECORDS);
case fUseCustomFee:
return QVariant((pwalletMain) ? pwalletMain->fUseCustomFee : false);
case nCustomFee:
Expand Down Expand Up @@ -396,6 +399,8 @@ bool OptionsModel::setData(const QModelIndex& index, const QVariant& value, int
setAutoCombineThreshold(static_cast<CAmount>(value.toDouble() * COIN));
//setACTChanged(true);
break;
case LoadedRecordsMaxCount:
setLoadedRecordsMaxCount(value.toInt());
case DisplayUnit:
setDisplayUnit(value);
break;
Expand Down Expand Up @@ -524,6 +529,20 @@ void OptionsModel::setAutoCombineThreshold(const CAmount nAutoCombineThreshold)
}
}

/* Update LoadedRecordsMaxCount value in wallet */
void OptionsModel::setLoadedRecordsMaxCount(const int nLoadedRecordsMaxCount)
{
if (pwalletMain && pwalletMain->nLoadedRecordsMaxCount != nLoadedRecordsMaxCount) {
CWalletDB walletdb(pwalletMain->strWalletFile);
LOCK(pwalletMain->cs_wallet);
{
pwalletMain->nLoadedRecordsMaxCount = nLoadedRecordsMaxCount;
if (pwalletMain->fFileBacked)
walletdb.WriteLoadedRecordsMaxCount(pwalletMain->nLoadedRecordsMaxCount);
}
}
}

/* returns default minimum value for stake split threshold as doulbe */
double OptionsModel::getSSTMinimum() const
{
Expand Down
46 changes: 24 additions & 22 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,34 @@ class OptionsModel : public QAbstractListModel
explicit OptionsModel(QObject* parent = 0);

enum OptionID {
StartAtStartup, // bool
MinimizeToTray, // bool
MapPortUPnP, // bool
MinimizeOnClose, // bool
ProxyUse, // bool
ProxyIP, // QString
ProxyPort, // int
DisplayUnit, // BitcoinUnits::Unit
ThirdPartyTxUrls, // QString
Digits, // QString
Theme, // QString
Language, // QString
CoinControlFeatures, // bool
ThreadsScriptVerif, // int
DatabaseCache, // int
SpendZeroConfChange, // bool
HideCharts, // bool
HideZeroBalances, // bool
HideOrphans, // bool
AnonymizePivxAmount, //int
ShowMasternodesTab, // bool
Listen, // bool
StartAtStartup, // bool
MinimizeToTray, // bool
MapPortUPnP, // bool
MinimizeOnClose, // bool
ProxyUse, // bool
ProxyIP, // QString
ProxyPort, // int
DisplayUnit, // BitcoinUnits::Unit
ThirdPartyTxUrls, // QString
Digits, // QString
Theme, // QString
Language, // QString
CoinControlFeatures, // bool
ThreadsScriptVerif, // int
DatabaseCache, // int
SpendZeroConfChange, // bool
HideCharts, // bool
HideZeroBalances, // bool
HideOrphans, // bool
AnonymizePivxAmount, //int
ShowMasternodesTab, // bool
Listen, // bool
StakeSplitThreshold, // CAmount (LongLong)
CombineDust, // bool
AutoCombineThreshold, // CAmount (LongLong)
fUseCustomFee, // bool
nCustomFee, // CAmount (LongLong)
LoadedRecordsMaxCount, // int
OptionIDRowCount,
};

Expand All @@ -73,6 +74,7 @@ class OptionsModel : public QAbstractListModel
void setStakeSplitThreshold(const CAmount value);
void setCombineDust(bool fCombineDust);
void setAutoCombineThreshold(const CAmount nAutoCombineThreshold);
void setLoadedRecordsMaxCount(const int nLoadedRecordsMaxCount);
double getSSTMinimum() const;
bool isSSTValid();
/* Update Custom Fee value in wallet */
Expand Down
43 changes: 43 additions & 0 deletions src/qt/pivx/settings/forms/settingswalletoptionswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,49 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="labelTitleLoadRecords">
<property name="text">
<string>Max. loaded transactions</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinBoxLoadedRecordsMaxCount">
<property name="decimals">
<number>0</number>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="value">
<number>100000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="bottomMargin">
Expand Down
7 changes: 7 additions & 0 deletions src/qt/pivx/settings/settingswalletoptionswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ SettingsWalletOptionsWidget::SettingsWalletOptionsWidget(PIVXGUI* _window, QWidg
this, &SettingsWalletOptionsWidget::onSpinBoxAutoCombineThresholdChanged);
setShadow(ui->spinBoxAutoCombineThreshold);

// Combobox
ui->labelTitleLoadRecords->setProperty("cssClass", "text-main-settings");
ui->spinBoxLoadedRecordsMaxCount->setProperty("cssClass", "btn-spin-box");
ui->spinBoxLoadedRecordsMaxCount->setAttribute(Qt::WA_MacShowFocusRect, 0);
setShadow(ui->spinBoxLoadedRecordsMaxCount);

// Radio buttons

// Title
Expand Down Expand Up @@ -84,6 +90,7 @@ void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper){
mapper->addMapping(ui->spinBoxStakeSplitThreshold, OptionsModel::StakeSplitThreshold);
mapper->addMapping(ui->checkBoxAutoCombine, OptionsModel::CombineDust);
mapper->addMapping(ui->spinBoxAutoCombineThreshold, OptionsModel::AutoCombineThreshold);
mapper->addMapping(ui->spinBoxLoadedRecordsMaxCount, OptionsModel::LoadedRecordsMaxCount);

// Network
mapper->addMapping(ui->checkBoxMap, OptionsModel::MapPortUPnP);
Expand Down
6 changes: 3 additions & 3 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TransactionTablePriv
if (txesSize > SINGLE_THREAD_MAX_TXES_SIZE) {

// First check if the amount of txs exceeds the UI limit
if (txesSize > MAX_AMOUNT_LOADED_RECORDS) {
if (txesSize > wallet->nLoadedRecordsMaxCount) {
// Sort the txs by date just to be really really sure that them are ordered.
// (this extra calculation should be removed in the future if can ensure that
// txs are stored in order in the db, which is what should be happening)
Expand All @@ -118,7 +118,7 @@ class TransactionTablePriv
});

// Only latest ones.
walletTxes = std::vector<CWalletTx>(walletTxes.begin(), walletTxes.begin() + MAX_AMOUNT_LOADED_RECORDS);
walletTxes = std::vector<CWalletTx>(walletTxes.begin(), walletTxes.begin() + wallet->nLoadedRecordsMaxCount);
txesSize = walletTxes.size();
};

Expand Down Expand Up @@ -265,7 +265,7 @@ class TransactionTablePriv

// As old transactions are still getting updated (+20k range),
// do not add them if we deliberately didn't load them at startup.
if (cachedWallet.size() >= MAX_AMOUNT_LOADED_RECORDS && wtx.GetTxTime() < nFirstLoadedTxTime) {
if (cachedWallet.size() >= wallet->nLoadedRecordsMaxCount && wtx.GetTxTime() < nFirstLoadedTxTime) {
return;
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/qt/transactiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

#define SINGLE_THREAD_MAX_TXES_SIZE 4000

// Maximum amount of loaded records in ram in the first load.
// If the user has more and want to load them:
// TODO, add load on demand in pages (not every tx loaded all the time into the records list).
#define MAX_AMOUNT_LOADED_RECORDS 100000

class TransactionRecord;
class TransactionTablePriv;
class WalletModel;
Expand Down
7 changes: 5 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3903,7 +3903,7 @@ void CWallet::SetNull()
fUseCustomFee = false;
nCustomFee = CWallet::minTxFee.GetFeePerK();

//MultiSend
// MultiSend
vMultiSend.clear();
fMultiSendStake = false;
fMultiSendMasternodeReward = false;
Expand All @@ -3912,9 +3912,12 @@ void CWallet::SetNull()
nLastMultiSendHeight = 0;
vDisabledAddresses.clear();

//Auto Combine Dust
// Auto Combine Dust
fCombineDust = false;
nAutoCombineThreshold = 0;

// Max record in the UI
nLoadedRecordsMaxCount = MAX_AMOUNT_LOADED_RECORDS;
}

bool CWallet::isMultiSendEnabled()
Expand Down
12 changes: 10 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ static const bool DEFAULT_DISABLE_WALLET = false;

extern const char * DEFAULT_WALLET_DAT;

// Maximum amount of loaded records in ram in the first load.
// If the user has more and want to load them:
// TODO, add load on demand in pages (not every tx loaded all the time into the records list).
#define MAX_AMOUNT_LOADED_RECORDS 100000

class CAccountingEntry;
class CCoinControl;
class COutput;
Expand Down Expand Up @@ -316,7 +321,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool fUseCustomFee;
CAmount nCustomFee;

//MultiSend
// MultiSend
std::vector<std::pair<std::string, int> > vMultiSend;
bool fMultiSendStake;
bool fMultiSendMasternodeReward;
Expand All @@ -325,10 +330,13 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
int nLastMultiSendHeight;
std::vector<std::string> vDisabledAddresses;

//Auto Combine Inputs
// Auto Combine Inputs
bool fCombineDust;
CAmount nAutoCombineThreshold;

// MAX_AMOUNT_LOADED_RECORDS
int nLoadedRecordsMaxCount;

CWallet();
CWallet(std::string strWalletFileIn);
~CWallet();
Expand Down
8 changes: 8 additions & 0 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ bool CWalletDB::WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold
return Write(std::string("autocombinesettings"), pSettings, true);
}

bool CWalletDB::WriteLoadedRecordsMaxCount(int nLoadedRecordsMaxCount)
{
nWalletDBUpdateCounter++;
return Write(std::string("loadedrecordsmaxcount"), nLoadedRecordsMaxCount, true);
}

bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
{
return Read(std::make_pair(std::string("pool"), nPool), keypool);
Expand Down Expand Up @@ -689,6 +695,8 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CW
// originally saved as integer
if (pwallet->nAutoCombineThreshold < COIN)
pwallet->nAutoCombineThreshold *= COIN;
} else if (strType == "loadedrecordsmaxcount") {
ssValue >> pwallet->nLoadedRecordsMaxCount;
} else if (strType == "destdata") {
std::string strAddress, strKey, strValue;
ssKey >> strAddress;
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/walletdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class CWalletDB : public CDB
bool WriteMSDisabledAddresses(std::vector<std::string> vDisabledAddresses);
bool EraseMSDisabledAddresses(std::vector<std::string> vDisabledAddresses);
bool WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold);

bool WriteLoadedRecordsMaxCount(int nLoadedRecordsMaxCount);

bool ReadPool(int64_t nPool, CKeyPool& keypool);
bool WritePool(int64_t nPool, const CKeyPool& keypool);
bool ErasePool(int64_t nPool);
Expand Down

0 comments on commit f979958

Please sign in to comment.