From 4dff308dc74d7e51d2ced108284a12bf3daadbde Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 15 Feb 2016 07:09:36 +0000 Subject: [PATCH] Qt/Options: Configure maxorphantx using rwconf --- src/net_processing.cpp | 8 ++++++++ src/net_processing.h | 2 ++ src/qt/optionsdialog.cpp | 7 +++++++ src/qt/optionsdialog.h | 2 ++ src/qt/optionsmodel.cpp | 17 +++++++++++++++++ src/qt/optionsmodel.h | 1 + 6 files changed, 37 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f5388971c4..d46800547e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -520,6 +520,7 @@ public: bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); std::vector GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + void LimitOrphanTxSize(unsigned int nMaxOrphans) override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SetBestBlock(int height, std::chrono::seconds time) override @@ -1952,6 +1953,13 @@ PeerManagerInfo PeerManagerImpl::GetInfo() const }; } +void PeerManagerImpl::LimitOrphanTxSize(unsigned int nMaxOrphans) +{ + LOCK(g_msgproc_mutex); + LOCK2(cs_main, m_tx_download_mutex); + m_orphanage.LimitOrphans(nMaxOrphans, m_rng); +} + int PeerManagerImpl::GetNumberOfPeersWithValidatedDownloads() const { AssertLockHeld(m_chainman.GetMutex()); diff --git a/src/net_processing.h b/src/net_processing.h index 7d6b5eb547..3aac9873f0 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -7,6 +7,7 @@ #define BITCOIN_NET_PROCESSING_H #include +#include #include #include @@ -95,6 +96,7 @@ public: /** Get statistics from node state */ virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0; + virtual void LimitOrphanTxSize(unsigned int nMaxOrphans) = 0; virtual std::vector GetOrphanTransactions() = 0; diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 8982a79fbb..297b3fab1c 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -202,6 +202,11 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) mempoolreplacement->addItem(QString("with a higher mining fee (no opt-out)"), QVariant("fee,-optin")); CreateOptionUI(verticalLayout_Mempool, mempoolreplacement, tr("Transaction &replacement: %s")); + maxorphantx = new QSpinBox(tabMempool); + maxorphantx->setMinimum(0); + maxorphantx->setMaximum(std::numeric_limits::max()); + CreateOptionUI(verticalLayout_Mempool, maxorphantx, tr("Keep at most %s unconnected transactions in memory")); + QGroupBox * const groupBox_Spamfiltering = new QGroupBox(tabMempool); groupBox_Spamfiltering->setTitle(tr("Spam filtering")); QVBoxLayout * const verticalLayout_Spamfiltering = new QVBoxLayout(groupBox_Spamfiltering); @@ -454,6 +459,8 @@ void OptionsDialog::setMapper() } mempoolreplacement->setCurrentIndex(current_mempoolreplacement_index); + mapper->addMapping(maxorphantx, OptionsModel::maxorphantx); + /* Window */ #ifndef Q_OS_MACOS if (QSystemTrayIcon::isSystemTrayAvailable()) { diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 5811844404..aaa8f9a316 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -15,6 +15,7 @@ class QValidatedLineEdit; QT_BEGIN_NAMESPACE class QBoxLayout; class QDataWidgetMapper; +class QSpinBox; class QString; class QValueComboBox; class QWidget; @@ -88,6 +89,7 @@ private: void CreateOptionUI(QBoxLayout *, QWidget *, const QString& text); QValueComboBox *mempoolreplacement; + QSpinBox *maxorphantx; }; #endif // BITCOIN_QT_OPTIONSDIALOG_H diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index d00d13a093..926a95c48e 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -635,6 +635,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con return gArgs.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS); case mempoolreplacement: return CanonicalMempoolReplacement(*this); + case maxorphantx: + return qlonglong(gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS)); default: return QVariant(); } @@ -953,6 +955,21 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: } break; } + case maxorphantx: + { + if (changed()) { + unsigned int nMaxOrphanTx = gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS); + unsigned int nNv = value.toLongLong(); + std::string strNv = value.toString().toStdString(); + gArgs.ForceSetArg("-maxorphantx", strNv); + gArgs.ModifyRWConfigFile("maxorphantx", strNv); + if (nNv < nMaxOrphanTx) { + assert(node().context() && node().context()->peerman); + node().context()->peerman->LimitOrphanTxSize(nNv); + } + } + break; + } default: break; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 2297c23fa2..38a984331a 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -81,6 +81,7 @@ public: peerbloomfilters, // bool peerblockfilters, // bool mempoolreplacement, + maxorphantx, OptionIDRowCount, };