From d6f4eb55f93ca687b47331db84961949b83e08be Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 15 Feb 2016 08:49:26 +0000 Subject: [PATCH] Qt/Options: Configure maxmempool using rwconf --- src/qt/optionsdialog.cpp | 10 +++++++++- src/qt/optionsdialog.h | 1 + src/qt/optionsmodel.cpp | 22 ++++++++++++++++++++++ src/qt/optionsmodel.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 297b3fab1c..2bf01db8c6 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -20,8 +21,8 @@ #include #include #include +#include // for maxmempoolMinimum #include - #include #include @@ -207,6 +208,12 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) maxorphantx->setMaximum(std::numeric_limits::max()); CreateOptionUI(verticalLayout_Mempool, maxorphantx, tr("Keep at most %s unconnected transactions in memory")); + maxmempool = new QSpinBox(tabMempool); + const int64_t nMempoolSizeMinMB = maxmempoolMinimumBytes(gArgs.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT_KVB) * 1'000) / 1'000'000; + maxmempool->setMinimum(nMempoolSizeMinMB); + maxmempool->setMaximum(std::numeric_limits::max()); + CreateOptionUI(verticalLayout_Mempool, maxmempool, tr("Keep the transaction memory pool below %s MB")); + QGroupBox * const groupBox_Spamfiltering = new QGroupBox(tabMempool); groupBox_Spamfiltering->setTitle(tr("Spam filtering")); QVBoxLayout * const verticalLayout_Spamfiltering = new QVBoxLayout(groupBox_Spamfiltering); @@ -460,6 +467,7 @@ void OptionsDialog::setMapper() mempoolreplacement->setCurrentIndex(current_mempoolreplacement_index); mapper->addMapping(maxorphantx, OptionsModel::maxorphantx); + mapper->addMapping(maxmempool, OptionsModel::maxmempool); /* Window */ #ifndef Q_OS_MACOS diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index aaa8f9a316..13cad80357 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -90,6 +90,7 @@ private: QValueComboBox *mempoolreplacement; QSpinBox *maxorphantx; + QSpinBox *maxmempool; }; #endif // BITCOIN_QT_OPTIONSDIALOG_H diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 926a95c48e..fd4ef110fe 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -14,6 +14,7 @@ #include #include #include +#include // for DEFAULT_MAX_MEMPOOL_SIZE_MB #include #include #include @@ -637,6 +638,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con return CanonicalMempoolReplacement(*this); case maxorphantx: return qlonglong(gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS)); + case maxmempool: + return qlonglong(node().mempool().m_opts.max_size_bytes / 1'000'000); default: return QVariant(); } @@ -970,6 +973,25 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: } break; } + case maxmempool: + { + if (changed()) { + long long nOldValue = node().mempool().m_opts.max_size_bytes; + long long nNv = value.toLongLong(); + std::string strNv = value.toString().toStdString(); + node().mempool().m_opts.max_size_bytes = nNv * 1'000'000; + gArgs.ForceSetArg("-maxmempool", strNv); + gArgs.ModifyRWConfigFile("maxmempool", strNv); + if (nNv < nOldValue) { + LOCK(cs_main); + auto node_ctx = node().context(); + assert(node_ctx && node_ctx->mempool && node_ctx->chainman); + auto& active_chainstate = node_ctx->chainman->ActiveChainstate(); + LimitMempoolSize(*node_ctx->mempool, active_chainstate.CoinsTip()); + } + } + break; + } default: break; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 38a984331a..a5a32ff662 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -82,6 +82,7 @@ public: peerblockfilters, // bool mempoolreplacement, maxorphantx, + maxmempool, OptionIDRowCount, };