diff options
author | Matt Corallo <git@bluematt.me> | 2015-10-02 14:19:55 -0700 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2015-10-13 01:39:27 -0700 |
commit | 794a8cec5db84fde1cce82ada51740070ec188ac (patch) | |
tree | 35b6750a3dc813c635fb304f9d7658b2695edb70 /src/txmempool.h | |
parent | e6c7b362ab8915e2aac167fa519bd29836d482af (diff) |
Implement on-the-fly mempool size limitation.
After each transaction which is added to mempool, we first call
Expire() to remove old transactions, then throwing away the
lowest-feerate transactions.
After throwing away transactions by feerate, we set the minimum
relay fee to the maximum fee transaction-and-dependant-set we
removed, plus the default minimum relay fee.
After the next block is received, the minimum relay fee is allowed
to decrease exponentially. Its halflife defaults to 12 hours, but
is decreased to 6 hours if the mempool is smaller than half its
maximum size, and 3 hours if the mempool is smaller than a quarter
its maximum size.
The minimum -maxmempool size is 40*-limitdescendantsize, as it is
easy for an attacker to play games with the cheapest
-limitdescendantsize transactions. -maxmempool defaults to 300MB.
This disables high-priority transaction relay when the min relay
fee adjustment is >0 (ie when the mempool is full). When the relay
fee adjustment drops below the default minimum relay fee / 2 it is
set to 0 (re-enabling priority-based free relay).
Diffstat (limited to 'src/txmempool.h')
-rw-r--r-- | src/txmempool.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/txmempool.h b/src/txmempool.h index e45867f713..e8572e7bda 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -287,6 +287,13 @@ private: CFeeRate minReasonableRelayFee; + mutable int64_t lastRollingFeeUpdate; + mutable bool blockSinceLastRollingFeeBump; + mutable double rollingMinimumFeeRate; //! minimum fee to get into the pool, decreases exponentially + static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; + + void trackPackageRemoved(const CFeeRate& rate); + public: typedef boost::multi_index_container< CTxMemPoolEntry, @@ -410,6 +417,17 @@ public: */ bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents = true); + /** The minimum fee to get into the mempool, which may itself not be enough + * for larger-sized transactions. + * The minReasonableRelayFee constructor arg is used to bound the time it + * takes the fee rate to go back down all the way to 0. When the feerate + * would otherwise be half of this, it is set to 0 instead. + */ + CFeeRate GetMinFee(size_t sizelimit) const; + + /** Remove transactions from the mempool until its dynamic size is <= sizelimit. */ + void TrimToSize(size_t sizelimit); + /** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */ int Expire(int64_t time); |