diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2554,8 +2554,9 @@ mapAlreadyAskedFor.erase(txid); if (!AlreadyHave(inv) && - AcceptToMemoryPool(config, g_mempool, state, ptx, true, - &fMissingInputs)) { + AcceptToMemoryPool(config, g_mempool, state, ptx, &fMissingInputs, + false /* bypass_limits */, + Amount::zero() /* nAbsurdFee */)) { g_mempool.check(pcoinsTip.get()); RelayTransaction(tx, connman); for (size_t i = 0; i < tx.vout.size(); i++) { @@ -2600,7 +2601,9 @@ } if (AcceptToMemoryPool(config, g_mempool, stateDummy, - porphanTx, true, &fMissingInputs2)) { + porphanTx, &fMissingInputs2, + false /* bypass_limits */, + Amount::zero() /* nAbsurdFee */)) { LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanId.ToString()); RelayTransaction(orphanTx, connman); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1194,9 +1194,8 @@ // Push to local node and sync with wallets. CValidationState state; bool fMissingInputs; - bool fLimitFree = false; if (!AcceptToMemoryPool(config, g_mempool, state, std::move(tx), - fLimitFree, &fMissingInputs, false, + &fMissingInputs, false /* bypass_limits */, nMaxRawTxFee)) { if (state.IsInvalid()) { throw JSONRPCError(RPC_TRANSACTION_REJECTED, @@ -1309,8 +1308,8 @@ { LOCK(cs_main); test_accept_res = AcceptToMemoryPool( - config, g_mempool, state, std::move(tx), fLimitFree, - &missing_inputs, /* bypass_limits */ false, max_raw_tx_fee, + config, g_mempool, state, std::move(tx), &missing_inputs, + /* bypass_limits */ false, max_raw_tx_fee, /* test_accept */ true); } result_0.pushKV("allowed", test_accept_res); diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp --- a/src/test/txvalidation_tests.cpp +++ b/src/test/txvalidation_tests.cpp @@ -38,12 +38,12 @@ unsigned int initialPoolSize = g_mempool.size(); - BOOST_CHECK_EQUAL( - false, - AcceptToMemoryPool( - GetConfig(), g_mempool, state, MakeTransactionRef(coinbaseTx), - false /* pfMissingInputs */, nullptr /* plTxnReplaced */, - true /* bypass_limits */, Amount::zero() /* nAbsurdFee */)); + BOOST_CHECK_EQUAL(false, + AcceptToMemoryPool(GetConfig(), g_mempool, state, + MakeTransactionRef(coinbaseTx), + nullptr /* pfMissingInputs */, + true /* bypass_limits */, + Amount::zero() /* nAbsurdFee */)); // Check that the transaction hasn't been added to mempool. BOOST_CHECK_EQUAL(g_mempool.size(), initialPoolSize); diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp --- a/src/test/txvalidationcache_tests.cpp +++ b/src/test/txvalidationcache_tests.cpp @@ -29,9 +29,10 @@ LOCK(cs_main); CValidationState state; - return AcceptToMemoryPool(GetConfig(), g_mempool, state, - MakeTransactionRef(tx), false, nullptr, true, - Amount::zero()); + return AcceptToMemoryPool( + GetConfig(), g_mempool, state, MakeTransactionRef(tx), + nullptr /* pfMissingInputs */, true /* bypass_limits */, + Amount::zero() /* nAbsurdFee */); } BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup) { diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1356,8 +1356,8 @@ // ignore validation errors in resurrected transactions CValidationState stateDummy; if (!fAddToMempool || tx->IsCoinBase() || - !AcceptToMemoryPool(config, g_mempool, stateDummy, tx, false, - nullptr, true)) { + !AcceptToMemoryPool(config, g_mempool, stateDummy, tx, nullptr, + true, Amount::zero())) { // If the transaction doesn't make it in to the mempool, remove any // transactions that depend on it (which would now be orphans). g_mempool.removeRecursive(*tx, MemPoolRemovalReason::REORG); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -470,10 +470,8 @@ */ bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, - bool fLimitFree, bool *pfMissingInputs, - bool fOverrideMempoolLimit = false, - const Amount nAbsurdFee = Amount::zero(), - bool test_accept = false) + bool *pfMissingInputs, bool bypass_limits, + const Amount nAbsurdFee, bool test_accept = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Convert CValidationState to a human-readable message for logging */ diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -527,12 +527,13 @@ txdata); } -static bool AcceptToMemoryPoolWorker( - const Config &config, CTxMemPool &pool, CValidationState &state, - const CTransactionRef &ptx, bool fLimitFree, bool *pfMissingInputs, - int64_t nAcceptTime, bool fOverrideMempoolLimit, const Amount nAbsurdFee, - std::vector &coins_to_uncache, bool test_accept) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { +static bool +AcceptToMemoryPoolWorker(const Config &config, CTxMemPool &pool, + CValidationState &state, const CTransactionRef &ptx, + bool *pfMissingInputs, int64_t nAcceptTime, + bool bypass_limits, const Amount nAbsurdFee, + std::vector &coins_to_uncache, + bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { AssertLockHeld(cs_main); const Consensus::Params &consensusParams = @@ -705,7 +706,7 @@ gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000) .GetFee(nSize); - if (mempoolRejectFee > Amount::zero() && + if (!bypass_limits && mempoolRejectFee > Amount::zero() && nModifiedFees < mempoolRejectFee) { return state.DoS( 0, false, REJECT_INSUFFICIENTFEE, "mempool min fee not met", @@ -725,7 +726,7 @@ // This mitigates 'penny-flooding' -- sending thousands of free // transactions just to be annoying or make others' transactions take // longer to confirm. - if (fLimitFree && nModifiedFees < minRelayTxFee.GetFee(nSize)) { + if (bypass_limits && nModifiedFees < minRelayTxFee.GetFee(nSize)) { static CCriticalSection csFreeLimiter; static double dFreeCount; static int64_t nLastTime; @@ -838,7 +839,7 @@ pool.addUnchecked(txid, entry, setAncestors); // Trim mempool and check if tx was trimmed. - if (!fOverrideMempoolLimit) { + if (!bypass_limits) { pool.LimitSize( gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * @@ -857,15 +858,16 @@ /** * (try to) add transaction to memory pool with a specified acceptance time. */ -static bool AcceptToMemoryPoolWithTime( - const Config &config, CTxMemPool &pool, CValidationState &state, - const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, - int64_t nAcceptTime, bool fOverrideMempoolLimit, const Amount nAbsurdFee, - bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { +static bool +AcceptToMemoryPoolWithTime(const Config &config, CTxMemPool &pool, + CValidationState &state, const CTransactionRef &tx, + bool *pfMissingInputs, int64_t nAcceptTime, + bool bypass_limits, const Amount nAbsurdFee, + bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { std::vector coins_to_uncache; bool res = AcceptToMemoryPoolWorker( - config, pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, - fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache, test_accept); + config, pool, state, tx, pfMissingInputs, nAcceptTime, bypass_limits, + nAbsurdFee, coins_to_uncache, test_accept); if (!res) { for (const COutPoint &outpoint : coins_to_uncache) { pcoinsTip->Uncache(outpoint); @@ -882,12 +884,11 @@ bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, - bool fLimitFree, bool *pfMissingInputs, - bool fOverrideMempoolLimit, const Amount nAbsurdFee, - bool test_accept) { - return AcceptToMemoryPoolWithTime( - config, pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), - fOverrideMempoolLimit, nAbsurdFee, test_accept); + bool *pfMissingInputs, bool bypass_limits, + const Amount nAbsurdFee, bool test_accept) { + return AcceptToMemoryPoolWithTime(config, pool, state, tx, pfMissingInputs, + GetTime(), bypass_limits, nAbsurdFee, + test_accept); } /** @@ -5634,9 +5635,8 @@ if (nTime + nExpiryTimeout > nNow) { LOCK(cs_main); AcceptToMemoryPoolWithTime( - config, g_mempool, state, tx, true /* fLimitFree */, - nullptr /* pfMissingInputs */, nTime, - false /* fOverrideMempoolLimit */, + config, g_mempool, state, tx, nullptr /* pfMissingInputs */, + nTime, false /* bypass_limits */, Amount::zero() /* nAbsurdFee */, false /* test_accept */); if (state.IsValid()) { ++count; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4763,10 +4763,9 @@ // user could call sendmoney in a loop and hit spurious out of funds errors // because we think that this newly generated transaction's change is // unavailable as we're not yet aware that it is in the mempool. - bool ret = ::AcceptToMemoryPool( - GetConfig(), g_mempool, state, tx, true /* fLimitFree */, - nullptr /* pfMissingInputs */, false /* fOverrideMempoolLimit */, - nAbsurdFee); + bool ret = ::AcceptToMemoryPool(GetConfig(), g_mempool, state, tx, + nullptr /* pfMissingInputs */, + false /* bypass_limits */, nAbsurdFee); fInMempool = ret; return ret; }