diff --git a/src/main.cpp b/src/main.cpp index 10062c915..9d881f42a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2072,6 +2072,12 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { LOCK(pool.cs); + // Bound mempool memory: this fork never ported fee-ordered TrimToSize eviction, so + // instead of evicting we refuse new admissions once the pool exceeds -maxmempool. + // removeExpired() already clears unmineable expired txs on each block connect; this + // caps the total footprint against a flood of otherwise-minable/low-fee txs (OOM DoS). + if ( pool.DynamicMemoryUsage() > (size_t)GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ) + return state.DoS(0, error("AcceptToMemoryPool: mempool full, rejecting tx %s", hash.ToString()), REJECT_INSUFFICIENTFEE, "mempool-full"); // Store transaction in memory pool.addUnchecked(hash, entry, !IsInitialBlockDownload()); diff --git a/src/main.h b/src/main.h index 26689de83..6ecef2f77 100644 --- a/src/main.h +++ b/src/main.h @@ -66,6 +66,8 @@ class PrecomputedTransactionData; struct CNodeStateStats; #define DEFAULT_MEMPOOL_EXPIRY 1 +/** Default for -maxmempool, maximum megabytes of mempool memory usage */ +#define DEFAULT_MAX_MEMPOOL_SIZE 300 #define _COINBASE_MATURITY 100 /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/