diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index adf781c97d..bb4b0fc173 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -210,6 +210,11 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) maxmempool->setMaximum(std::numeric_limits::max()); CreateOptionUI(verticalLayout_Mempool, maxmempool, tr("Keep the transaction memory pool below %s MB")); + mempoolexpiry = new QSpinBox(tabMempool); + mempoolexpiry->setMinimum(1); + mempoolexpiry->setMaximum(std::numeric_limits::max()); + CreateOptionUI(verticalLayout_Mempool, mempoolexpiry, tr("Do not keep transactions in memory more than %s hours")); + QGroupBox * const groupBox_Spamfiltering = new QGroupBox(tabMempool); groupBox_Spamfiltering->setTitle(tr("Spam filtering")); QVBoxLayout * const verticalLayout_Spamfiltering = new QVBoxLayout(groupBox_Spamfiltering); @@ -456,6 +461,7 @@ void OptionsDialog::setMapper() mapper->addMapping(maxorphantx, OptionsModel::maxorphantx); mapper->addMapping(maxmempool, OptionsModel::maxmempool); + mapper->addMapping(mempoolexpiry, OptionsModel::mempoolexpiry); /* Window */ #ifndef Q_OS_MACOS diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 13cad80357..dd3042a721 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -91,6 +91,7 @@ private: QValueComboBox *mempoolreplacement; QSpinBox *maxorphantx; QSpinBox *maxmempool; + QSpinBox *mempoolexpiry; }; #endif // BITCOIN_QT_OPTIONSDIALOG_H diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 1270f936d1..76b41b9eee 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -15,7 +15,7 @@ #include #include #include -#include // for DEFAULT_MAX_MEMPOOL_SIZE_MB +#include // for DEFAULT_MAX_MEMPOOL_SIZE_MB, DEFAULT_MEMPOOL_EXPIRY_HOURS #include #include #include @@ -33,6 +33,8 @@ #include #endif +#include + #include #include #include @@ -614,6 +616,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con return qlonglong(gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS)); case maxmempool: return qlonglong(node().mempool().m_max_size_bytes / 1'000'000); + case mempoolexpiry: + return qlonglong(std::chrono::duration_cast(node().mempool().m_expiry).count()); default: return QVariant(); } @@ -965,6 +969,25 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: } break; } + case mempoolexpiry: + { + if (changed()) { + const auto old_value = node().mempool().m_expiry; + const std::chrono::hours new_value{value.toLongLong()}; + std::string strNv = value.toString().toStdString(); + node().mempool().m_expiry = new_value; + gArgs.ForceSetArg("-mempoolexpiry", strNv); + gArgs.ModifyRWConfigFile("mempoolexpiry", strNv); + if (new_value < old_value) { + 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 a5a32ff662..df760517f7 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -83,6 +83,7 @@ public: mempoolreplacement, maxorphantx, maxmempool, + mempoolexpiry, OptionIDRowCount, }; diff --git a/src/txmempool.h b/src/txmempool.h index 754b84850a..fdaab1e10f 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -463,7 +463,7 @@ public: using Options = kernel::MemPoolOptions; int64_t m_max_size_bytes; - const std::chrono::seconds m_expiry; + std::chrono::seconds m_expiry; const CFeeRate m_incremental_relay_feerate; const CFeeRate m_min_relay_feerate; const CFeeRate m_dust_relay_feerate;